Class ExcelAbstractExporter<RC extends XlsReportConfiguration,C extends XlsExporterConfiguration,E extends JRExporterContext>
java.lang.Object
net.sf.jasperreports.engine.JRAbstractExporter<RC,C,OutputStreamExporterOutput,E>
net.sf.jasperreports.engine.export.ExcelAbstractExporter<RC,C,E>
- All Implemented Interfaces:
Exporter<ExporterInput,RC, C, OutputStreamExporterOutput>
- Direct Known Subclasses:
JRXlsAbstractExporter,XlsxMetadataExporter
public abstract class ExcelAbstractExporter<RC extends XlsReportConfiguration,C extends XlsExporterConfiguration,E extends JRExporterContext>
extends JRAbstractExporter<RC,C,OutputStreamExporterOutput,E>
- Author:
- Sanda Zaharia (shertage@users.sourceforge.net)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassprotected static classNested classes/interfaces inherited from class net.sf.jasperreports.engine.JRAbstractExporter
JRAbstractExporter.BaseExporterContext, JRAbstractExporter.PageRange -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Stringprotected Stringprotected booleanstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringprotected booleanprotected booleanprotected JRFontprotected booleanprotected booleanprotected ImageAnchorTypeEnumprotected booleanprotected booleanprotected booleanprotected booleanstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringprotected booleanprotected booleanprotected booleanprotected Stringprotected Booleanprotected intprotected ExporterNatureprotected booleanprotected PrintPageFormatprotected intstatic final StringThis element-level property is used to indicate the boundaries of the autofilter data range in the current sheet.static final StringFlag property that indicates whether Excel should autofit the current column width.static final StringFlag property that indicates whether Excel should autofit the current row height.static final StringProperty specifying the multiplication factor to be used when calculating the column width for auto fit columns on top of the fill-time calculated average char width.static final StringElement level property specifying if a sheet will break after the row displaying that element.static final StringElement level property specifying if a sheet will break before the row displaying that element.static final StringProperty that stores the formula which has to be applied to a given cell in an excel sheet.static final StringProperty that stores the pattern which has to be applied to a given cell in an excel sheet.static final StringA string that represents the name for the column that should appear in the XLS export.static final StringElement-level property used to adjust the column width to values suitable for Excel output, taking into account that column widths are measured in Excel in Normal style default character width units.static final StringElement-level property used to adjust the column width to values suitable for Excel metadata output, taking into account that when column headers are included in the report, they come with no available width settings.static final StringProperty that specifies what value to associate withPROPERTY_COLUMN_NAME.static final StringThis property indicates the vertical edge of the freeze pane, relative to the current cell.static final StringThis property indicates the horizontal edge of the freeze pane, relative to the current cell.static final StringFlag property that indicates whether the height of the element should contribute to the current row height calculation.static final StringProperty that specifies whether the value associated withPROPERTY_COLUMN_NAMEshould be repeated or not when it is missing.static final StringProperty prefix used to indicate the current outline row level, and when necessary, the ending row of the current outline row group with the given level.static final StringProperty used to set the name of the sheet containing a given element.protected RenderersCacheprotected intprotected intUsed for counting the total number of sheets.protected JRXlsAbstractExporter.SheetInfoprotected String[]protected intUsed for iterating through sheet names.Used when indexing the identical sheet name.protected intprotected Stringstatic final StringFields inherited from class net.sf.jasperreports.engine.JRAbstractExporter
allSelector, crtCompositeConfiguration, crtCompositeItemConfiguration, crtItem, dateFormatCache, EXCEPTION_MESSAGE_KEY_EMPTY_INPUT_SOURCE_IN_BATCH_MODE, EXCEPTION_MESSAGE_KEY_END_PAGE_INDEX_OUT_OF_RANGE, EXCEPTION_MESSAGE_KEY_INVALID_IMAGE_NAME, EXCEPTION_MESSAGE_KEY_INVALID_ZOOM_RATIO, EXCEPTION_MESSAGE_KEY_NO_INPUT_SOURCE, EXCEPTION_MESSAGE_KEY_NO_OUTPUT_SPECIFIED, EXCEPTION_MESSAGE_KEY_OUTPUT_WRITER_ERROR, EXCEPTION_MESSAGE_KEY_PAGE_INDEX_OUT_OF_RANGE, EXCEPTION_MESSAGE_KEY_START_PAGE_INDEX_OUT_OF_RANGE, exporterConfiguration, exporterContext, exporterInput, exporterOutput, filter, fontUtil, hyperlinkProducerFactory, itemConfiguration, jasperPrint, jasperReportsContext, noBackcolorSelector, noneSelector, numberFormatCache, propertiesUtil, PROPERTY_DEFAULT_FILTER_FACTORY, PROPERTY_SUFFIX_DEFAULT_FILTER_FACTORY, rendererUtil, styledTextUtil, textValueClasses -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidaddRowBreak(int rowIndex) protected final intcalculateHeightForDinAN(int n) protected final intcalculateHeightForDinBN(int n) protected final intcalculateHeightForDinCN(int n) protected final intcalculateWidthForDinAN(int n) protected final intcalculateWidthForDinBN(int n) protected final intcalculateWidthForDinCN(int n) protected abstract voidprotected abstract voidprotected voidconfigureDefinedNames(ExporterNature exporterNature, JRPrintElement element) protected voidconfigureDefinedNames(JRPropertiesUtil.PropertySuffix propertySuffix) protected voidprotected voidprotected abstract voidvoidPerforms the export.protected abstract voidstatic StringgetColumIndexName(int colIndex, int maxColIndex) protected intgetColumnIndex(String columnName) protected StringgetColumnName(int columnIndex) Deprecated.protected StringgetConvertedPattern(JRPrintText text, String pattern) protected JRFontprotected StringgetFormula(JRPrintText text) protected intprotected Integerprotected ExporterNatureprotected StringgetSheetName(String sheetName) protected StringgetSheetName(String sheetName, String defaultSheetName) protected JRStyledTextgetStyledText(JRPrintText textElement) getTextAlignHolder(JRPrintText textElement) protected booleanprotected voidprotected voidprotected booleanisCellHidden(JRPrintElement element) protected booleanisCellLocked(JRPrintElement element) protected booleanisIgnoreTextFormatting(JRPrintElement element) protected booleanisShrinkToFit(JRPrintElement element) protected booleanisUseTimeZone(JRPrintElement element) protected booleanisValidScale(Integer scale) protected booleanisWrapText(JRPrintElement element) protected voidmergeAndSetRowLevels(XlsRowLevelInfo levelInfo, SortedMap<String, Boolean> rowLevelMap, int rowIndex) protected abstract voidprotected voidprotected abstract voidsetAutoFilter(String autoFilterRange) protected abstract voidsetColumnWidth(int col, int width, boolean autoFit) protected abstract voidsetFreezePane(int rowIndex, int colIndex) protected abstract voidsetRowLevels(XlsRowLevelInfo levelInfo, String level) protected abstract voidsetSheetName(String sheetName) protected voidprotected StringtoExcelName(String name) protected DatetranslateDateValue(JRPrintText text, Date value) protected voidupdateHeaderFooter(JRXlsAbstractExporter.SheetInfo.SheetPrintSettings printSettings, XlsReportConfiguration configuration) protected voidupdatePrintSettings(JRXlsAbstractExporter.SheetInfo.SheetPrintSettings printSettings, XlsReportConfiguration configuration) Methods inherited from class net.sf.jasperreports.engine.JRAbstractExporter
checkInterrupted, createFilter, defaultParseNumber, ensureJasperReportsContext, ensureOutput, getBooleanCellValue, getConfigurationInterface, getCurrentConfiguration, getCurrentItemConfiguration, getCurrentJasperPrint, getDateCellValue, getDateFormat, getExporterConfiguration, getExporterContext, getExporterInput, getExporterKey, getExporterOutput, getExporterPropertiesPrefix, getHyperlinkProducer, getItemConfigurationInterface, getJasperReportsContext, getLocale, getNumberCellValue, getNumberFormat, getOffsetX, getOffsetY, getPageRange, getPropertiesUtil, getRendererUtil, getReportContext, getReportExportConfiguration, getRepository, getStyledText, getTextFormatFactoryClass, getTextLocale, getTextTimeZone, getTextValue, getTextValueString, insideFrame, reset, resetExportContext, restoreElementOffsets, setConfiguration, setConfiguration, setCurrentExporterInputItem, setExporterInput, setExporterOutput, setFrameElementsOffset, setJasperReportsContext, setOffset, setOffset, setReportContext
-
Field Details
-
XLS_EXPORTER_PROPERTIES_PREFIX
- See Also:
-
DEFAULT_SHEET_NAME_PREFIX
- See Also:
-
DEFAULT_DEFINED_NAME_SCOPE
- See Also:
-
DEFAULT_DEFINED_NAME_SCOPE_SEPARATOR
- See Also:
-
EXCEPTION_MESSAGE_KEY_CANNOT_ADD_CELL
- See Also:
-
EXCEPTION_MESSAGE_KEY_CANNOT_MERGE_CELLS
- See Also:
-
EXCEPTION_MESSAGE_KEY_CELL_FORMAT_TEMPLATE_ERROR
- See Also:
-
EXCEPTION_MESSAGE_KEY_COLUMN_INDEX_BEYOND_LIMIT
- See Also:
-
EXCEPTION_MESSAGE_KEY_LOADED_FONTS_ERROR
- See Also:
-
EXCEPTION_MESSAGE_KEY_NEGATIVE_COLUMN_INDEX
- See Also:
-
EXCEPTION_MESSAGE_KEY_REPORT_GENERATION_ERROR
- See Also:
-
EXCEPTION_MESSAGE_KEY_TEMPLATE_NOT_FOUND
- See Also:
-
PROPERTY_CELL_FORMULA
Property that stores the formula which has to be applied to a given cell in an excel sheet.- See Also:
-
PROPERTY_CELL_PATTERN
Property that stores the pattern which has to be applied to a given cell in an excel sheet.- See Also:
-
PROPERTY_SHEET_NAME
Property used to set the name of the sheet containing a given element. Its value overrides the report-level settings for the sheet name. If several elements in the sheet contain this property, the engine will consider the value of the last exported element's property.- See Also:
-
PROPERTY_FREEZE_ROW_EDGE
This property indicates the horizontal edge of the freeze pane, relative to the current cell. If set, it overrides the PROPERTY_FREEZE_ROW value. Allowed values are:Top- The current row is the first unlocked row in the sheet. All rows above are 'frozen'.Bottom- The current row is the last 'frozen' row in the sheet. All rows below are unlocked.
- See Also:
-
PROPERTY_FREEZE_COLUMN_EDGE
This property indicates the vertical edge of the freeze pane, relative to the current cell. If set, it overrides the PROPERTY_FREEZE_COLUMN and PROPERTY_FREEZE_SHEET_COLUMNS values. Allowed values are:Left- The current column is the first unlocked column in the sheet. All columns to the left are 'frozen'.Right- The current column is the last 'frozen' column in the sheet. All columns to the right are unlocked.
- See Also:
-
PROPERTY_AUTO_FIT_ROW
Flag property that indicates whether Excel should autofit the current row height. Allowed values are:truefalse- this is the default value.
- Since:
- 4.5.1
- See Also:
-
PROPERTY_IGNORE_ROW_HEIGHT
Flag property that indicates whether the height of the element should contribute to the current row height calculation. The current row height is given by the tallest element on the row, unless row height auto fit is activated. But in certain cases, the tallest element might span multiple rows and thus its bigger height should not be considered, especially in case of metadata based exports. Allowed values are:truefalse- this is the default value.
- Since:
- 6.20.1
- See Also:
-
PROPERTY_AUTO_FIT_COLUMN
Flag property that indicates whether Excel should autofit the current column width. Allowed values are:truefalse- this is the default value.
- Since:
- 4.5.1
- See Also:
-
PROPERTY_AUTO_FILTER
This element-level property is used to indicate the boundaries of the autofilter data range in the current sheet. Allowed values are:Start- The current cell will be marked as autofilter heading cell, and column data below/to the right of this cell can be considered as part of the autofilter data range. The starting point of the autofilter data range will be the next cell below the current cell (ie if the current cell reference is B4, the autofilter range will start with the "B5" cell reference: "B5:M20").
If multiple autofilterStartvalues are found in the same sheet, only the last one will be considered. If theStartvalue is present but noEndvalue is found in the sheet, then only the current column will be considered for the data range.
If the autofilterStartvalue is set on the same row as the autofilterEndvalue, the data range will include all data below this heading row, placed between the start column and the end column.End- The current cell will be marked as autofilter ending cell, and column data in this cell and above/to the left can be considered as part of the autofilter data range. The ending cell in the data range is the current cell reference (ie if the current cell reference is M20, the autofilter range will end in "M20": "B5:M20"). The heading cell for the current column will be placed in the same column on the row containing the autofilterStartvalue.
Caution: If no autofilterStartvalue is found in the sheet, the autofilterEndvalue will be considered asStartvalue instead.
If multiple autofilterEndvalue are found in the same sheet, only the last one will be considered.
If the autofilterStartvalue is set on the same row as the autofilterEndvalue, the data range will include all data below this heading row, placed between the start column and the end column.
- See Also:
-
PROPERTY_COLUMN_WIDTH
Element-level property used to adjust the column width to values suitable for Excel output, taking into account that column widths are measured in Excel in Normal style default character width units. The pixel-to-character width translation depends on the default normal style character width, so it cannot be always accurately fitted. In this case, one can adjust the current column width by setting this property with an integer value measured in pixels. The JR engine will perform the pixel-to-character width mapping using this value instead of the element'swidthattribute.
If defined, this property will override thePROPERTY_COLUMN_WIDTH_RATIOvalue for the current column- See Also:
-
PROPERTY_AVERAGE_CHAR_WIDTH_FACTOR
Property specifying the multiplication factor to be used when calculating the column width for auto fit columns on top of the fill-time calculated average char width.- See Also:
-
PROPERTY_ROW_OUTLINE_LEVEL_PREFIX
Property prefix used to indicate the current outline row level, and when necessary, the ending row of the current outline row group with the given level. The suffix of these properties is associated with the outline level, while the property value indicates if the current row group should continue or should end. The most recommended practice is to use the outline level itself as property suffix, although this is not mandatory. The suffix may take any other string value, but one has to keep in mind that suffixes are used as sorted row level descriptors. For instance, because "aaa" < "bbb", the outline level associated with the "aaa" suffix will be smaller than the level associated with the "bbb" suffix. The most intuitive representation of the row levels uses the row level as property suffix.
In such a case, thenet.sf.jasperreports.export.xls.outline.level.2property means that its value is correlated with the outline level 2, so the current row belongs to a level 2 row group. Based on Office Open XML specs, allowed values for outline levels are positive integers from 1 to 7.
The value of this property could be any expression (includingnull). When such a property occurrence is met, the suffix indicates the outline level for that row. If multiple properties with the same prefix are defined for the same row, the deepest outline level is considered for that row. To end an outline row group one has to set the related outline level property with theEndvalue. This is a special property value instructing the JR engine that the current row group of that level ends on the current row.- See Also:
-
PROPERTY_BREAK_BEFORE_ROW
Element level property specifying if a sheet will break before the row displaying that element. It is very useful especially when displaying each report's group on a separate sheet is intended.- See Also:
-
PROPERTY_BREAK_AFTER_ROW
Element level property specifying if a sheet will break after the row displaying that element. It is very useful especially when displaying each report's group on a separate sheet is intended.- See Also:
-
PROPERTY_COLUMN_NAME
A string that represents the name for the column that should appear in the XLS export. It must be one of the values inXlsMetadataReportConfiguration.getColumnNames(), if provided.- See Also:
-
PROPERTY_REPEAT_VALUE
Property that specifies whether the value associated withPROPERTY_COLUMN_NAMEshould be repeated or not when it is missing.The property itself defaults to
false.- See Also:
-
PROPERTY_DATA
Property that specifies what value to associate withPROPERTY_COLUMN_NAME.The property itself defaults to the text value of the report element that this property is assigned to.
- See Also:
-
PROPERTY_COLUMN_WIDTH_METADATA
Element-level property used to adjust the column width to values suitable for Excel metadata output, taking into account that when column headers are included in the report, they come with no available width settings. Also keep in mind that column widths are measured in Excel in Normal style default character width units. The pixel-to-character width translation depends on the default normal style character width, so it cannot be always accurately fitted. In this case, one can adjust the current column width by setting this property with an integer value measured in pixels. The JR engine will perform the pixel-to-character width mapping using this value instead of the element'swidthattribute.
If defined, this property will override both thePROPERTY_COLUMN_WIDTHvalue for the current column and the the element'swidthattribute- See Also:
-
CURRENT_ROW_HEIGHT
- See Also:
-
CURRENT_ROW_AUTOFIT
- See Also:
-
loadedFonts
-
nature
-
sheetNames
-
reportIndex
protected int reportIndex -
pageIndex
protected int pageIndex -
pageFormat
-
onePagePerSheetMap
-
sheetsBeforeCurrentReport
protected int sheetsBeforeCurrentReport -
sheetsBeforeCurrentReportMap
-
renderersCache
-
defaultFont
-
sheetInfo
-
sheetIndex
protected int sheetIndexUsed for counting the total number of sheets. -
sheetNamesIndex
protected int sheetNamesIndexUsed for iterating through sheet names. -
sheetNamesMap
Used when indexing the identical sheet name. Contains sheet names as keys and the number of occurrences of each sheet name as values. -
autoFilterStart
-
autoFilterEnd
-
firstPageNotSet
protected boolean firstPageNotSet -
keepTemplateSheets
-
workbookTemplate
-
invalidCharReplacement
-
maxColumnIndex
protected int maxColumnIndex -
definedNamesMap
protected Map<ExcelAbstractExporter<RC extends XlsReportConfiguration,C extends XlsExporterConfiguration, definedNamesMapE extends JRExporterContext>.NameScope, String> -
formatPatternsMap
-
onePagePerSheet
protected boolean onePagePerSheet -
defaultShrinkToFit
protected boolean defaultShrinkToFit -
defaultWrapText
protected boolean defaultWrapText -
defaultCellLocked
protected boolean defaultCellLocked -
defaultCellHidden
protected boolean defaultCellHidden -
defaultIgnoreTextFormatting
protected boolean defaultIgnoreTextFormatting -
ignoreAnchors
protected boolean ignoreAnchors -
defaultIgnoreHyperlink
protected boolean defaultIgnoreHyperlink -
detectCellType
protected boolean detectCellType -
defaultImageAnchorType
-
collapseRowSpan
protected boolean collapseRowSpan -
defaultUseTimeZone
protected boolean defaultUseTimeZone -
imageBorderFixEnabled
protected boolean imageBorderFixEnabled
-
-
Constructor Details
-
ExcelAbstractExporter
public ExcelAbstractExporter()- See Also:
-
ExcelAbstractExporter
-
-
Method Details
-
getDefaultFont
-
exportReport
Description copied from interface:ExporterPerforms the export.- Specified by:
exportReportin interfaceExporter<ExporterInput,RC extends XlsReportConfiguration, C extends XlsExporterConfiguration, OutputStreamExporterOutput> - Specified by:
exportReportin classJRAbstractExporter<RC extends XlsReportConfiguration,C extends XlsExporterConfiguration, OutputStreamExporterOutput, E extends JRExporterContext> - Throws:
JRException
-
ensureInput
protected void ensureInput()- Overrides:
ensureInputin classJRAbstractExporter<RC extends XlsReportConfiguration,C extends XlsExporterConfiguration, OutputStreamExporterOutput, E extends JRExporterContext>
-
initExport
protected void initExport()- Overrides:
initExportin classJRAbstractExporter<RC extends XlsReportConfiguration,C extends XlsExporterConfiguration, OutputStreamExporterOutput, E extends JRExporterContext>
-
initReport
protected void initReport()- Overrides:
initReportin classJRAbstractExporter<RC extends XlsReportConfiguration,C extends XlsExporterConfiguration, OutputStreamExporterOutput, E extends JRExporterContext>
-
updatePrintSettings
protected void updatePrintSettings(JRXlsAbstractExporter.SheetInfo.SheetPrintSettings printSettings, XlsReportConfiguration configuration) -
mergeAndSetRowLevels
protected void mergeAndSetRowLevels(XlsRowLevelInfo levelInfo, SortedMap<String, Boolean> rowLevelMap, int rowIndex) -
getStyledText
- Overrides:
getStyledTextin classJRAbstractExporter<RC extends XlsReportConfiguration,C extends XlsExporterConfiguration, OutputStreamExporterOutput, E extends JRExporterContext>
-
getTextAlignHolder
-
getImageBorderCorrection
-
getSheetName
-
getSheetName
-
calculateWidthForDinAN
protected final int calculateWidthForDinAN(int n) -
calculateHeightForDinAN
protected final int calculateHeightForDinAN(int n) -
calculateWidthForDinBN
protected final int calculateWidthForDinBN(int n) -
calculateHeightForDinBN
protected final int calculateHeightForDinBN(int n) -
calculateWidthForDinCN
protected final int calculateWidthForDinCN(int n) -
calculateHeightForDinCN
protected final int calculateHeightForDinCN(int n) -
isWrapText
-
isCellLocked
-
isShrinkToFit
-
isIgnoreTextFormatting
-
getFormula
-
setSheetNames
protected void setSheetNames() -
hasGlobalSheetNames
protected boolean hasGlobalSheetNames() -
isCellHidden
-
getConvertedPattern
-
getColumnIndex
- Returns:
- the calculated column index
-
getColumnName
Deprecated.Replaced byJRStringUtil.getLetterNumeral(int, boolean). -
resetAutoFilters
protected void resetAutoFilters() -
isUseTimeZone
-
translateDateValue
-
isValidScale
-
getMaxRowsPerSheet
-
getNature
-
getColumIndexName
- Parameters:
colIndex- The 0-based integer column index- Returns:
- The column name computed from the 0-based column index
-
configureDefinedNames
-
configureDefinedNames
-
configureDefinedNames
-
toExcelName
-
openWorkbook
- Throws:
JRExceptionIOException
-
closeSheet
protected abstract void closeSheet() -
closeWorkbook
- Throws:
JRExceptionIOException
-
setColumnWidth
protected abstract void setColumnWidth(int col, int width, boolean autoFit) -
addRowBreak
protected abstract void addRowBreak(int rowIndex) -
setFreezePane
protected abstract void setFreezePane(int rowIndex, int colIndex) -
setSheetName
-
setAutoFilter
-
setRowLevels
-
exportReportToStream
- Throws:
JRExceptionIOException
-
exportEmptyReport
- Throws:
JRExceptionIOException
-
JRStringUtil.getLetterNumeral(int, boolean).