Search in sources :

Example 11 with StreamWriter

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();
        }
    };
}
Also used : OutputStreamWriter(java.io.OutputStreamWriter) StreamWriter(org.dkpro.lab.storage.StreamWriter) OutputStream(java.io.OutputStream) PrintSetup(org.apache.poi.ss.usermodel.PrintSetup) Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet) Cell(org.apache.poi.ss.usermodel.Cell) Workbook(org.apache.poi.ss.usermodel.Workbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Aggregations

OutputStream (java.io.OutputStream)11 StreamWriter (org.dkpro.lab.storage.StreamWriter)11 OutputStreamWriter (java.io.OutputStreamWriter)10 PrintWriter (java.io.PrintWriter)6 CSVWriter (au.com.bytecode.opencsv.CSVWriter)2 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)2 Cell (org.apache.poi.ss.usermodel.Cell)2 PrintSetup (org.apache.poi.ss.usermodel.PrintSetup)2 Row (org.apache.poi.ss.usermodel.Row)2 Sheet (org.apache.poi.ss.usermodel.Sheet)2 Workbook (org.apache.poi.ss.usermodel.Workbook)2 IOException (java.io.IOException)1 AnalysisEngineDescription (org.apache.uima.analysis_engine.AnalysisEngineDescription)1 ResourceInitializationException (org.apache.uima.resource.ResourceInitializationException)1