use of org.dkpro.lab.storage.StreamWriter in project dkpro-tc by dkpro.
the class TcFlexTable method getExcelWriter.
public StreamWriter getExcelWriter() {
return new StreamWriter() {
@Override
public void write(OutputStream aStream) throws Exception {
String[] colIds = TcFlexTable.this.compact ? getCompactColumnIds(false) : getColumnIds();
Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet("Summary");
PrintSetup printSetup = sheet.getPrintSetup();
printSetup.setLandscape(true);
sheet.setFitToPage(true);
sheet.setHorizontallyCenter(true);
// Header row
{
Row row = sheet.createRow(0);
Cell rowIdCell = row.createCell(0);
rowIdCell.setCellValue("ID");
int colNum = 1;
for (String colId : colIds) {
Cell cell = row.createCell(colNum);
cell.setCellValue(colId);
colNum++;
}
}
// Body rows
{
int rowNum = 1;
for (String rowId : getRowIds()) {
Row row = sheet.createRow(rowNum);
Cell rowIdCell = row.createCell(0);
rowIdCell.setCellValue(rowId);
int colNum = 1;
for (String colId : colIds) {
Cell cell = row.createCell(colNum);
String value = getValueAsString(rowId, colId);
try {
cell.setCellValue(Double.valueOf(value));
} catch (NumberFormatException e) {
cell.setCellValue(value);
}
colNum++;
}
rowNum++;
}
}
wb.write(aStream);
wb.close();
}
};
}
Aggregations