Example usage for org.apache.poi.ss.usermodel Row setHeightInPoints

List of usage examples for org.apache.poi.ss.usermodel Row setHeightInPoints

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel Row setHeightInPoints.

Prototype

void setHeightInPoints(float height);

Source Link

Document

Set the row's height in points.

Usage

From source file:org.sigmah.server.endpoint.export.Export.java

License:Open Source License

private void createHeaders(ActivityDTO activity, HSSFSheet sheet) {

    /// The HEADER rows

    Row headerRow1 = sheet.createRow(0);
    Row headerRow2 = sheet.createRow(1);
    headerRow2.setHeightInPoints(75);

    int column = 0;
    createHeaderCell(headerRow2, column++, "Date1", CellStyle.ALIGN_RIGHT);
    createHeaderCell(headerRow2, column++, "Date2", CellStyle.ALIGN_RIGHT);

    createHeaderCell(headerRow2, column, "Partner");
    sheet.setColumnWidth(column, 16 * 256);
    column++;//  w  w w.  ja  v  a2s .  c  o m

    createHeaderCell(headerRow2, column, activity.getLocationType().getName());
    sheet.setColumnWidth(column, 20 * 256);
    column++;

    createHeaderCell(headerRow2, column++, "Axe");

    indicators = new ArrayList<Integer>(activity.getIndicators().size());
    if (activity.getReportingFrequency() == ActivityDTO.REPORT_ONCE) {
        for (IndicatorGroup group : activity.groupIndicators()) {
            if (group.getName() != null) {
                // create a merged cell on the top row spanning all members of the group
                createHeaderCell(headerRow1, column, group.getName());
                sheet.addMergedRegion(
                        new CellRangeAddress(0, 0, column, column + group.getIndicators().size() - 1));
            }
            for (IndicatorDTO indicator : group.getIndicators()) {
                indicators.add(indicator.getId());
                createHeaderCell(headerRow2, column, indicator.getName(), indicatorHeaderStyle);
                sheet.setColumnWidth(column, 16 * 256);
                column++;
            }
        }
    }
    attributes = new ArrayList<Integer>();
    int firstAttributeColumn = column;
    for (AttributeGroupDTO group : activity.getAttributeGroups()) {
        if (group.getAttributes().size() != 0) {
            createHeaderCell(headerRow1, column, group.getName(), CellStyle.ALIGN_CENTER);
            sheet.addMergedRegion(
                    new CellRangeAddress(0, 0, column, column + group.getAttributes().size() - 1));

            for (AttributeDTO attrib : group.getAttributes()) {
                attributes.add(attrib.getId());
                createHeaderCell(headerRow2, column, attrib.getName(), attribHeaderStyle);
                sheet.setColumnWidth(column, 5 * 256);
                column++;
            }
        }
    }
    //        sheet.getSheetConditionalFormatting().addConditionalFormatting(
    //                new CellRangeAddress[] { new CellRangeAddress(2, 65535, firstAttributeColumn, column-1) },
    //                new HSSFConditionalFormattingRule[] { attribTrueRule, attribFalseRule });

    levels = new ArrayList<Integer>();
    for (AdminLevelDTO level : activity.getAdminLevels()) {
        createHeaderCell(headerRow2, column++, "Code " + level.getName());
        createHeaderCell(headerRow2, column++, level.getName());
        levels.add(level.getId());
    }
    createHeaderCell(headerRow2, column, "Longitude", CellStyle.ALIGN_RIGHT);
    createHeaderCell(headerRow2, column + 1, "Latitude", CellStyle.ALIGN_RIGHT);
    sheet.setColumnWidth(column, 12 * 256);
    sheet.setColumnWidth(column + 1, 12 * 256);

}

From source file:org.unitime.timetable.export.XLSPrinter.java

License:Apache License

@Override
public void printHeader(String... fields) {
    Row headerRow = iSheet.createRow(iRowNum++);

    int cellIdx = 0;
    int nrLines = 1;
    for (int idx = 0; idx < fields.length; idx++) {
        if (iHiddenColumns.contains(idx))
            continue;
        Cell cell = headerRow.createCell(cellIdx++);
        cell.setCellStyle(iStyles.get("header"));
        cell.setCellValue(fields[idx]);//from   w  w w  .  java 2s .c o  m
        if (fields[idx] != null)
            nrLines = Math.max(nrLines, fields[idx].split("\n").length);
    }
    if (nrLines > 1)
        headerRow.setHeightInPoints(nrLines * iSheet.getDefaultRowHeightInPoints() + 1f);
}

From source file:org.unitime.timetable.export.XLSPrinter.java

