Example usage for org.apache.poi.hssf.usermodel HSSFSheet setRepeatingRows

List of usage examples for org.apache.poi.hssf.usermodel HSSFSheet setRepeatingRows

Introduction

In this page you can find the example usage for org.apache.poi.hssf.usermodel HSSFSheet setRepeatingRows.

Prototype

@Override
    public void setRepeatingRows(CellRangeAddress rowRangeRef) 

Source Link

Usage

From source file:io.vertigo.quarto.plugins.export.xls.XLSExporter.java

License:Apache License

private void exportList(final ExportSheet parameters, final HSSFWorkbook workbook, final HSSFSheet sheet,
        final Map<Integer, Double> maxWidthPerColumn) {
    // exporte le header
    final HSSFRow headerRow = sheet.createRow(0);
    int cellIndex = 0;
    for (final ExportField exportColumn : parameters.getExportFields()) {
        final HSSFCell cell = headerRow.createCell(cellIndex);
        final String displayedLabel = exportColumn.getLabel().getDisplay();
        cell.setCellValue(new HSSFRichTextString(displayedLabel));
        cell.setCellStyle(createHeaderCellStyle(workbook));

        updateMaxWidthPerColumn(displayedLabel, 1.2, cellIndex, maxWidthPerColumn); // +20% pour les majuscules
        cellIndex++;/* ww w  .  j  ava2 s  .c  o  m*/
    }
    //La premiere ligne est rptable
    sheet.setRepeatingRows(new CellRangeAddress(0, 0, -1, -1));

    int rowIndex = 1;
    for (final DtObject dto : parameters.getDtList()) {
        final HSSFRow row = sheet.createRow(rowIndex);
        cellIndex = 0;
        Object value;
        for (final ExportField exportColumn : parameters.getExportFields()) {
            final HSSFCell cell = row.createCell(cellIndex);

            value = ExportUtil.getValue(storeManager, referenceCache, denormCache, dto, exportColumn);
            putValueInCell(value, cell, rowIndex % 2 == 0 ? evenHssfStyleCache : oddHssfStyleCache, cellIndex,
                    maxWidthPerColumn, exportColumn.getDtField().getDomain());

            cellIndex++;
        }
        rowIndex++;
    }
}

From source file:org.eclipse.scada.ae.ui.views.export.excel.impl.ExportEventsImpl.java

License:Open Source License

private IStatus storeExcel(final File file, final List<Event> events, final List<Field> columns,
        final IProgressMonitor monitor) throws IOException {
    final HSSFWorkbook workbook = new HSSFWorkbook();

    final HSSFDataFormat dateFormat = workbook.createDataFormat();
    final HSSFCellStyle dateCellStyle = workbook.createCellStyle();
    dateCellStyle.setDataFormat(dateFormat.getFormat("YYYY-MM-DD hh:mm:ss.000"));

    try {/*from w w  w  . j a  v  a  2 s  .c o  m*/
        monitor.beginTask(Messages.ExportImpl_Progress_ExportingEvents, events.size() + 3 + columns.size());

        try {
            monitor.subTask(Messages.ExportImpl_Progress_CreateWorkbook);
            monitor.worked(1);

            final HSSFSheet sheet = createSheet(events, workbook, columns);
            monitor.worked(1);

            monitor.setTaskName(Messages.ExportImpl_Progress_ExportEvents);

            for (int i = 0; i < events.size(); i++) {
                final HSSFRow row = sheet.createRow(i + 1);

                final Event e = events.get(i);
                for (int j = 0; j < columns.size(); j++) {
                    final Field field = columns.get(j);
                    final ExcelCell cell = new ExcelCell(row, j, dateCellStyle);
                    field.render(e, cell);
                }
                monitor.worked(1);
                if (monitor.isCanceled()) {
                    return Status.CANCEL_STATUS;
                }
            }

            sheet.setRepeatingRows(new CellRangeAddress(0, 1, -1, -1));

            monitor.setTaskName("Auto sizing");
            for (int i = 0; i < columns.size(); i++) {
                monitor.subTask(String.format("Auto sizing column: %s", columns.get(i).getHeader()));
                sheet.autoSizeColumn(i);
                monitor.worked(1);

                if (monitor.isCanceled()) {
                    return Status.CANCEL_STATUS;
                }
            }

        } finally {
            monitor.subTask(Messages.ExportImpl_Progress_CloseFile);
            if (workbook != null) {
                makeDocInfo(workbook);

                final FileOutputStream stream = new FileOutputStream(file);
                workbook.write(stream);
                stream.close();
            }
            monitor.worked(1);
        }
    } finally {
        monitor.done();
    }

    return Status.OK_STATUS;
}