HSSFSheet sheet;
sheet = wb.createSheet("sheet");
int currentRow = 0;
HSSFRow row;
HSSFCell cell;
CellStyle cellStyle = new CellStyle(wb, (short) headFontSize);
// Overskrift
if (heading != null && heading.length() != 0) {
row = sheet.createRow((short) currentRow++);
createCell(row, cellStyle.getHeadingStyle(), (short) 0, heading);
}
// Kolonneoverskrift
row = sheet.createRow((short) currentRow++);
int columnCount = table.getColumnCount();
int rowCount = table.getRowCount();
// Skriver ut kolonneoverskrift
createColumnHeadings(row, cellStyle.getHeadingStyle(),
table.getModel(), 0, columnCount, 0, notVisibleColumns);
String groupValue = "";
List<ExcelGroupSum> formulaCells = new ArrayList<ExcelGroupSum>();
String groupSumValue = "";
ExcelGroupSum currentExcelGroupSum = null;
// Data
int j;
int k;
int l = currentRow;
// G�r gjennom alle rader og kolonner
for (j = currentRow; j < rowCount + currentRow; j++) {
// dersom data skal grupperes
if (groupColumn != null
&& !table.getValueAt(j - currentRow, groupColumn).equals(
groupValue)) {
// setter forrige grupperingssum
if (currentExcelGroupSum != null) {
currentExcelGroupSum.setToRow((short) (l));
formulaCells.add(currentExcelGroupSum);
groupSumValue = "";
currentExcelGroupSum = null;
}
// henter grupperingsverdi og setter ny overskrift for
// gruppering
groupValue = (String) table.getValueAt(j - currentRow,
groupColumn);
row = sheet.createRow((short) l);
createCell(row, cellStyle.getGroupStyle(), (short) 0,
groupValue);
sheet.addMergedRegion(new Region((short) l, (short) 0,
(short) l,
(short) (columnCount - notVisibleColumnsSize - 1)));
l++;
}
setLabelInfo(labelInfo, infoString, j);
row = sheet.createRow((short) l);
l++;
// g�r gjennom alle kolonner for rad
for (k = 0; k < columnCount; k++) {
// dersom kolonne skal v�re synlig
if (notVisibleColumns == null || !notVisibleColumns.contains(k)) {
// dersom kolonnebredde er satt
if (colSize != null) {
Integer columnSize = colSize.get(k);
if (columnSize != null) {
sheet.setColumnWidth((short) k, columnSize
.shortValue());
}
}
cell = row.createCell((short) k);
// dersom celle har verdi
if (table.getValueAt(j - currentRow, k) != null) {
// dersom det er grupperingssum satt og den er ulik
// forrige
if (groupSumValueColumn != null
&& !table.getValueAt(j - currentRow,
groupSumValueColumn).equals(
groupSumValue)) {
groupSumValue = (String) table.getValueAt(j
- currentRow, groupSumValueColumn);
short dayColorIndex = DayEnum
.getDayColorIndex(groupSumValue);
if (currentExcelGroupSum != null) {
currentExcelGroupSum.setToRow((short) (l - 1));
formulaCells.add(currentExcelGroupSum);
}
if (groupResultColumn != null) {
currentExcelGroupSum = new ExcelGroupSum(
(short) l, row
.createCell(groupResultColumn
.shortValue()),
groupSumColumn.shortValue(),
dayColorIndex, wb.createCellStyle());
}
}
cell.setCellStyle(cellStyle.createDayStyle(wrapText,
groupSumValue));
// dersom kolonne ikke er summeringskolonne
if (groupResultColumn == null || k != groupResultColumn) {
setCellValue(table, numberCols, currentRow, 0,
cell, j, k);
}
// dersom celle ikke har verdi settes den til tomstreng
// for � f� med eventuell formatering
} else {
cell
.setCellStyle(cellStyle.createDayStyle(false,
null));
cell.setCellValue(new HSSFRichTextString(""));
}
}
}
}
// setter siste grupperingssum dersom det finnes