Skip to content

Commit

Permalink
New excel emitter option "ExcelEmitter.StreamingXlsx" to configure the
Browse files Browse the repository at this point in the history
memory usage of the SpudSoft Xlsx Emitter eclipse-birt#1322
  • Loading branch information
speckyspooky committed Jun 9, 2023
1 parent 2c466e4 commit 1184bb3
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
* Copyright (c) 2011, 2012, 2013 James Talbut.
* jim-emitters@spudsoft.co.uk
*
*
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0/.
*
*
* SPDX-License-Identifier: EPL-2.0
*
*
* Contributors:
* James Talbut - Initial implementation.
************************************************************************************/
Expand Down Expand Up @@ -52,40 +52,101 @@
import uk.co.spudsoft.birt.emitters.excel.framework.Logger;
import uk.co.spudsoft.birt.emitters.excel.handlers.PageHandler;

/**
* Create the excel emitter for output
*
* @since 3.3
*
*/
public abstract class ExcelEmitter implements IContentEmitter {

/** property: ExcelEmitter.DEBUG */
public static final String DEBUG = "ExcelEmitter.DEBUG";

/** property: ExcelEmitter.RemoveBlankRows */
public static final String REMOVE_BLANK_ROWS = "ExcelEmitter.RemoveBlankRows";

/** property: ExcelEmitter.Rotation */
public static final String ROTATION_PROP = "ExcelEmitter.Rotation";

/** property: ExcelEmitter.ForceAutoColWidths */
public static final String FORCEAUTOCOLWIDTHS_PROP = "ExcelEmitter.ForceAutoColWidths";

/** property: ExcelEmitter.SingleSheet */
public static final String SINGLE_SHEET = "ExcelEmitter.SingleSheet";

/** property: ExcelEmitter.SingleSheetWithPageBreaks */
public static final String SINGLE_SHEET_PAGE_BREAKS = "ExcelEmitter.SingleSheetWithPageBreaks";

/** property: ExcelEmitter.InsertPrintBreakAfter */
public static final String PRINT_BREAK_AFTER = "ExcelEmitter.InsertPrintBreakAfter";

/** property: ExcelEmitter.DisableGrouping */
public static final String DISABLE_GROUPING = "ExcelEmitter.DisableGrouping";

/** property: ExcelEmitter.StructuredHeader */
public static final String STRUCTURED_HEADER = "ExcelEmitter.StructuredHeader";

/** property: ExcelEmitter.CustomNumberFormat */
public static final String CUSTOM_NUMBER_FORMAT = "ExcelEmitter.CustomNumberFormat";

/** property: ExcelEmitter.AutoFilter */
public static final String AUTO_FILTER = "ExcelEmitter.AutoFilter";

/** property: ExcelEmitter.SheetProtectPassword */
public static final String SHEET_PASSWORD = "ExcelEmitter.SheetProtectPassword";

/** property: ExcelEmitter.GroupSummaryHeader */
public static final String GROUP_SUMMARY_HEADER = "ExcelEmitter.GroupSummaryHeader";

/** property: ExcelEmitter.FreezePanes */
public static final String FREEZE_PANES = "ExcelEmitter.FreezePanes";

/** property: ExcelEmitter.BlankRowAfterTopLevelTable */
public static final String BLANK_ROW_AFTER_TOP_LEVEL_TABLE = "ExcelEmitter.BlankRowAfterTopLevelTable";

/** property: ExcelEmitter.SpannedRowHeight */
public static final String SPANNED_ROW_HEIGHT = "ExcelEmitter.SpannedRowHeight";

/** property: ExcelEmitter.NestedTableInLastCell */
public static final String NEST_TABLE_IN_LAST_CELL = "ExcelEmitter.NestedTableInLastCell";

/** property: spanned row height spread */
public static final int SPANNED_ROW_HEIGHT_SPREAD = 0;

/** property: spanned row height first */
public static final int SPANNED_ROW_HEIGHT_FIRST = 1;

/** property: spanned row height ignored */
public static final int SPANNED_ROW_HEIGHT_IGNORED = 2;

/** property: ExcelEmitter.PrintScale */
public static final String PRINT_SCALE = "ExcelEmitter.PrintScale";

/** property: ExcelEmitter.PrintPagesWide */
public static final String PRINT_PAGES_WIDE = "ExcelEmitter.PrintPagesWide";

/** property: ExcelEmitter.PrintPagesHigh */
public static final String PRINT_PAGES_HIGH = "ExcelEmitter.PrintPagesHigh";

/** property: ExcelEmitter.DisplayFormulas */
public static final String DISPLAYFORMULAS_PROP = "ExcelEmitter.DisplayFormulas";

/** property: ExcelEmitter.DisplayGridlines */
public static final String DISPLAYGRIDLINES_PROP = "ExcelEmitter.DisplayGridlines";

/** property: ExcelEmitter.DisplayRowColHeadings */
public static final String DISPLAYROWCOLHEADINGS_PROP = "ExcelEmitter.DisplayRowColHeadings";

/** property: ExcelEmitter.DisplayZeros */
public static final String DISPLAYZEROS_PROP = "ExcelEmitter.DisplayZeros";

/** property: ExcelEmitter.TemplateFile */
public static final String TEMPLATE_FILE = "ExcelEmitter.TemplateFile";

/** property: ExcelEmitter.StreamingXlsx */
public static final String STREAMING_XLSX = "ExcelEmitter.StreamingXlsx";

/**
* Logger.
*/
Expand Down Expand Up @@ -160,6 +221,15 @@ protected ExcelEmitter(StyleManagerUtils.Factory utilsFactory) {
*/
protected abstract Workbook createWorkbook();

/**
* Constructs a new workbook to be processed by the emitter.
*
* @return The new (streaming) workbook.
*
* @since 4.14
*/
protected abstract Workbook createSWorkbook();

/**
* Constructs a new workbook to be processed by the emitter.
*
Expand Down Expand Up @@ -206,7 +276,11 @@ public void start(IReportContent report) throws BirtException {
"Unable to open template workbook for " + templateFile.toString(), ex);
}
} else {
wb = createWorkbook();
if (EmitterServices.booleanOption(renderOptions, report, ExcelEmitter.STREAMING_XLSX, false)) {
wb = createSWorkbook();
} else {
wb = createWorkbook();
}
}

CSSEngine cssEngine = report.getRoot().getCSSEngine();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
* Copyright (c) 2011, 2012, 2013 James Talbut.
* jim-emitters@spudsoft.co.uk
*
*
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0/.
*
*
* SPDX-License-Identifier: EPL-2.0
*
*
* Contributors:
* James Talbut - Initial implementation.
************************************************************************************/
Expand Down Expand Up @@ -49,6 +49,11 @@ protected Workbook createWorkbook() {
return new HSSFWorkbook();
}

@Override
protected Workbook createSWorkbook() {
return new HSSFWorkbook();
}

@Override
protected Workbook openWorkbook(File templateFile) throws IOException {
InputStream stream = new FileInputStream(templateFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
* Copyright (c) 2011, 2012, 2013 James Talbut.
* jim-emitters@spudsoft.co.uk
*
*
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0/.
*
*
* SPDX-License-Identifier: EPL-2.0
*
*
* Contributors:
* James Talbut - Initial implementation.
************************************************************************************/
Expand All @@ -21,6 +21,7 @@
import java.io.InputStream;

import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

/**
Expand Down Expand Up @@ -49,6 +50,21 @@ protected Workbook createWorkbook() {
return new XSSFWorkbook();
}

/**
* Create a workbook of xlsx with streaming support
*
* @return xlsx workbook for streaming
*
* @since 4.14
*/
public Workbook createSWorkbook() {
SXSSFWorkbook swb = new SXSSFWorkbook();
// temp files will be gzipped
swb.setCompressTempFiles(true);

return swb;
}

@Override
protected Workbook openWorkbook(File templateFile) throws IOException {
InputStream stream = new FileInputStream(templateFile);
Expand Down

0 comments on commit 1184bb3

Please sign in to comment.