worksheet.setColumnWidth(1, (30 * 256));
worksheet.setColumnWidth(4, (20 * 256));
HSSFRow row = worksheet.createRow(0);
HSSFRichTextString value = new HSSFRichTextString("Customers");
value.applyFont(font);
row.createCell(0).setCellValue(value);
row = worksheet.createRow(1);
row.createCell(0).setCellValue(new HSSFRichTextString("Customer Account Details"));
worksheet.createRow(2);
row = worksheet.createRow(3);
HSSFCellStyle style = wb.createCellStyle();
style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
font = wb.createFont();
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
value = new HSSFRichTextString("Name");
value.applyFont(font);
HSSFCell cell = row.createCell(0);
cell.setCellValue(value);
cell.setCellStyle(style);
value = new HSSFRichTextString("Email");
value.applyFont(font);
cell = row.createCell(1);
cell.setCellValue(value);
cell.setCellStyle(style);
value = new HSSFRichTextString("Age");
value.applyFont(font);
cell = row.createCell(2);
cell.setCellValue(value);
cell.setCellStyle(style);
value = new HSSFRichTextString("Holdings");
value.applyFont(font);
cell = row.createCell(3);
cell.setCellValue(value);
cell.setCellStyle(style);
value = new HSSFRichTextString("Investments");
value.applyFont(font);
cell = row.createCell(4);
cell.setCellValue(value);
cell.setCellStyle(style);
int rowIndex = 4;
List<Customer> customers = customerService.getCustomers();
for (Customer customer : customers) {
row = worksheet.createRow(rowIndex++);
row.createCell(0).setCellValue(new HSSFRichTextString(customer.getName()));
row.createCell(1).setCellValue(new HSSFRichTextString(customer.getEmail()));
if (customer.getAge() != null) {
row.createCell(2).setCellValue(customer.getAge().intValue());
}
if (customer.getHoldings() != null) {
row.createCell(3).setCellValue(customer.getHoldings().doubleValue());
}
row.createCell(4).setCellValue(new HSSFRichTextString(customer.getInvestments()));
}
return wb;
}