2011-03-26 106 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); 
     }