I have 3 different array lists that need to be exported to a开发者_运维技巧 excel spreadsheet using apache poi. The problem I am having is in the format they print to the sheet. Is there a way to have one of the arraylists print straight down a single column?
To print straight down a single column you can try this code.
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));
}
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);
}
精彩评论