License:Apache License

@Override
public void printLine(String... fields) {
    int cellIdx = 0;
    Row row = iSheet.createRow(iRowNum++);
    int nrLines = 1;
    for (int idx = 0; idx < fields.length; idx++) {
        if (iHiddenColumns.contains(idx))
            continue;
        if (iHiddenColumns.contains(idx))
            continue;
        Cell cell = row.createCell(cellIdx++);

        String f = fields[idx];//from   w ww  .j a v a  2  s  .  c  o  m
        if (f == null || f.isEmpty() || (iCheckLast
                && f.equals(iLastLine == null || idx >= iLastLine.length ? null : iLastLine[idx])))
            f = "";

        boolean number = sNumber.matcher(f).matches();

        cell.setCellStyle(iStyles.get(number ? "number" : "plain"));
        if (f == null || f.isEmpty()) {
        } else if (number) {
            try {
                cell.setCellValue(Double.valueOf(f));
            } catch (NumberFormatException e) {
                cell.setCellValue(f);
            }
        } else {
            nrLines = Math.max(nrLines, f.split("\n").length);
            cell.setCellValue(f);
        }
    }
    if (nrLines > 1)
        row.setHeightInPoints(nrLines * iSheet.getDefaultRowHeightInPoints() + 1f);
    iLastLine = fields;
}

From source file:org.unitime.timetable.export.XLSPrinter.java

License:Apache License

public void printLine(A... fields) {
    int cellIdx = 0;
    Row row = iSheet.createRow(iRowNum++);
    int nrLines = 1;
    for (int idx = 0; idx < fields.length; idx++) {
        if (iHiddenColumns.contains(idx))
            continue;
        Cell cell = row.createCell(cellIdx++);

        A f = fields[idx];/*from  ww  w  .j a va 2s .c o  m*/
        if (f == null || f.isEmpty() || (iCheckLast
                && f.equals(iLastLine == null || idx >= iLastLine.length ? null : iLastLine[idx]))) {
            f = new A();
            if (fields[idx] != null && fields[idx].has(F.NOSEPARATOR))
                f.set(F.NOSEPARATOR);
        }

        cell.setCellStyle(getStyle(f, iLastLine == null && !f.has(F.NOSEPARATOR), f.getPattern()));

        if (f.hasBufferedImage()) {
            try {
                addImageToSheet(cellIdx - 1, iRowNum - 1, (HSSFSheet) iSheet, f.getBufferedImage(),
                        EXPAND_ROW_AND_COLUMN);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        if (f.isNumber()) {
            cell.setCellValue(f.getNumber());
        } else if (f.isDate()) {
            cell.setCellValue(f.getDate());
        } else if (f.hasText()) {
            boolean number = sNumber.matcher(f.getText()).matches();
            if (number && f.has(F.RIGHT)) {
                try {
                    cell.setCellValue(Double.valueOf(f.getText()));
                } catch (NumberFormatException e) {
                    cell.setCellValue(f.getText());
                }
            } else {
                cell.setCellValue(f.getText());
                nrLines = Math.max(nrLines, f.getText().split("\n").length);
            }
        } else if (f.hasChunks()) {
            StringBuffer text = new StringBuffer();
            List<Object[]> font = new ArrayList<Object[]>();
            for (A g : f.getChunks()) {
                if (g.hasText()) {
                    if (text.length() > 0)
                        text.append(f.has(F.INLINE) ? " " : "\n");
                    font.add(new Object[] { text.length(),
                            getFont(g.has(F.BOLD), g.has(F.ITALIC), g.has(F.UNDERLINE), g.getColor())
                                    .getIndex() });
                    text.append(g.getText());
                }
                if (g.hasChunks()) {
                    for (A h : g.getChunks()) {
                        if (h.hasText()) {
                            if (text.length() > 0)
                                text.append(" ");
                            font.add(new Object[] { text.length(),
                                    getFont(h.has(F.BOLD), h.has(F.ITALIC), h.has(F.UNDERLINE), h.getColor())
                                            .getIndex() });
                            text.append(h.getText());
                        }
                    }
                }
            }
            nrLines = Math.max(nrLines, text.toString().split("\n").length);
            font.add(new Object[] { text.length(), (short) 0 });
            HSSFRichTextString value = new HSSFRichTextString(text.toString());
            for (int i = 0; i < font.size() - 1; i++)
                value.applyFont((Integer) font.get(i)[0], (Integer) font.get(1 + i)[0], (Short) font.get(i)[1]);
            cell.setCellValue(value);
        }
    }
    if (nrLines > 1)
        row.setHeightInPoints(
                Math.max(nrLines * iSheet.getDefaultRowHeightInPoints() + 1f, row.getHeightInPoints()));
    iLastLine = fields;
}

From source file:org.xianairlines.action.staffs.StaffsList.java

public void exportStaffsByColumNames() throws UnsupportedEncodingException {
    ServletOutputStream os = null;//  w ww.  j  a v a2s  .c  o  m
    try {
        final HttpServletResponse response = (HttpServletResponse) extCtx.getResponse();
        os = response.getOutputStream();
        response.setContentType("application/x-download");
        final String newFileName = encodeFileName("??.xls");
        response.addHeader("Content-disposition", "attachment;filename=" + newFileName + ";charset=UTF-8");
        Workbook wb = new HSSFWorkbook();
        Sheet sheet1 = wb.createSheet("sheet1");
        Row row = null;
        Cell cell = null;
        CellStyle cellStyle = wb.createCellStyle();
        // ?
        cellStyle.setBorderBottom(CellStyle.BORDER_THIN);
        cellStyle.setBorderTop(CellStyle.BORDER_THIN);
        cellStyle.setBorderLeft(CellStyle.BORDER_THIN);
        cellStyle.setBorderRight(CellStyle.BORDER_THIN);
        // ?
        cellStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
        cellStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());
        cellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
        cellStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());
        cellStyle.setAlignment(CellStyle.ALIGN_CENTER);
        cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
        // Font
        Font font = wb.createFont();
        font.setFontName("");
        font.setColor(HSSFColor.BLUE.index);
        font.setItalic(true);
        font.setFontHeight((short) 300);
        row = sheet1.createRow(0);
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
        for (int i = 0; i < columNames.length; i++) {
            sheet1.setColumnWidth(i, (short) 6000);
            String[] colums = columNames[i].split(",");
            cell = row.createCell(i);
            cell.setCellStyle(cellStyle);
            cell.setCellValue(colums[1]);
        }
        List<Staffs> list = this.getResultList();
        for (int i = 1; i <= list.size(); i = i + 1) {
            row = sheet1.createRow(i);
            row.setHeightInPoints(20);
            for (int j = 0; j < columNames.length; j++) {
                String[] colums = columNames[j].split(",");
                cell = row.createCell(j);
                cell.setCellStyle(cellStyle);
                Object value = this.getStaffsFieldValue((Staffs) list.get(i - 1), colums[0]);
                if (value == null) {
                    cell.setCellValue("");
                } else if (value instanceof java.util.Date) {
                    String cellValue = dateFormat.format((java.util.Date) value);
                    cell.setCellValue(cellValue);
                } else {
                    cell.setCellValue(value.toString());
                }

            }
        }
        wb.write(os);
        os.flush();
    } catch (Exception e) {
    } finally {
        if (os != null) {
            try {
                os.close();
            } catch (IOException e) {
            }
        }
        facesContext.responseComplete();
    }

}

