以此格式列出数据 [{行ID = 7565.0,产品ID = test11223,邮政编码= 98103.0},{行ID = 7567.0,产品ID = test11213,邮政编码= 98101.0}]拥有超过100个这样的行ID记录,我想存储Excel中的数据格式如下
行ID订单ID邮政编码 7565 test11233 98103 7567 test11233 98101
请帮助共享代码以在excel中写入上面的列表数据。日Thnx
答案 0 :(得分:-1)
使用Apache POI,您可以编写任何类型的MS Office文件。 这是quick example如何用它写单元格。
Workbook wb = new HSSFWorkbook();
//Workbook wb = new XSSFWorkbook();
CreationHelper createHelper = wb.getCreationHelper();
Sheet sheet = wb.createSheet("new sheet");
// Create a row and put some cells in it. Rows are 0 based.
Row row = sheet.createRow(0);
// Create a cell and put a value in it.
Cell cell = row.createCell(0);
cell.setCellValue(1);
// Or do it on one line.
row.createCell(1).setCellValue(1.2);
row.createCell(2).setCellValue(
createHelper.createRichTextString("This is a string"));
row.createCell(3).setCellValue(true);
// Write the output to a file
try (OutputStream fileOut = new FileOutputStream("workbook.xls")) {
wb.write(fileOut);
}