我有一个List<String>
元素很少,我想使用 Apache POI 将这些元素写入 Excel 工作表。此外,我想在每 10 个项目之后将数据放入单独的行中。例如,我的列表有以下元素:
["aaa","bbb","ccc","ddd","eee","fff","ggg","hhh","iii","jjj","kkk","lll","mmm","nnn","ooo","ppp","qqq","rrr","sss","ttt",....]
我想要这个在excel表中,格式如下
col1, col2, col3, col4, col5, col6, col7, col8, col9, col10
row1 : aaa, bbb, ccc, ddd, eee, fff, ggg, hhh, iii, jjj
row2 : kkk, lll, mmm, nnn, ooo, ppp, qqq, rrr, sss, ttt
这可以通过Apache POI实现吗?
我尝试了以下方法(我在循环中真的很糟糕)
public void csvUpdateWorksheet1(String fileName, String sheetName, List<String> data) {
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet(sheetName);
logger.info(data.size());
int rownum = 0;
for (int i = 0; i < data.size(); i++) {
Row row = sheet.createRow(i);
Cell cell = row.createCell(i);
cell.setCellValue(data.get(i));
}
csvWriteToFile(workbook, fileName);
}