Skip to content

Commit

Permalink
Enhancement to add excel formula options (#1643) (#1644)
Browse files Browse the repository at this point in the history
* Enhancement to add excel formula options (#1643)
* documentation of the ExcelEmitter user properties at README.md
  • Loading branch information
speckyspooky authored Apr 26, 2024
1 parent 4852072 commit 8e2041b
Show file tree
Hide file tree
Showing 4 changed files with 435 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ public abstract class ExcelEmitter implements IContentEmitter {
/** property: ExcelEmitter.DisplayZeros */
public static final String DISPLAYZEROS_PROP = "ExcelEmitter.DisplayZeros";

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

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
# Eclipse BIRT
Introduction to use the specialist user properties of the ExcelEmitter.

## Reason
The ExelEmitter provides a set of specialist user properties to optimize the excel output according of the reporting based requirements.

Each of the user properties starts with the master prefix "ExcelEmitter".


### User properties of the ExcelEmitter

The following list get an overview of all supported user properties, the content and the definition of use.

**ExcelEmitter.DEBUG**

Content activate the debug log during the excel file creation
Location report
Data type boolean
Values true, enable debug log
false, disabled debug log
Default false


**ExcelEmitter.RemoveBlankRows**

Content handling of blank rows
Location report, table, grid, list, row
Data type boolean
Values true, blank rows will be removed
false, keep blank rows
Default false

**ExcelEmitter.Rotation**

Content rotation of the element
Location text-element of cell
Data type number, float
Values degree value for the rotation of the content
Default empty (null)

**ExcelEmitter.ForceAutoColWidths**

Content define if the column width will be calculated through content-length or based on the column width
Location report
Data type boolean
Values true, column width will be calculated through content-lengt (ignore the column width definition)
false, the configured report column width will be used
Default false

**ExcelEmitter.SingleSheet**

Content the created excel will included all data into one excel sheet
Location report
Data type boolean
Values true, all data will be displayed at one sheet (page breaks for new sheets will be ignored)
false, use page breaks to create different sheets
Default false

**ExcelEmitter.SingleSheetWithPageBreaks**

Content the created excel will included all data into one excel sheet
Location report
Data type boolean
Values true, all data will be displayed at one sheet (page breaks for new sheets will be ignored)
false, use page breaks to create different sheets
Default false

**ExcelEmitter.InsertPrintBreakAfter**

Content insert a page break after the marked row
Location row
Data type boolean
Values true, add page break after the marked row (= create new sheet)
false, no additional page break, default behavior will be used
Default false

**ExcelEmitter.DisableGrouping**

Content option to disable the excel grouping
Location report
Data type boolean
Values true, hide the grouping section of excel
false, show the grouping section of excel
Default false

**ExcelEmitter.StructuredHeader**

Content option to display the header and footer details on excel sheet level
Location report
Data type boolean
Values true, the master page header will be display at first line and footer as last line of each sheet
false, the master page header and footer will be displayed like excel header and footer
Default false

**ExcelEmitter.CustomNumberFormat**

Content define the number format of a numeric value for excel
Location text-element of cell
Data type string
Values custom format which should be used to display the value on excel, e.g. "#,#00.00"
the format use the form of the excel-defined forms (language version: en)
Default empty (null)

**ExcelEmitter.AutoFilter**

Content activate the auto-filter of excel
Location report
Data type boolean
Values true, add the excel-filter on the first table header section on the last header row
false, hide excel-filter
Default false

**ExcelEmitter.SheetProtectPassword**

Content set a password to an excel sheet
Location table, list
Data type string
Values password to protect the excel file
Default empty (null)

**ExcelEmitter.GroupSummaryHeader**

Content flag indicating whether summary rows appear below detail in an outline, when applying an outline
Location report, table
Data type boolean
Values true, a summary row is inserted below the detailed data being summarized and a new outline level is established on that row
false, a summary row is inserted above the detailed data being summarized and a new outline levelis established on that row.
Default false

**ExcelEmitter.FreezePanes**

Content freeze excel rows
Location row
Data type boolean
Values true, based on the marked row the row will be frozen on excel
false, no frozen panes
Default false

**ExcelEmitter.BlankRowAfterTopLevelTable**

Content option to add a blank row after the top level table
Location table
Data type boolean
Values true, add a blank row after a top level table
false, no additional blank row
Default false

**ExcelEmitter.SpannedRowHeight**

Content define the row height of spanned cells
Location cell
Data type number, float
Values row height of spanned cells
Default 0

**ExcelEmitter.NestedTableInLastCell**

Content activate the special handling of nested tables of the last row-cell
Location table
Data type boolean
Values true, activate the nested table handling of the last cell of a row
false, no nested table at last cell of row
Default false

**ExcelEmitter.PrintScale**

Content define the scaling for the print output of the excel file
Location report
Data type number, short
Values the scale value must be -1 (= off) or between 10 and 400
Default -1

**ExcelEmitter.PrintPagesWide**

Content configuration of the page width for the excel print out
Location report
Data type number, short
Values page width for the excel print out
Default -1

**ExcelEmitter.PrintPagesHigh**

Content configuration of the page height for the excel print out
Location report
Data type number, short
Values page height for the excel print out
Default -1

**ExcelEmitter.DisplayFormulas**

Content display the formulas as text without calculation
Location report, table, grid
Data type boolean
Values true, show formula as text
false, evaluate the content like formula
Default false

**ExcelEmitter.DisplayGridlines**

Content option to hide the excel grid
Location report
Data type boolean
Values true, show grid lines on excel
false, hide grid lines on excel
Default true

**ExcelEmitter.DisplayRowColHeadings**

Content option to hide the row and column header labels
Location table
Data type boolean
Values true, the column head and row line labels are shown on the excel sheet
false, the column head and row line labels are hidden on the excel sheet
Default true

**ExcelEmitter.DisplayZeros**

Content option to display or hide zeros
Location table
Data type boolean
Values true, show cell value of zero
false, hide cell value of zero
Default true

**ExcelEmitter.ValueAsFormula**

Content the content on an element will be added as excel-formula, for calculation teh string must be start with "="-sign
Location text-element of cell
Data type boolean
Values true, use content like formula
false, use content like text
Default false

**ExcelEmitter.Formula**

Content the content of this property will be added as excel-formula, for calculation teh string must be start with "="-sign
Location text-element of cell
Data type string
Values fixed text or formula for excel cell
Default empty (null)

**ExcelEmitter.TemplateFile**

Content define an excel-template to create the excel
Location report
Data type string
Values full file path (path & filename) to an excel template which should be used for the excel creation
Default empty (null)

**ExcelEmitter.StreamingXlsx**

Content define the technical output method DOM- or streaming-handling
Location report
Data type boolean
Values true, activate the streaming output method
false, standard output handling based on DOM will be used
Default false
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.awt.font.LineBreakMeasurer;
import java.awt.font.TextAttribute;
import java.awt.font.TextLayout;
import java.awt.font.TextMeasurer;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -786,11 +787,14 @@ protected int getRichTextRunIndexForStart(List<RichTextRun> richTextRuns, int st
* @param defaultFont The font to be used prior to the first RichTextRun.
* @param widthMM The width of the output.
* @param richTextRuns The list of RichTextRuns to be applied to the string
* @return The heigh, in points, of a box big enough to contain the formatted
* @param wrap If the excel cell marked as wrapped text then use the
* wrapped line break LineBreakMeasurer else use raw
* TextMeasurer
* @return The height, in points, of a box big enough to contain the formatted
* sourceText.
*/
public float calculateTextHeightPoints(String sourceText, Font defaultFont, double widthMM,
List<RichTextRun> richTextRuns) {
List<RichTextRun> richTextRuns, boolean wrap) {
log.debug("Calculating height for ", sourceText);

final float widthPt = (float) (72 * Math.max(0, widthMM - 6) / 25.4);
Expand Down Expand Up @@ -843,21 +847,37 @@ public float calculateTextHeightPoints(String sourceText, Font defaultFont, doub
}
}

LineBreakMeasurer measurer = new LineBreakMeasurer(attrString.getIterator(), frc);

float heightAdjustment = 0.0F;
int lineLength = textLine.isEmpty() ? 1 : textLine.length();
while (measurer.getPosition() < lineLength) {
TextLayout layout = measurer.nextLayout(widthPt);
float lineHeight = layout.getAscent() + layout.getDescent() + layout.getLeading();
if (layout.getDescent() + layout.getLeading() > heightAdjustment) {
heightAdjustment = layout.getDescent() + layout.getLeading();
try {
if (wrap) {
LineBreakMeasurer measurer = new LineBreakMeasurer(attrString.getIterator(), frc);

float heightAdjustment = 0.0F;
int lineLength = textLine.isEmpty() ? 1 : textLine.length();
while (measurer.getPosition() < lineLength) {
TextLayout layout = measurer.nextLayout(widthPt);
float lineHeight = layout.getAscent() + layout.getDescent() + layout.getLeading();
if (layout.getDescent() + layout.getLeading() > heightAdjustment) {
heightAdjustment = layout.getDescent() + layout.getLeading();
}
log.debug("Line: ", textLine, " gives height ", lineHeight, "(", layout.getAscent(), "/",
layout.getDescent(), "/", layout.getLeading(), ")");
totalHeight += lineHeight;
}
totalHeight += heightAdjustment;
} else {
if (textLine.length() > 0) {
TextMeasurer measurer = new TextMeasurer(attrString.getIterator(), frc);
TextLayout layout = measurer.getLayout(0, textLine.length());
float lineHeight = layout.getAscent() + 2 * (layout.getDescent() + layout.getLeading());
log.debug("Line: ", textLine, " gives height ", lineHeight, "(", layout.getAscent(), "/",
layout.getDescent(), "/", layout.getLeading(), ")");
totalHeight += lineHeight;
}
}
log.debug("Line: ", textLine, " gives height ", lineHeight, "(", layout.getAscent(), "/",
layout.getDescent(), "/", layout.getLeading(), ")");
totalHeight += lineHeight;
} catch (Throwable ex) {
log.error(0, "Calculating height of line \"" + textLine + "\" threw: ", ex);
}
totalHeight += heightAdjustment;

}
log.debug("Height calculated as ", totalHeight);
Expand Down
Loading

0 comments on commit 8e2041b

Please sign in to comment.