HSSFRow row = sheet.createRow((short) 0);
for (int i = 0; i < table.getHeader().getCells().size(); i++) {
HSSFCell cell = row.createCell((short) i);
ResultsStyle style = table.getHeader().getCells().get(i).getStyle();
if (!cellStyleHash.containsKey(style))
cellStyleHash.put(style, style.getStyleHSSF(wb));
cell.setCellStyle(cellStyleHash.get(style));
String title = table.getHeader().getCells().get(i).getValue();
cell.setCellValue(new HSSFRichTextString(title));
sheet.setColumnWidth((short) i,
(short) ((title.length() * MAGICWIDTH + MAGICPADDING) * style.getFontSize()));
}
for (int r = 0; r < table.getRows().size(); r++) {
row = sheet.createRow((short) r + 1);
for (int i = 0; i < table.getRows().get(r).getCells().size(); i++) {
HSSFCell cell = row.createCell((short) i);
ResultsStyle style = table.getRows().get(r).getCells().get(i).getStyle();
if (!cellStyleHash.containsKey(style))
cellStyleHash.put(style, style.getStyleHSSF(wb));
cell.setCellStyle(cellStyleHash.get(style));
String value = table.getRows().get(r).getCells().get(i).getValue();
if (value != null) {
try {
cell.setCellValue(Double.parseDouble(value));
} catch (NumberFormatException e) {
cell.setCellValue(new HSSFRichTextString(value));
}
sheet.setColumnWidth((short) i, (short) Math.max(sheet
.getColumnWidth((short) i),
(short) ((value.length() * MAGICWIDTH + MAGICPADDING) * style
.getFontSize())));
columnWidth[i] = Math.max(columnWidth[i], value.length());
}
}
}