Skip to content

Commit

Permalink
Add support for ExcelEmitter.AutoColWidthsIncludeTableHeader and Foot…
Browse files Browse the repository at this point in the history
…er (#2021)

Add support for ExcelEmitter.AutoColWidthsIncludeTableHeader (and Footer) properties.

These new properties control whether to include the table header and footer rows when automatic column widths are computed.
  • Loading branch information
hvbtup authored Jan 7, 2025
1 parent cfd15f7 commit 36c355d
Show file tree
Hide file tree
Showing 10 changed files with 669 additions and 4 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,12 @@ private static Object getReportDesignConfiguration(IReportContent reportContent,
} else if (name.equalsIgnoreCase(ExcelEmitter.FORCEAUTOCOLWIDTHS_PROP)) {
value = reportContent.getDesign().getReportDesign().getExcelForceAutoColWidths();

} else if (name.equalsIgnoreCase(ExcelEmitter.AUTO_COL_WIDTHS_INCLUDE_TABLE_HEADER)) {
value = reportContent.getDesign().getReportDesign().getExcelAutoColWidthsIncludeTableHeader();

} else if (name.equalsIgnoreCase(ExcelEmitter.AUTO_COL_WIDTHS_INCLUDE_TABLE_FOOTER)) {
value = reportContent.getDesign().getReportDesign().getExcelAutoColWidthsIncludeTableFooter();

} else if (name.equalsIgnoreCase(ExcelEmitter.IMAGE_SCALING_CELL_DIMENSION)) {
value = reportContent.getDesign().getReportDesign().getExcelImageScaling();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ public abstract class ExcelEmitter implements IContentEmitter {
/** property: ExcelEmitter.ForceAutoColWidths */
public static final String FORCEAUTOCOLWIDTHS_PROP = "ExcelEmitter.ForceAutoColWidths";

/** property: ExcelEmitter.ForceAutoColWidthsIncludeTableHeader */
public static final String AUTO_COL_WIDTHS_INCLUDE_TABLE_HEADER = "ExcelEmitter.AutoColWidthsIncludeTableHeader";

/** property: ExcelEmitter.ForceAutoColWidthsIncludeTableFooter */
public static final String AUTO_COL_WIDTHS_INCLUDE_TABLE_FOOTER = "ExcelEmitter.AutoColWidthsIncludeTableFooter";

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,29 @@ The following list get an overview of all supported user properties, the content
false, disabled debug log
Default false

**ExcelEmitter.AutoColWidthsIncludeTableFooter**

Content define if the table footer row (only one footer row is supported) is included in the column width calculation.
Location report
Data type boolean
Values true, the table footer row is included in the column width calculation
false, the table footer row is ignored in the column width calculation
Default false
Since 4.19
Designer 4.19

**ExcelEmitter.AutoColWidthsIncludeTableHeader**

Content define if the table header rows are included in the column width calculation.
Location report
Data type boolean
Values true, the table header rows are included in the column width calculation
false, the table header rows are ignored in the column width calculation
Default false
Since 4.19
Designer 4.19


**ExcelEmitter.AutoFilter**

Content activate the auto-filter of excel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,19 @@ public void endTable(HandlerState state, ITableContent table) throws BirtExcepti

log.debug("Details rows from ", startDetailsRow, " to ", endDetailsRow);

if ((startDetailsRow > 0) && (endDetailsRow > startDetailsRow)) {
int autoWidthStartRow = startDetailsRow;
if (EmitterServices.booleanOption(state.getRenderOptions(), table,
ExcelEmitter.AUTO_COL_WIDTHS_INCLUDE_TABLE_HEADER,
false)) {
autoWidthStartRow = startRow;
}
int autoWidthEndRow = endDetailsRow;
if (EmitterServices.booleanOption(state.getRenderOptions(), table,
ExcelEmitter.AUTO_COL_WIDTHS_INCLUDE_TABLE_FOOTER,
false)) {
autoWidthEndRow = state.rowNum - 1;
}
if ((autoWidthStartRow >= 0) && (autoWidthEndRow > autoWidthStartRow)) {
boolean defaultAutoColWidth = EmitterServices.booleanOption(state.getRenderOptions(), table,
ExcelEmitter.STREAMING_XLSX, false);
// force automated column width calculation if streaming mode of XLSX is enabled
Expand All @@ -173,15 +185,15 @@ public void endTable(HandlerState state, ITableContent table) throws BirtExcepti
for (int col = 0; col < table.getColumnCount(); ++col) {
int oldWidth = state.currentSheet.getColumnWidth(col);
if (forceAutoColWidths || (oldWidth == 256 * state.currentSheet.getDefaultColumnWidth())) {
FilteredSheet filteredSheet = new FilteredSheet(state.currentSheet, startDetailsRow,
Math.min(endDetailsRow, startDetailsRow + 12));
FilteredSheet filteredSheet = new FilteredSheet(state.currentSheet, autoWidthStartRow,
Math.min(autoWidthEndRow, autoWidthStartRow + 12));
double calcWidth = SheetUtil.getColumnWidth(filteredSheet, col, false);

if (state.currentSheet instanceof XSSFSheet) {
state.currentSheet.autoSizeColumn(col, true);
}
if (calcWidth > 1.0) {
calcWidth = state.currentSheet.getColumnWidth(col) * 1.15; // offset to handle width differences of apache poi
calcWidth *= 1.15 * 256; // The factor 1.15 is used to handle width differences of Apache POI.
int maxColumnWidth = 255 * 256; // The maximum column width for an individual cell is 255
// characters
if (calcWidth > maxColumnWidth) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1434,6 +1434,48 @@ public void setExcelForceAutoColWidths(boolean forceAutoColWidths) throws Semant
setBooleanProperty(EXCEL_FORCE_AUTO_COL_WIDTHS, forceAutoColWidths);
}

/**
* Get the auto column width include header flag for the excel output
*
* @return include the header rows in auto columns widths calculation or not
*/
public boolean getExcelAutoColWidthsIncludeTableHeader() {
return getBooleanProperty(EXCEL_AUTO_COL_WIDTHS_INCLUDE_TABLE_HEADER);
}

/**
* Set the auto column width include header flag for the excel output
*
* @param autoColWidthsIncludeTableHeader include header rows in auto columns widths
* calculation
* @throws SemanticException
*/
public void setExcelAutoColWidthsIncludeTableHeader(boolean autoColWidthsIncludeTableHeader)
throws SemanticException {
setBooleanProperty(EXCEL_AUTO_COL_WIDTHS_INCLUDE_TABLE_HEADER, autoColWidthsIncludeTableHeader);
}

/**
* Get the auto column width include footer flag for the excel output
*
* @return include the footer row in auto columns widths calculation or not
*/
public boolean getExcelAutoColWidthsIncludeTableFooter() {
return getBooleanProperty(EXCEL_AUTO_COL_WIDTHS_INCLUDE_TABLE_FOOTER);
}

/**
* Set the auto column width include footer flag for the excel output
*
* @param autoColWidthsIncludeTableFooter include footer row in auto columns
* widths calculation
* @throws SemanticException
*/
public void setExcelAutoColWidthsIncludeTableFooter(boolean autoColWidthsIncludeTableFooter)
throws SemanticException {
setBooleanProperty(EXCEL_AUTO_COL_WIDTHS_INCLUDE_TABLE_FOOTER, autoColWidthsIncludeTableFooter);
}

/**
* Get the configuration for the excel handling of single sheet result
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,16 @@ public interface IInternalReportDesignModel {
*/
String EXCEL_FORCE_AUTO_COL_WIDTHS = "excelForceAutoColWidths"; //$NON-NLS-1$

/**
* Excel option, include header rows in auto column width calculation
*/
String EXCEL_AUTO_COL_WIDTHS_INCLUDE_TABLE_HEADER = "excelAutoColWidthsIncludeTableHeader"; //$NON-NLS-1$

/**
* Excel option, include footer row in auto column width calculation
*/
String EXCEL_AUTO_COL_WIDTHS_INCLUDE_TABLE_FOOTER = "excelAutoColWidthsIncludeTableFooter"; //$NON-NLS-1$

/**
* Excel option, create only singe sheet
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1943,6 +1943,14 @@
<!-- excel (Spudsoft): force the column width calculation -->
<Property canInherit="false" displayNameID="Element.ReportDesign.Emitter.excel.forceAutoColWidths" name="excelForceAutoColWidths" runtimeSettable="false" since="4.17" type="boolean" >
<Default>false</Default>
</Property>
<!-- excel (Spudsoft): include header in the column width calculation -->
<Property canInherit="false" displayNameID="Element.ReportDesign.Emitter.excel.autoColWidthsIncludeHeader" name="excelAutoColWidthsIncludeTableHeader" runtimeSettable="false" since="4.19" type="boolean" >
<Default>false</Default>
</Property>
<!-- excel (Spudsoft): include footer in the column width calculation -->
<Property canInherit="false" displayNameID="Element.ReportDesign.Emitter.excel.autoColWidthsIncludeFooter" name="excelAutoColWidthsIncludeTableFooter" runtimeSettable="false" since="4.19" type="boolean" >
<Default>false</Default>
</Property>
<!-- excel (Spudsoft): output of table as single sheet -->
<Property canInherit="false" displayNameID="Element.ReportDesign.Emitter.excel.singleSheet" name="excelSingleSheet" runtimeSettable="false" since="4.17" type="boolean" >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2653,6 +2653,8 @@ Element.ReportDesign.language=Language
Element.ReportDesign.PDFAccessible=Accessible PDF
Element.ReportDesign.Emitter.excel=Emitter Excel configuration
Element.ReportDesign.Emitter.excel.forceAutoColWidths=Force auto column width calculation
Element.ReportDesign.Emitter.excel.autoColWidthsIncludeHeader=Include header rows in auto column width calculation
Element.ReportDesign.Emitter.excel.autoColWidthsIncludeFooter=Include footer rows in auto column width calculation
Element.ReportDesign.Emitter.excel.singleSheet=Single sheet
Element.ReportDesign.Emitter.excel.disableGrouping=Disable grouping
Element.ReportDesign.Emitter.excel.displayGridlines=Display grid lines
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ protected void writeSimpleProperties(ReportDesign obj) {

property(obj, IInternalReportDesignModel.EXCEL_DISABLE_GROUPING);
property(obj, IInternalReportDesignModel.EXCEL_FORCE_AUTO_COL_WIDTHS);
property(obj, IInternalReportDesignModel.EXCEL_AUTO_COL_WIDTHS_INCLUDE_TABLE_HEADER);
property(obj, IInternalReportDesignModel.EXCEL_AUTO_COL_WIDTHS_INCLUDE_TABLE_FOOTER);
property(obj, IInternalReportDesignModel.EXCEL_SINGLE_SHEET);
property(obj, IInternalReportDesignModel.EXCEL_DISPLAY_GRIDLINES);
property(obj, IInternalReportDesignModel.EXCEL_AUTO_FILTER);
Expand Down

0 comments on commit 36c355d

Please sign in to comment.