From source file:OutputStyles.DiffExcelDefault.java

private void SetHeaderRow(Sheet sheet, TreeSet<String> sampleSet, TreeSet<String> comparisonSet) {
    // Merged upper row
    Row FHeaderRow = sheet.createRow(0);

    FHeaderRow.setHeightInPoints(20f);
    Cell locCell = FHeaderRow.createCell(0);
    locCell.setCellValue("Gene and Location Data");
    locCell.setCellStyle(this.headerStyles.get("grey"));
    CellRangeAddress first = new CellRangeAddress(0, 0, 0, 4);

    Cell sampCell = FHeaderRow.createCell(5);
    sampCell.setCellValue("Sample RPKM values");
    sampCell.setCellStyle(this.headerStyles.get("grey"));
    CellRangeAddress second = new CellRangeAddress(0, 0, 5, sampleSet.size() + 4);

    sheet.addMergedRegion(first);/*  www.  j  a  v a 2 s .c  o m*/
    sheet.addMergedRegion(second);

    //int col = 5 + sampleSet.size();
    Iterator<String> compItr = comparisonSet.descendingIterator();
    for (int i = 5 + sampleSet.size(); compItr.hasNext(); i += 6) {
        Cell temp = FHeaderRow.createCell(i);
        String s = compItr.next();
        temp.setCellValue(s);
        temp.setCellStyle(this.headerStyles.get(s));
        sheet.addMergedRegion(new CellRangeAddress(0, 0, i, i + 5));
        //col += 6;
    }
    //CellRangeAddress third = new CellRangeAddress(0,0, 5 + sampleSet.size(), col - 6);

    // Non-merged second row
    Row SHeaderRow = sheet.createRow(1);

    for (int i = 0; i < this.coordheaders.length; i++) {
        Cell temp = SHeaderRow.createCell(i);
        temp.setCellValue(coordheaders[i]);
        temp.setCellStyle(headerStyles.get("grey"));
    }
    Iterator<String> samps = sampleSet.descendingIterator();
    for (int i = coordheaders.length; i < sampleSet.size() + coordheaders.length; i++) {
        Cell temp = SHeaderRow.createCell(i);
        temp.setCellValue(samps.next());
        temp.setCellStyle(headerStyles.get("grey"));
    }

    int op = 0;
    for (int i = coordheaders.length + sampleSet.size(); i < coordheaders.length + sampleSet.size()
            + (comparisonSet.size() * 6); i++) {
        Cell temp = SHeaderRow.createCell(i);
        temp.setCellValue(this.diffheaders[op]);
        temp.setCellStyle(headerStyles.get("grey"));
        op++;
        if (op >= 6)
            op = 0;
    }

    System.err.println("[DIFF OUT] Created Header Row for output");
}

