私はAndroidで新しい手を持っています。私は、DateTime
,OnOffStatus
,AlarmImage
という3つの列に分けられたListView
を使ってレポートを作成しました。Sqliteデータベースを使用してAndroidでExcelレポートを生成
これは問題なく機能していますが、この表のデータをExcel形式にエクスポートしたいと考えています。それは可能かどうか、どうですか?
事前 オムParkash Kaushikによる内おかげ
私はAndroidで新しい手を持っています。私は、DateTime
,OnOffStatus
,AlarmImage
という3つの列に分けられたListView
を使ってレポートを作成しました。Sqliteデータベースを使用してAndroidでExcelレポートを生成
これは問題なく機能していますが、この表のデータをExcel形式にエクスポートしたいと考えています。それは可能かどうか、どうですか?
事前 オムParkash Kaushikによる内おかげ
http://poi.apache.org/を見てのスタートとhttp://poi.apache.org/spreadsheet/index.html 私はExcelのレポートのすべてに、このライブラリを使用しています。ワークブックを作成しての
スタート:
HSSFWorkbook workbook = new HSSFWorkbook();
Map<String, CellStyle> styles = createStyles(workbook);
HSSFSheet sheet = workbook.createSheet();
セットアップいくつかのスタイル:
private static Map<String, CellStyle> createStyles(Workbook wb) {
Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
CellStyle style;
Font monthFont = wb.createFont();
monthFont.setFontHeightInPoints((short) 11);
monthFont.setColor(IndexedColors.WHITE.getIndex());
style = wb.createCellStyle();
style.setAlignment(CellStyle.ALIGN_CENTER);
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
style.setFont(monthFont);
style.setWrapText(true);
styles.put("header", style);
style = wb.createCellStyle();
style.setAlignment(CellStyle.ALIGN_CENTER);
style.setWrapText(true);
style.setBorderRight(CellStyle.BORDER_NONE);
style.setBorderLeft(CellStyle.BORDER_NONE);
style.setBorderTop(CellStyle.BORDER_NONE);
style.setBorderBottom(CellStyle.BORDER_NONE);
styles.put("cell", style);
return styles;
}
そしてセットアップヘッダ行:
private static final String[] article_headers = {"header1", "header2"};
// Header row
Row headerRow = sheet.createRow(0);
headerRow.setHeightInPoints(40);
Cell headerCell;
for (int i = 0; i < article_headers.length; i++) {
headerCell = headerRow.createCell(i);
headerCell.setCellValue(article_headers[i]);
headerCell.setCellStyle(styles.get("header"));
}
そして、スタイルと値を設定して行を続けます。
この情報が役立つことを願っています。この情報が役立つと思われる場合は、受け入れてください。
//ヤコブ
のアプリケーションでこのコードを実行すると、「java.lang.NoClassDefFoundError:org.apache.poi.hssf.usermodel.HSSFWorkbook」エラーが表示されます私のコードからこのエラーを取り除く方法。プロジェクトにpoi-3.9-20121203.jarファイルを追加しました。 – ved
可能な重複[アンドロイドで/ csvファイルをExcelにエクスポートのsqliteを実装するには?](http://stackoverflow.com/questions/21448001/how-to-implement-export-sqlite -to-excel-csv-file-in-android) – Mifeet