Class JRDocxExporter
- java.lang.Object
-
- net.sf.jasperreports.engine.JRAbstractExporter<DocxReportConfiguration,DocxExporterConfiguration,OutputStreamExporterOutput,JRDocxExporterContext>
-
- net.sf.jasperreports.engine.export.ooxml.JRDocxExporter
-
- All Implemented Interfaces:
Exporter<ExporterInput,DocxReportConfiguration,DocxExporterConfiguration,OutputStreamExporterOutput>
public class JRDocxExporter extends JRAbstractExporter<DocxReportConfiguration,DocxExporterConfiguration,OutputStreamExporterOutput,JRDocxExporterContext>
Exports a JasperReports document to DOCX format. It has binary output type and exports the document to a grid-based layout, therefore having the known limitations of grid exporters. It can work in batch mode and supports all types of exporter input and output, content filtering, and font mappings. Currently, there are the following special configurations that can be made to a DOCX exporter instance (seeDocxReportConfiguration
):- Forcing the use of nested tables to render the content of frame elements using either
the
isFramesAsNestedTables()
exporter configuration flag or its corresponding exporter hint callednet.sf.jasperreports.export.docx.frames.as.nested.tables
. - Allowing table rows to adjust their height if more text is typed into their cells using
the Word editor. This is controlled using either the
isFlexibleRowHeight()
exporter configuration flag, or its corresponding exporter hint callednet.sf.jasperreports.export.docx.flexible.row.height
. - Ignoring hyperlinks in generated documents if they are not intended for the DOCX output format. This can be
customized using either the
isIgnoreHyperlink()
exporter configuration flag, or its corresponding exporter hint callednet.sf.jasperreports.export.docx.ignore.hyperlink
- Author:
- Sanda Zaharia (shertage@users.sourceforge.net)
- See Also:
DocxReportConfiguration
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
JRDocxExporter.ExporterContext
-
Nested classes/interfaces inherited from class net.sf.jasperreports.engine.JRAbstractExporter
JRAbstractExporter.BaseExporterContext, JRAbstractExporter.PageRange
-
-
Field Summary
-
Fields 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 Constructor Description JRDocxExporter()
JRDocxExporter(JasperReportsContext jasperReportsContext)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
endHyperlink(boolean isText)
protected void
ensureInput()
protected void
exportEllipse(DocxTableHelper tableHelper, JRPrintEllipse ellipse, JRExporterGridCell gridCell)
protected void
exportFrame(DocxTableHelper tableHelper, JRPrintFrame frame, JRExporterGridCell gridCell)
In deep grids, this is called only for empty frames.protected void
exportGenericElement(DocxTableHelper tableHelper, JRGenericPrintElement element, JRExporterGridCell gridCell)
protected void
exportGrid(JRGridLayout gridLayout, JRPrintElementIndex frameIndex)
protected void
exportHeader(JRPrintPage page)
void
exportImage(DocxTableHelper tableHelper, JRPrintImage image, JRExporterGridCell gridCell)
protected void
exportLine(DocxTableHelper tableHelper, JRPrintLine line, JRExporterGridCell gridCell)
protected void
exportPage(JRPrintPage page)
protected void
exportRectangle(DocxTableHelper tableHelper, JRPrintRectangle rectangle, JRExporterGridCell gridCell)
void
exportReport()
Performs the export.protected void
exportReportToStream(OutputStream os)
protected void
exportStyledText(JRStyle style, JRStyledText styledText, Locale locale, boolean hiddenText, boolean startedHyperlink, boolean isNewLineJustified, boolean rtl)
void
exportText(DocxTableHelper tableHelper, JRPrintText text, JRExporterGridCell gridCell)
protected Class<DocxExporterConfiguration>
getConfigurationInterface()
protected JRPrintElementIndex
getElementIndex(JRExporterGridCell gridCell)
String
getExporterKey()
String
getExporterPropertiesPrefix()
Returns the properties prefix for the current exporter.protected String
getHyperlinkTarget(JRPrintHyperlink link)
protected String
getHyperlinkURL(JRPrintHyperlink link)
protected Class<DocxReportConfiguration>
getItemConfigurationInterface()
static JRPrintElementIndex
getPrintElementIndex(String imageName)
protected JRStyledText
getStyledText(JRPrintText textElement, boolean setBackcolor)
protected void
initExport()
protected void
initReport()
protected void
insertBookmark(String bookmark, BaseHelper helper)
protected void
restoreBackcolor()
protected void
setBackcolor(Color color)
protected boolean
startHyperlink(JRPrintHyperlink link, boolean isText)
-
Methods inherited from class net.sf.jasperreports.engine.JRAbstractExporter
checkInterrupted, createFilter, defaultParseNumber, ensureJasperReportsContext, ensureOutput, getBooleanCellValue, getCurrentConfiguration, getCurrentItemConfiguration, getCurrentJasperPrint, getDateCellValue, getDateFormat, getExporterConfiguration, getExporterContext, getExporterInput, getExporterOutput, getHyperlinkProducer, 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 Detail
-
DOCX_EXPORTER_KEY
public static final String DOCX_EXPORTER_KEY
The exporter key, as used inGenericElementHandlerEnviroment.getElementHandler(JRGenericElementType, String)
.- See Also:
- Constant Field Values
-
EXCEPTION_MESSAGE_KEY_COLUMN_COUNT_OUT_OF_RANGE
public static final String EXCEPTION_MESSAGE_KEY_COLUMN_COUNT_OUT_OF_RANGE
- See Also:
- Constant Field Values
-
DOCX_EXPORTER_PROPERTIES_PREFIX
public static final String DOCX_EXPORTER_PROPERTIES_PREFIX
- See Also:
- Constant Field Values
-
PROPERTY_HIDDEN_TEXT
public static final String PROPERTY_HIDDEN_TEXT
This property is used to mark text elements as being hidden either for printing or on-screen display.- See Also:
JRPropertiesUtil
, Constant Field Values
-
JR_PAGE_ANCHOR_PREFIX
public static final String JR_PAGE_ANCHOR_PREFIX
- See Also:
- Constant Field Values
-
IMAGE_NAME_PREFIX
public static final String IMAGE_NAME_PREFIX
- See Also:
- Constant Field Values
-
IMAGE_NAME_PREFIX_LEGTH
protected static final int IMAGE_NAME_PREFIX_LEGTH
-
IMAGE_LINK_PREFIX
public static final String IMAGE_LINK_PREFIX
- See Also:
- Constant Field Values
-
docxZip
protected DocxZip docxZip
-
docHelper
protected DocxDocumentHelper docHelper
-
docWriter
protected Writer docWriter
-
headerHelper
protected DocxHeaderHelper headerHelper
-
headerWriter
protected Writer headerWriter
-
crtDocHelper
protected DocxDocumentHelper crtDocHelper
-
crtDocWriter
protected Writer crtDocWriter
-
rendererToImagePathMap
protected Map<String,Pair<String,ExifOrientationEnum>> rendererToImagePathMap
-
renderersCache
protected RenderersCache renderersCache
-
reportIndex
protected int reportIndex
-
pageIndex
protected int pageIndex
-
startPageIndex
protected int startPageIndex
-
endPageIndex
protected int endPageIndex
-
tableIndex
protected int tableIndex
-
headerIndex
protected int headerIndex
-
startPage
protected boolean startPage
-
invalidCharReplacement
protected String invalidCharReplacement
-
pageFormat
protected PrintPageFormat pageFormat
-
pageGridLayout
protected JRGridLayout pageGridLayout
-
backcolorStack
protected LinkedList<Color> backcolorStack
-
backcolor
protected Color backcolor
-
runHelper
protected DocxRunHelper runHelper
-
headerRunHelper
protected DocxRunHelper headerRunHelper
-
crtRunHelper
protected DocxRunHelper crtRunHelper
-
backgroundNature
protected ExporterNature backgroundNature
-
pageNature
protected ExporterNature pageNature
-
bookmarkIndex
protected long bookmarkIndex
-
pageAnchor
protected String pageAnchor
-
relsHelper
protected DocxRelsHelper relsHelper
-
headerRelsHelper
protected DocxHeaderRelsHelper headerRelsHelper
-
crtRelsHelper
protected DocxRelsHelper crtRelsHelper
-
ctHelper
protected DocxContentTypesHelper ctHelper
-
appHelper
protected PropsAppHelper appHelper
-
coreHelper
protected PropsCoreHelper coreHelper
-
docxFontHelper
protected DocxFontHelper docxFontHelper
-
docxFontTableHelper
protected DocxFontTableHelper docxFontTableHelper
-
docxFontTableRelsHelper
protected DocxFontTableRelsHelper docxFontTableRelsHelper
-
-
Constructor Detail
-
JRDocxExporter
public JRDocxExporter()
- See Also:
JRDocxExporter(JasperReportsContext)
-
JRDocxExporter
public JRDocxExporter(JasperReportsContext jasperReportsContext)
-
-
Method Detail
-
getConfigurationInterface
protected Class<DocxExporterConfiguration> getConfigurationInterface()
-
getItemConfigurationInterface
protected Class<DocxReportConfiguration> getItemConfigurationInterface()
-
exportReport
public void exportReport() throws JRException
Description copied from interface:Exporter
Performs the export.- Specified by:
exportReport
in interfaceExporter<ExporterInput,DocxReportConfiguration,DocxExporterConfiguration,OutputStreamExporterOutput>
- Specified by:
exportReport
in classJRAbstractExporter<DocxReportConfiguration,DocxExporterConfiguration,OutputStreamExporterOutput,JRDocxExporterContext>
- Throws:
JRException
-
initExport
protected void initExport()
-
initReport
protected void initReport()
-
exportReportToStream
protected void exportReportToStream(OutputStream os) throws JRException, IOException
- Throws:
JRException
IOException
-
exportHeader
protected void exportHeader(JRPrintPage page) throws JRException
- Throws:
JRException
-
exportPage
protected void exportPage(JRPrintPage page) throws JRException
- Throws:
JRException
-
exportGrid
protected void exportGrid(JRGridLayout gridLayout, JRPrintElementIndex frameIndex) throws JRException
- Throws:
JRException
-
exportLine
protected void exportLine(DocxTableHelper tableHelper, JRPrintLine line, JRExporterGridCell gridCell)
-
exportRectangle
protected void exportRectangle(DocxTableHelper tableHelper, JRPrintRectangle rectangle, JRExporterGridCell gridCell)
-
exportEllipse
protected void exportEllipse(DocxTableHelper tableHelper, JRPrintEllipse ellipse, JRExporterGridCell gridCell)
-
exportText
public void exportText(DocxTableHelper tableHelper, JRPrintText text, JRExporterGridCell gridCell)
-
exportStyledText
protected void exportStyledText(JRStyle style, JRStyledText styledText, Locale locale, boolean hiddenText, boolean startedHyperlink, boolean isNewLineJustified, boolean rtl)
-
exportImage
public void exportImage(DocxTableHelper tableHelper, JRPrintImage image, JRExporterGridCell gridCell) throws JRException
- Throws:
JRException
-
getElementIndex
protected JRPrintElementIndex getElementIndex(JRExporterGridCell gridCell)
-
getPrintElementIndex
public static JRPrintElementIndex getPrintElementIndex(String imageName)
-
exportFrame
protected void exportFrame(DocxTableHelper tableHelper, JRPrintFrame frame, JRExporterGridCell gridCell) throws JRException
In deep grids, this is called only for empty frames.- Throws:
JRException
-
exportGenericElement
protected void exportGenericElement(DocxTableHelper tableHelper, JRGenericPrintElement element, JRExporterGridCell gridCell)
-
setBackcolor
protected void setBackcolor(Color color)
-
restoreBackcolor
protected void restoreBackcolor()
-
startHyperlink
protected boolean startHyperlink(JRPrintHyperlink link, boolean isText)
-
getHyperlinkTarget
protected String getHyperlinkTarget(JRPrintHyperlink link)
-
getHyperlinkURL
protected String getHyperlinkURL(JRPrintHyperlink link)
-
endHyperlink
protected void endHyperlink(boolean isText)
-
insertBookmark
protected void insertBookmark(String bookmark, BaseHelper helper)
-
ensureInput
protected void ensureInput()
-
getStyledText
protected JRStyledText getStyledText(JRPrintText textElement, boolean setBackcolor)
-
getExporterKey
public String getExporterKey()
- Specified by:
getExporterKey
in classJRAbstractExporter<DocxReportConfiguration,DocxExporterConfiguration,OutputStreamExporterOutput,JRDocxExporterContext>
-
getExporterPropertiesPrefix
public String getExporterPropertiesPrefix()
Description copied from class:JRAbstractExporter
Returns the properties prefix for the current exporter.- Specified by:
getExporterPropertiesPrefix
in classJRAbstractExporter<DocxReportConfiguration,DocxExporterConfiguration,OutputStreamExporterOutput,JRDocxExporterContext>
- Returns:
- the properties prefix for the current exporter
-
-