Apache POI在excel中的单元格内创建行或表

时间:2014-06-27 10:03:18

标签: java apache-poi cell rows

我遇到过需要在excel中的单元格中添加表格或行。

我用谷歌搜索但没有找到任何东西。

请帮我知道怎么做。

1 个答案:

答案 0 :(得分:0)

你正在寻找这个吗?

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((short)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
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();