Java 用Sqlite数据库在Android中生成Excel报表
我对安卓系统有了新的了解。我使用Java 用Sqlite数据库在Android中生成Excel报表,java,android,eclipse,sqlite,Java,Android,Eclipse,Sqlite,我对安卓系统有了新的了解。我使用ListView制作了一份报告,该报告分为三列,分别为DateTime、OnOffStatus、AlarmImage 它运行良好,看起来足够好,但现在我想将此表数据导出为Excel格式。有没有可能,怎么可能 提前谢谢 Om Parkash Kaushik通过查看和 我使用此库保存所有excel报告 开始创建工作簿: HSSFWorkbook workbook = new HSSFWorkbook(); Map<String, CellStyle> st
ListView
制作了一份报告,该报告分为三列,分别为DateTime
、OnOffStatus
、AlarmImage
它运行良好,看起来足够好,但现在我想将此表数据导出为Excel格式。有没有可能,怎么可能
提前谢谢
Om Parkash Kaushik通过查看和
我使用此库保存所有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"));
}
HSSFWorkbook工作簿=新的HSSFWorkbook();
地图样式=创建样式(工作簿);
HSSFSheet sheet=workbook.createSheet();
设置一些样式:
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"));
}
private静态映射createStyles(工作簿wb){
映射样式=新HashMap();
蜂窝式;
Font-monthFont=wb.createFont();
月面设置高度为点((短)11);
setColor(IndexedColors.WHITE.getIndex());
style=wb.createCellStyle();
style.setAlignment(CellStyle.ALIGN_CENTER);
花柱.垂直排列(细胞花柱.垂直中心);
style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setFillPattern(CellStyle.SOLID\u前景);
style.setFont(monthFont);
style.setWrapText(true);
样式。放置(“标题”,样式);
style=wb.createCellStyle();
style.setAlignment(CellStyle.ALIGN_CENTER);
style.setWrapText(true);
style.setBorderRight(CellStyle.BORDER_无);
style.setBorderLeft(CellStyle.BORDER_无);
style.setBorderTop(CellStyle.BORDER_无);
style.setboordbottom(CellStyle.BORDER_无);
样式。放置(“单元格”,样式);
返回样式;
}
然后设置标题行:
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"));
}
private static final String[]article_headers={“header1”、“header2”};
//标题行
Row headerRow=sheet.createRow(0);
头部误差设置高度(40);
细胞头细胞;
对于(int i=0;i
然后通过设置行的样式和值来继续处理行
希望这有帮助,如果你觉得这有帮助,记得接受
//Jakob我在应用程序中运行此代码时出现了“java.lang.NoClassDefFoundError:org.apache.poi.hssf.usermodel.HSSFWorkbook”错误。您能指导我如何从代码中删除此错误吗?我已在项目中添加了poi-3.9-20121203.jar文件。可能是