From source file:packtest.NewLinesInCells.java

License:Apache License

public static void main(String[] args) throws Exception {
    Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
    Sheet sheet = wb.createSheet();// www.  j  a v a 2s  . co m

    Row row = sheet.createRow(2);
    Cell cell = row.createCell(2);
    cell.setCellValue("Use \n with word wrap on to create a new line");

    //to enable newlines you need set a cell styles with wrap=true
    CellStyle cs = wb.createCellStyle();
    cs.setWrapText(true);
    cell.setCellStyle(cs);

    //increase row height to accomodate two lines of text
    row.setHeightInPoints((2 * sheet.getDefaultRowHeightInPoints()));

    //adjust column width to fit the content
    sheet.autoSizeColumn(2);

    FileOutputStream fileOut = new FileOutputStream("ooxml-newlines.xlsx");
    wb.write(fileOut);
    fileOut.close();
}

From source file:poi.ReadWriteWorkbook.java

License:Apache License

public static void main(String[] args) throws IOException {
    Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();

    Sheet sheet = wb.createSheet();//from ww  w.j  a  v  a2  s.  co  m
    Row row = sheet.createRow((short) 2);
    row.setHeightInPoints(30);

    createCell(wb, row, (short) 0, CellStyle.ALIGN_CENTER, CellStyle.VERTICAL_BOTTOM);
    createCell(wb, row, (short) 1, CellStyle.ALIGN_CENTER_SELECTION, CellStyle.VERTICAL_BOTTOM);
    createCell(wb, row, (short) 2, CellStyle.ALIGN_FILL, CellStyle.VERTICAL_CENTER);
    createCell(wb, row, (short) 3, CellStyle.ALIGN_GENERAL, CellStyle.VERTICAL_CENTER);
    createCell(wb, row, (short) 4, CellStyle.ALIGN_JUSTIFY, CellStyle.VERTICAL_JUSTIFY);
    createCell(wb, row, (short) 5, CellStyle.ALIGN_LEFT, CellStyle.VERTICAL_TOP);
    createCell(wb, row, (short) 6, CellStyle.ALIGN_RIGHT, CellStyle.VERTICAL_TOP);

    // Write the output to a file
    FileOutputStream fileOut = new FileOutputStream("E:\\excel\\test\\xssf-align.xlsx");
    wb.write(fileOut);
    fileOut.close();
}

From source file:project1.TimesheetDemo.java

License:Apache License

