我使用的是poi3.9开发jar
dom4j
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet spreadsheet = workbook.createSheet("cell types");
XSSFRow row = spreadsheet.createRow((short) 1);
row.createCell(0).setCellValue("Type of Cell");
row.createCell(1).setCellValue("cell value");
row.createCell(2).setCellValue("你一个是实打实的");
row=spreadsheet.createRow(10);
row.createCell(0).setCellValue("Type of Cell");
row.createCell(1).setCellValue("cell valsssssssue");
row.createCell(2).setCellValue("你一个是实打实的");
row = spreadsheet.createRow((short) 3);
row.createCell(0).setCellValue("set cell type BLANK");
row.createCell(1);
row = spreadsheet.createRow((short) 4);
row.createCell(0).setCellValue("set cell type BOOLEAN");
row.createCell(1).setCellValue(true);
row = spreadsheet.createRow((short) 5);
row.createCell(0).setCellValue("set cell type ERROR");
row.createCell(1).setCellValue(XSSFCell.CELL_TYPE_ERROR );
row = spreadsheet.createRow((short) 6);
row.createCell(0).setCellValue("set cell type date");
row.createCell(1).setCellValue(new Date());
row = spreadsheet.createRow((short) 7);
row.createCell(0).setCellValue("set cell type numeric" );
row.createCell(1).setCellValue(20 );
row = spreadsheet.createRow((short) 8);
row.createCell(0).setCellValue("set cell type string");
row.createCell(1).setCellValue("A String");
FileOutputStream out = new FileOutputStream(new File("my.xlsx"));
workbook.write(out);
out.close();
System.out.println(
"typesofcells.xlsx written successfully");
本文介绍如何使用Java POI库创建包含不同单元格类型的Excel文件。通过实例演示了设置各种单元格类型的方法,包括空白、布尔值、错误、日期、数值和字符串等。

被折叠的 条评论
为什么被折叠?



