我尝试从java应用程序导出excel是我的代码,但问题是只有最后一列值显示所有其他列都为空,如此图像链接http://i.imgur.com/mTjCYH3.jpg所示。
我使用的是poi-3.10.1。
请提出我需要做出的任何更改。
public class ExcelExport {
public static void main(String[] args) throws IOException {
FileOutputStream fos = null;
File file = null;
file = new File("D:/ExportExcel.xls");
fos = new FileOutputStream(file);
Workbook workbook = new HSSFWorkbook();
Sheet sheet = workbook.createSheet();
Cell cell = sheet.createRow(0).createCell(0);
int row = 0;
while (row < 5) {
for (int column = 0; column < 5; column++) {
cell = sheet.createRow(row).createCell(column);
cell.setCellValue(row + "," + column);
}
row++;
}
workbook.write(fos);
fos.close();
}
}
答案 0 :(得分:0)
正如@BackSlash建议的那样,我的代码工作正常
int row = 0;
while (row < 5) {
Row r = sheet.createRow(row);
for (int column = 0; column < 5; column++) {
cell = r.createCell(column);
cell.setCellValue(row + "," + column);
}
row++;
}