2011-03-26 104 views
0

我有3個不同的數組列表,需要使用apache poi導出到excel電子表格。我遇到的問題是它們打印到表格的格式。有沒有辦法讓其中一個陣列列表直接打印到單個列中?Apache poi,單列輸出爲excel

回答

1

要直接打印一列,你可以試試這段代碼。

Sheet sheet = ....; 

for (int i = 0; i < array1.size(); i++) { 
    Row row = sheet.createRow(i); 
    Cell cell = row.createCell(0); 
    cell.setCellValue(array1.get(i)); 
} 
0
private void createCellAndSetValue(HSSFRow row1, int i, String value,HSSFSheet sheet,HSSFCellStyle style) { 
    HSSFCell cell=row1.createCell(i); 
    setCellValue(cell, value); 
    sheet.autoSizeColumn(i); 
    setCellStyle(cell, style); 
    style.setWrapText(true); 
} 

    for (int i = 0; i < list.Size(); i++) { 
      HSSFRow row = sheet.createRow(count); 
      createCellAndSetValue(row,1,list.get(i),sheet,style); 
      createCellAndSetValue(row,2,listOne.get(i),sheet,style); 
     }