使用 Apache poi 的 API 创建新的行和单元格对象,并在空白表格中写入数据。以下是示例代码:
//创建新的工作簿 Workbook workbook = new XSSFWorkbook();
//创建新的表格 Sheet sheet = workbook.createSheet("Sheet1");
//创建新的行对象 Row row = sheet.createRow(0);
//创建新的单元格对象 Cell cell = row.createCell(0);
//在单元格中写入数据 cell.setCellValue("Hello World");
//将数据写入 Excel 文件中 FileOutputStream fileOut = new FileOutputStream("output.xlsx"); workbook.write(fileOut); fileOut.close();
此代码可以在空白的 Sheet1 表格中创建新的行和单元格对象,并将数据写入单元格中,最后将数据写入 Excel 文件中。