public static void main(String[] args) throws Exception {
    Workbook wb;/* w w w .j a v  a 2 s .c  om*/

    //     if(args.length > 0 && args[0].equals("-xls")) wb = new HSSFWorkbook();
    //     else 
    wb = new XSSFWorkbook();

    Map<String, CellStyle> styles = createStyles(wb);

    Sheet sheet = wb.createSheet("Timesheet");
    PrintSetup printSetup = sheet.getPrintSetup();
    printSetup.setLandscape(true);
    sheet.setFitToPage(true);
    sheet.setHorizontallyCenter(true);

    //title row
    Row titleRow = sheet.createRow(0);
    titleRow.setHeightInPoints(45);
    Cell titleCell = titleRow.createCell(0);
    titleCell.setCellValue("Weekly Timesheet");
    titleCell.setCellStyle(styles.get("title"));
    sheet.addMergedRegion(CellRangeAddress.valueOf("$A$1:$L$1"));

    //header row
    Row headerRow = sheet.createRow(1);
    headerRow.setHeightInPoints(40);
    Cell headerCell;
    for (int i = 0; i < titles.length; i++) {
        headerCell = headerRow.createCell(i);
        headerCell.setCellValue(titles[i]);
        headerCell.setCellStyle(styles.get("header"));
    }

    int rownum = 2;
    for (int i = 0; i < 10; i++) {
        Row row = sheet.createRow(rownum++);
        for (int j = 0; j < titles.length; j++) {
            Cell cell = row.createCell(j);
            if (j == 9) {
                //the 10th cell contains sum over week days, e.g. SUM(C3:I3)
                String ref = "C" + rownum + ":I" + rownum;
                cell.setCellFormula("SUM(" + ref + ")");
                cell.setCellStyle(styles.get("formula"));
            } else if (j == 11) {
                cell.setCellFormula("J" + rownum + "-K" + rownum);
                cell.setCellStyle(styles.get("formula"));
            } else {
                cell.setCellStyle(styles.get("cell"));
            }
        }
    }

    //row with totals below
    Row sumRow = sheet.createRow(rownum++);
    sumRow.setHeightInPoints(35);
    Cell cell;
    cell = sumRow.createCell(0);
    cell.setCellStyle(styles.get("formula"));
    cell = sumRow.createCell(1);
    cell.setCellValue("Total Hrs:");
    cell.setCellStyle(styles.get("formula"));

    for (int j = 2; j < 12; j++) {
        cell = sumRow.createCell(j);
        String ref = (char) ('A' + j) + "3:" + (char) ('A' + j) + "12";
        cell.setCellFormula("SUM(" + ref + ")");
        if (j >= 9)
            cell.setCellStyle(styles.get("formula_2"));
        else
            cell.setCellStyle(styles.get("formula"));
    }
    rownum++;
    sumRow = sheet.createRow(rownum++);
    sumRow.setHeightInPoints(25);
    cell = sumRow.createCell(0);
    cell.setCellValue("Total Regular Hours");
    cell.setCellStyle(styles.get("formula"));
    cell = sumRow.createCell(1);
    cell.setCellFormula("L13");
    cell.setCellStyle(styles.get("formula_2"));
    sumRow = sheet.createRow(rownum++);
    sumRow.setHeightInPoints(25);
    cell = sumRow.createCell(0);
    cell.setCellValue("Total Overtime Hours");
    cell.setCellStyle(styles.get("formula"));
    cell = sumRow.createCell(1);
    cell.setCellFormula("K13");
    cell.setCellStyle(styles.get("formula_2"));

    //set sample data
    for (int i = 0; i < sample_data.length; i++) {
        Row row = sheet.getRow(2 + i);
        for (int j = 0; j < sample_data[i].length; j++) {
            if (sample_data[i][j] == null)
                continue;

            if (sample_data[i][j] instanceof String) {
                row.getCell(j).setCellValue((String) sample_data[i][j]);
            } else {
                row.getCell(j).setCellValue((Double) sample_data[i][j]);
            }
        }
    }

    //finally set column widths, the width is measured in units of 1/256th of a character width
    sheet.setColumnWidth(0, 30 * 256); //30 characters wide
    for (int i = 2; i < 9; i++) {
        sheet.setColumnWidth(i, 6 * 256); //6 characters wide
    }
    sheet.setColumnWidth(10, 10 * 256); //10 characters wide

    // Write the output to a file
    String file = "timesheet.xls";
    if (wb instanceof XSSFWorkbook)
        file += "x";
    FileOutputStream out = new FileOutputStream(file);
    wb.write(out);
    out.close();
}

From source file:qmul.align.AlignmentTester.java

License:Open Source License

/**
 * Process a single dialogue/*from ww  w .  j  a  va2 s.  com*/
 * 
 * @param d
 *            the dialogue to process
 * @param wb
 *            the XLS workbook to write to, or null not to bother
 * @return a list of {@link Double} scores, one per {@link DialogueWindower} step (e.g. dialogue turn)
 */
public List<Double> processDialogue(Dialogue d, Workbook wb, HashMap<String, ArrayList<Double>> speakerScores,
        HashMap<String, String> originalSpks, HashMap<String, ArrayList<Double>> speakerN,
        MetricsMap spkMetrics, MetricsMap totMetrics, Workbook wbcounts,
        HashMap<String, HashMap<Object, Integer>> allCounts,
        HashMap<String, HashMap<Object, Integer>> commonCounts, HashMap<Object, Integer> diaAllCounts,
        HashMap<Object, Integer> diaCommonCounts) {

    CreationHelper creationHelper = wb.getCreationHelper();

    win.setDialogue(d);
    sim.reset();
    ArrayList<DialogueSpeaker> spks = new ArrayList<DialogueSpeaker>(d.getSpeakers());
    Collections.sort(spks);
    Sheet sheet = (wb == null ? null : wb.createSheet(d.getId().replaceAll(":", "-")));
    Sheet sheetcounts = (wbcounts == null ? null : wbcounts.createSheet(d.getId().replaceAll(":", "-")));
    int iRow = 0;
    if (sheet != null) {
        iRow = writeSheetHeader(creationHelper, sheet, iRow, d, spks);
    }
    int iCRow = 0;
    if (sheetcounts != null) {
        iCRow = writeSheetHeader(creationHelper, sheet, iCRow, d, spks);
    }
    ArrayList<Double> scores = new ArrayList<Double>();
    HashSet<X> counted = new HashSet<X>();
    do {
        List<X> left = win.getLeftWindow();
        Collections.reverse(left); // windowers return things in dialogue order: we'll look progressively backwards
        List<X> right = win.getRightWindow();
        // System.out.println("lengthS " + left.size() + " " + right.size());
        double score = 0.0;
        double n = 0.0;
        for (X r : right) {
            String spkKey = makeSpkKey(r.getSpeaker(), d);
            String originalSpkKey = "";
            if (r.getOriginalSpeaker() != null) {
                originalSpkKey = r.getOriginalSpeaker().getId();
                // fix for the fact that BNC speakers are not currently given SUBdialogue ID in their ID - TODO
                // change that?
                Dialogue od = r.getOriginalDialogue();
                if ((od == null) && (r instanceof DialogueSentence)) {
                    od = ((DialogueSentence) r).getTurn().getOriginalDialogue();
                }
                String originalDia;
                if (od != null) {
                    originalDia = od.getId();
                } else {
                    originalDia = d.getId().replaceFirst("-\\d+$", "");
                }
                if (!originalSpkKey.contains(originalDia)) {
                    if (!originalDia.contains(":")) {
                        throw new RuntimeException("can't find super-dialogue, no : in " + originalDia);
                    }
                    String originalSuperDia = originalDia.substring(0, originalDia.lastIndexOf(":"));
                    if (originalSpkKey.contains(originalSuperDia)) {
                        originalSpkKey = originalSpkKey.replace(originalSuperDia, originalDia);
                    } else {
                        throw new RuntimeException("spk key without super-dialogue " + spkKey + ", "
                                + originalSpkKey + ", " + originalDia);
                    }
                }
            }
            Row row = (wb == null ? null : sheet.createRow(iRow++));
            int iCol = 0;
            Cell cell = (wb == null ? null : row.createCell(iCol++, Cell.CELL_TYPE_STRING));
            if (cell != null) {
                cell.setCellValue(creationHelper.createRichTextString(r.getSpeaker().getId()));
                cell = row.createCell(iCol++, Cell.CELL_TYPE_STRING);
                cell.setCellValue(creationHelper.createRichTextString(originalSpkKey));
                // cell = row.createCell(iCol++, Cell.CELL_TYPE_STRING);
                // cell.setCellValue(creationHelper.createRichTextString(r.getId()));
                cell = row.createCell(iCol++, Cell.CELL_TYPE_STRING);
                cell.setCellValue(creationHelper.createRichTextString(r.toString()));
                row.setHeightInPoints(12);
                sheet.setColumnWidth(iCol - 1, 2560);
            }
            if (!speakerScores.containsKey(spkKey)) {
                speakerScores.put(spkKey, new ArrayList<Double>());
                speakerN.put(spkKey, new ArrayList<Double>());
                originalSpks.put(spkKey, originalSpkKey);
                for (int i = 0; i < win.getLeftWindowSize(); i++) {
                    speakerScores.get(spkKey).add(0.0);
                    speakerN.get(spkKey).add(0.0);
                }
                Boolean isTurns = null;
                if (left.size() > 0) {
                    isTurns = (left.get(0) instanceof DialogueTurn);
                } else if (right.size() > 0) {
                    isTurns = (right.get(0) instanceof DialogueTurn);
                }
                spkMetrics.setNumUnits(spkKey, 0);
                totMetrics.setNumUnits(d.getId(), (isTurns ? d.numTurns() : d.numSents()));
                spkMetrics.setNumWords(spkKey, 0);
                totMetrics.setNumWords(d.getId(), d.numWords());
                spkMetrics.setNumTokens(spkKey, 0);
                totMetrics.setNumTokens(d.getId(), d.numTokens());
            }
            int iLeft = 0;
            double offset = Double.NaN;
            boolean gotOffset = false;
            for (X l : left) {
                double s = sim.similarity(l, r);
                // System.out.println("Siml = " + s + " for l:" + l.getId() + " r:" + r.getId());
                if ((l.getOriginalId() != null) && (r.getOriginalId() != null)
                        && l.getOriginalId().equals(r.getOriginalId())) {
                    System.out.println("Equal IDs sim = " + s + " for l:" + l.getId() + " " + l.getOriginalId()
                            + " r:" + r.getId() + " " + r.getOriginalId() + " d " + d.getId() + " nturns "
                            + d.numTurns());
                }
                if (wbcounts != null) {
                    if (!counted.contains(l)) {
                        MapUtil.addAll(diaAllCounts, sim.rawCountsA());
                        MapUtil.addAll(allCounts.get(""), sim.rawCountsA());
                        MapUtil.addAll(allCounts.get(d.getGenre()), sim.rawCountsA());
                        counted.add(l);
                    }
                    if (!counted.contains(r)) {
                        MapUtil.addAll(diaAllCounts, sim.rawCountsB());
                        MapUtil.addAll(allCounts.get(""), sim.rawCountsB());
                        MapUtil.addAll(allCounts.get(d.getGenre()), sim.rawCountsB());
                        counted.add(r);
                    }
                    MapUtil.addAll(diaCommonCounts, sim.rawCountsAB());
                    MapUtil.addAll(commonCounts.get(""), sim.rawCountsAB());
                    MapUtil.addAll(commonCounts.get(d.getGenre()), sim.rawCountsAB());
                }
                cell = (wb == null ? null : row.createCell(iCol++, Cell.CELL_TYPE_NUMERIC));
                if (cell != null) {
                    cell.setCellValue(s);
                }
                score += s;
                n++;
                speakerScores.get(spkKey).set(iLeft, speakerScores.get(spkKey).get(iLeft) + s);
                speakerN.get(spkKey).set(iLeft, speakerN.get(spkKey).get(iLeft) + 1);
                if (!win.getClass().toString().contains("AllOther")) { // for "all other" windowers, actually
                    // average over "window"
                    iLeft++;
                }
                if (!gotOffset) {
                    offset = r.getStartTime() - l.getEndTime();
                    gotOffset = true;
                    // if (!Double.isNaN(offset)) {
                    // System.out.println("Offset = " + offset + " for l:" + l.getId() + " r:" + r.getId());
                    // }
                }
            }
            // print number sents/words/tokens
            iCol += (win.getLeftWindowSize() - left.size() + 1);
            if (wb != null) { // if we are writing to a workbook
                cell = (wb == null ? null : row.createCell(iCol++, Cell.CELL_TYPE_NUMERIC));
                cell.setCellValue(r instanceof DialogueTurn ? ((DialogueTurn) r).getSents().size() : 1);
                cell = (wb == null ? null : row.createCell(iCol++, Cell.CELL_TYPE_NUMERIC));
                cell.setCellValue(r.numWords());
                cell = (wb == null ? null : row.createCell(iCol++, Cell.CELL_TYPE_NUMERIC));
                cell.setCellValue(r.numTokens());
            }
            iCol += 1;
            if (!Double.isNaN(offset)) {
                cell = (wb == null ? null : row.createCell(iCol++, Cell.CELL_TYPE_NUMERIC));
                cell.setCellValue(offset);
            } else {
                iCol++;
            }
            double wordRate = (double) (r.getEndTime() - r.getStartTime()) / (double) r.numWords();
            if (r.numWords() == 0) {
                wordRate = Double.NaN; // on some OSs this doesn't happen in the calc above
            }
            if (!Double.isNaN(wordRate)) {
                cell = (wb == null ? null : row.createCell(iCol++, Cell.CELL_TYPE_NUMERIC));
                cell.setCellValue(wordRate);
            } else {
                iCol++;
            }
            // make sure we counted this one - the first one can get missed if leftWindow empty
            if ((wbcounts != null) && !counted.contains(r)) {
                sim.similarity(r, r);
                MapUtil.addAll(diaAllCounts, sim.rawCountsA());
                MapUtil.addAll(allCounts.get(""), sim.rawCountsA());
                MapUtil.addAll(allCounts.get(d.getGenre()), sim.rawCountsA());
                counted.add(r);
            }
            spkMetrics.setNumUnits(spkKey, spkMetrics.getNumUnits(spkKey) + 1);
            spkMetrics.setNumWords(spkKey, spkMetrics.getNumWords(spkKey) + r.numWords());
            spkMetrics.setNumTokens(spkKey, spkMetrics.getNumTokens(spkKey) + r.numTokens());
            if (!Double.isNaN(offset)) {
                spkMetrics.setTurnOffset(spkKey, spkMetrics.getTurnOffset(spkKey) + offset);
                spkMetrics.setNumTurnOffsets(spkKey, spkMetrics.getNumTurnOffsets(spkKey) + 1);
                totMetrics.setTurnOffset(d.getId(), totMetrics.getTurnOffset(d.getId()) + offset);
                totMetrics.setNumTurnOffsets(d.getId(), totMetrics.getNumTurnOffsets(d.getId()) + 1);
            }
            if (!Double.isNaN(wordRate)) {
                spkMetrics.setWordRate(spkKey, spkMetrics.getWordRate(spkKey) + wordRate);
                spkMetrics.setNumWordRates(spkKey, spkMetrics.getNumWordRates(spkKey) + 1);
                totMetrics.setWordRate(d.getId(), totMetrics.getWordRate(d.getId()) + wordRate);
                totMetrics.setNumWordRates(d.getId(), totMetrics.getNumWordRates(d.getId()) + 1);
            }
        }
        scores.add((n == 0.0) ? 0.0 : (score / n));
    } while (win.advance());
    if (wb != null) {
        iRow++;
        for (DialogueSpeaker spk : spks) {
            String spkKey = makeSpkKey(spk, d);
            Row row = sheet.createRow(iRow++);
            int iCol = 0;
            row.createCell(iCol++, Cell.CELL_TYPE_STRING)
                    .setCellValue(creationHelper.createRichTextString(spk.getId()));
            row.createCell(iCol++, Cell.CELL_TYPE_STRING)
                    .setCellValue(creationHelper.createRichTextString(originalSpks.get(spkKey)));
            row.createCell(iCol++, Cell.CELL_TYPE_STRING)
                    .setCellValue(creationHelper.createRichTextString("Mean"));
            for (int i = 0; i < win.getLeftWindowSize(); i++) {
                if (speakerN.get(spkKey).get(i) > 0) {
                    row.createCell(iCol++, Cell.CELL_TYPE_NUMERIC)
                            .setCellValue(speakerScores.get(spkKey).get(i) / speakerN.get(spkKey).get(i));
                } else {
                    iCol++;
                }
                // System.out
                // .println("score " + i + " for speaker " + spkKey + "=" + speakerScores.get(spkKey).get(i));
                // System.out.println("N " + i + " for speaker " + spkKey + "=" + speakerN.get(spkKey).get(i));
                // System.out.println("mean " + i + " for speaker " + spkKey + "="
                // + (speakerScores.get(spkKey).get(i) / speakerN.get(spkKey).get(i)));
            }
            iCol++;
            row.createCell(iCol++, Cell.CELL_TYPE_NUMERIC).setCellValue(
                    (double) spkMetrics.getNumUnits(spkKey) / (double) spkMetrics.getNumUnits(spkKey));
            row.createCell(iCol++, Cell.CELL_TYPE_NUMERIC).setCellValue(
                    (double) spkMetrics.getNumWords(spkKey) / (double) spkMetrics.getNumUnits(spkKey));
            row.createCell(iCol++, Cell.CELL_TYPE_NUMERIC).setCellValue(
                    (double) spkMetrics.getNumTokens(spkKey) / (double) spkMetrics.getNumUnits(spkKey));
            iCol++;
            row.createCell(iCol++, Cell.CELL_TYPE_NUMERIC).setCellValue(
                    (double) spkMetrics.getTurnOffset(spkKey) / (double) spkMetrics.getNumTurnOffsets(spkKey));
            row.createCell(iCol++, Cell.CELL_TYPE_NUMERIC).setCellValue(
                    (double) spkMetrics.getWordRate(spkKey) / (double) spkMetrics.getNumWordRates(spkKey));
        }
    }
    if (wbcounts != null) {
        iCRow++;
        ArrayList<Object> keys = new ArrayList<Object>(diaAllCounts.keySet());
        Collections.sort(keys, new DescendingComparator<Object>(diaAllCounts));
        for (Object key : keys) {
            Row row = sheetcounts.createRow(iCRow++);
            int iCol = 0;
            row.createCell(iCol++, Cell.CELL_TYPE_STRING)
                    .setCellValue(creationHelper.createRichTextString(key.toString()));
            Cell cell = row.createCell(iCol++, Cell.CELL_TYPE_NUMERIC);
            if (diaAllCounts.get(key) != null) {
                cell.setCellValue(diaAllCounts.get(key));
            }
            cell = row.createCell(iCol++, Cell.CELL_TYPE_NUMERIC);
            if (diaCommonCounts.get(key) != null) {
                cell.setCellValue(diaCommonCounts.get(key));
            }
        }
    }
    return scores;
}