net.sf.jasperreports.engine.export.ooxml

## Class JRDocxExporter

- java.lang.Object
- - net.sf.jasperreports.engine.JRAbstractExporter<DocxReportConfiguration,DocxExporterConfiguration,OutputStreamExporterOutput,JRDocxExporterContext>
  - - net.sf.jasperreports.engine.export.ooxml.JRDocxExporter

- All Implemented Interfaces:
    JRExporter<ExporterInput,DocxReportConfiguration,DocxExporterConfiguration,OutputStreamExporterOutput>, 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 (see `DocxReportConfiguration`):
  - 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 called `net.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 called `net.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 called `net.sf.jasperreports.export.docx.ignore.hyperlinks`
  Version:
    $Id: JRDocxExporter.java 7067 2014-04-30 09:32:46Z shertage $
  Author:
    sanda zaharia (shertage@users.sourceforge.net)
  See Also:
    `DocxReportConfiguration`

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `protected class` | `JRDocxExporter.ExporterContext`

    - ### Nested classes/interfaces inherited from class net.sf.jasperreports.engine.JRAbstractExporter

      `JRAbstractExporter.BaseExporterContext, JRAbstractExporter.PageRange`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected java.awt.Color` | `backcolor`
    `protected java.util.LinkedList<java.awt.Color>` | `backcolorStack`
    `protected long` | `bookmarkIndex`
    `protected DocxDocumentHelper` | `docHelper`
    `protected java.io.Writer` | `docWriter`
    `static java.lang.String` | `DOCX_EXPORTER_KEY` The exporter key, as used in `GenericElementHandlerEnviroment.getElementHandler(JRGenericElementType, String)`.
    `protected static java.lang.String` | `DOCX_EXPORTER_PROPERTIES_PREFIX`
    `protected DocxZip` | `docxZip`
    `protected int` | `endPageIndex`
    `static java.lang.String` | `IMAGE_LINK_PREFIX`
    `static java.lang.String` | `IMAGE_NAME_PREFIX`
    `protected static int` | `IMAGE_NAME_PREFIX_LEGTH`
    `protected java.lang.String` | `invalidCharReplacement`
    `static java.lang.String` | `JR_PAGE_ANCHOR_PREFIX`
    `protected ExporterNature` | `nature`
    `protected java.lang.String` | `pageAnchor`
    `protected int` | `pageIndex`
    `static java.lang.String` | `PROPERTY_HIDDEN_TEXT` This property is used to mark text elements as being hidden either for printing or on-screen display.
    `static java.lang.String` | `PROPERTY_IGNORE_HYPERLINK` Deprecated. Replaced by `DocxReportConfiguration.PROPERTY_IGNORE_HYPERLINK`.
    `protected DocxRelsHelper` | `relsHelper`
    `protected java.util.Map<java.lang.String,java.lang.String>` | `rendererToImagePathMap`
    `protected int` | `reportIndex`
    `protected DocxRunHelper` | `runHelper`
    `protected boolean` | `startPage`
    `protected int` | `startPageIndex`
    `protected int` | `tableIndex`

    - ### Fields inherited from class net.sf.jasperreports.engine.JRAbstractExporter

      `allSelector, crtCompositeConfiguration, crtCompositeItemConfiguration, crtItem, dateFormatCache, EXCEPTION_MESSAGE_KEY_END_PAGE_INDEX_OUT_OF_RANGE, EXCEPTION_MESSAGE_KEY_PAGE_INDEX_OUT_OF_RANGE, EXCEPTION_MESSAGE_KEY_START_PAGE_INDEX_OUT_OF_RANGE, exporterConfiguration, exporterContext, exporterInput, exporterOutput, filter, itemConfiguration, jasperPrint, jasperReportsContext, noBackcolorSelector, noneSelector, numberFormatCache, parameters, propertiesUtil, PROPERTY_DEFAULT_FILTER_FACTORY, PROPERTY_SUFFIX_DEFAULT_FILTER_FACTORY, styledTextUtil`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `JRDocxExporter()`
    `JRDocxExporter(JasperReportsContext jasperReportsContext)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `endHyperlink(boolean isText)`
    `protected void` | `ensureInput()`
    `protected void` | `ensureOutput()`
    `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)`
    `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(java.io.OutputStream os)`
    `protected void` | `exportStyledText(JRStyle style, JRStyledText styledText, java.util.Locale locale, boolean hiddenText, boolean startedHyperlink)`
    `void` | `exportText(DocxTableHelper tableHelper, JRPrintText text, JRExporterGridCell gridCell)`
    `protected java.lang.Class<DocxExporterConfiguration>` | `getConfigurationInterface()`
    `protected JRPrintElementIndex` | `getElementIndex(JRExporterGridCell gridCell)`
    `java.lang.String` | `getExporterKey()`
    `java.lang.String` | `getExporterPropertiesPrefix()` Returns the properties prefix for the current exporter.
    `protected java.lang.String` | `getHyperlinkTarget(JRPrintHyperlink link)`
    `protected java.lang.String` | `getHyperlinkURL(JRPrintHyperlink link)`
    `protected java.lang.Class<DocxReportConfiguration>` | `getItemConfigurationInterface()`
    `static JRPrintElementIndex` | `getPrintElementIndex(java.lang.String imageName)` protected void writeImageMap(String imageMapName, JRPrintHyperlink mainHyperlink, List imageMapAreas) { writer.write("\n"); for (Iterator it = imageMapAreas.iterator(); it.hasNext();) { JRPrintImageAreaHyperlink areaHyperlink = (JRPrintImageAreaHyperlink) it.next(); JRPrintImageArea area = areaHyperlink.getArea(); writer.write(" \n"); } if (mainHyperlink.getHyperlinkTypeValue() !
    `protected void` | `initExport()`
    `protected void` | `initReport()`
    `protected void` | `insertBookmark(java.lang.String bookmark, BaseHelper helper)`
    `protected void` | `restoreBackcolor()`
    `protected void` | `setBackcolor(java.awt.Color color)`
    `protected boolean` | `startHyperlink(JRPrintHyperlink link, boolean isText)`

    - ### Methods inherited from class net.sf.jasperreports.engine.JRAbstractExporter

      `createFilter, defaultParseNumber, ensureJasperReportsContext, getBooleanCellValue, getCurrentConfiguration, getCurrentItemConfiguration, getCurrentJasperPrint, getCustomHandler, getDateCellValue, getDateFormat, getExporterContext, getExporterInput, getExporterOutput, getHyperlinkProducer, getJasperReportsContext, getLocale, getNumberCellValue, getNumberFormat, getOffsetX, getOffsetY, getPageRange, getParameter, getParameters, getPropertiesUtil, getReportContext, getStyledText, getStyledText, getTextFormatFactoryClass, getTextLocale, getTextTimeZone, getTextValue, getTextValueString, reset, resetClassLoader, resetExportContext, restoreElementOffsets, setClassLoader, setConfiguration, setConfiguration, setCurrentExporterInputItem, setExporterInput, setExporterOutput, setFrameElementsOffset, setJasperPrint, setJasperReportsContext, setOffset, setOffset, setParameter, setParameters, setReportContext`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### DOCX_EXPORTER_KEY

          public static final java.lang.String DOCX_EXPORTER_KEY

      The exporter key, as used in `GenericElementHandlerEnviroment.getElementHandler(JRGenericElementType, String)`.
      See Also:
        Constant Field Values

    - #### DOCX_EXPORTER_PROPERTIES_PREFIX

          protected static final java.lang.String DOCX_EXPORTER_PROPERTIES_PREFIX

      See Also:
        Constant Field Values

    - #### PROPERTY_IGNORE_HYPERLINK

          public static final java.lang.String PROPERTY_IGNORE_HYPERLINK

      Deprecated. Replaced by `DocxReportConfiguration.PROPERTY_IGNORE_HYPERLINK`.
      See Also:
        Constant Field Values

    - #### PROPERTY_HIDDEN_TEXT

          public static final java.lang.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 java.lang.String JR_PAGE_ANCHOR_PREFIX

      See Also:
        Constant Field Values

    - #### IMAGE_NAME_PREFIX

          public static final java.lang.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 java.lang.String IMAGE_LINK_PREFIX

      See Also:
        Constant Field Values

    - #### docxZip

          protected DocxZip docxZip

    - #### docHelper

          protected DocxDocumentHelper docHelper

    - #### docWriter

          protected java.io.Writer docWriter

    - #### rendererToImagePathMap

          protected java.util.Map<java.lang.String,java.lang.String> rendererToImagePathMap

    - #### reportIndex

          protected int reportIndex

    - #### pageIndex

          protected int pageIndex

    - #### startPageIndex

          protected int startPageIndex

    - #### endPageIndex

          protected int endPageIndex

    - #### tableIndex

          protected int tableIndex

    - #### startPage

          protected boolean startPage

    - #### invalidCharReplacement

          protected java.lang.String invalidCharReplacement

    - #### backcolorStack

          protected java.util.LinkedList<java.awt.Color> backcolorStack

    - #### backcolor

          protected java.awt.Color backcolor

    - #### runHelper

          protected DocxRunHelper runHelper

    - #### nature

          protected ExporterNature nature

    - #### bookmarkIndex

          protected long bookmarkIndex

    - #### pageAnchor

          protected java.lang.String pageAnchor

    - #### relsHelper

          protected DocxRelsHelper relsHelper

  - ### Constructor Detail

    - #### JRDocxExporter

          public JRDocxExporter()

      See Also:
        `JRDocxExporter(JasperReportsContext)`

    - #### JRDocxExporter

          public JRDocxExporter(JasperReportsContext jasperReportsContext)

  - ### Method Detail

    - #### getConfigurationInterface

          protected java.lang.Class<DocxExporterConfiguration> getConfigurationInterface()

      Specified by:
        `getConfigurationInterface` in class `JRAbstractExporter<DocxReportConfiguration,DocxExporterConfiguration,OutputStreamExporterOutput,JRDocxExporterContext>`

    - #### getItemConfigurationInterface

          protected java.lang.Class<DocxReportConfiguration> getItemConfigurationInterface()

      Specified by:
        `getItemConfigurationInterface` in class `JRAbstractExporter<DocxReportConfiguration,DocxExporterConfiguration,OutputStreamExporterOutput,JRDocxExporterContext>`

    - #### ensureOutput

          protected void ensureOutput()

      Specified by:
        `ensureOutput` in class `JRAbstractExporter<DocxReportConfiguration,DocxExporterConfiguration,OutputStreamExporterOutput,JRDocxExporterContext>`

    - #### exportReport

          public void exportReport()
                            throws JRException

      Description copied from interface: `Exporter`
      Performs the export.
      Specified by:
        `exportReport` in interface `Exporter<ExporterInput,DocxReportConfiguration,DocxExporterConfiguration,OutputStreamExporterOutput>`
      Specified by:
        `exportReport` in class `JRAbstractExporter<DocxReportConfiguration,DocxExporterConfiguration,OutputStreamExporterOutput,JRDocxExporterContext>`
      Throws:
        `JRException`

    - #### initExport

          protected void initExport()

      Overrides:
        `initExport` in class `JRAbstractExporter<DocxReportConfiguration,DocxExporterConfiguration,OutputStreamExporterOutput,JRDocxExporterContext>`

    - #### initReport

          protected void initReport()

      Overrides:
        `initReport` in class `JRAbstractExporter<DocxReportConfiguration,DocxExporterConfiguration,OutputStreamExporterOutput,JRDocxExporterContext>`

    - #### exportReportToStream

          protected void exportReportToStream(java.io.OutputStream os)
                                       throws JRException,
                                              java.io.IOException

      Throws:
        `JRException`
        `java.io.IOException`

    - #### 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,
                              java.util.Locale locale,
                              boolean hiddenText,
                              boolean startedHyperlink)

    - #### 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(java.lang.String imageName)

      protected void writeImageMap(String imageMapName, JRPrintHyperlink mainHyperlink, List imageMapAreas) { writer.write("\n"); for (Iterator it = imageMapAreas.iterator(); it.hasNext();) { JRPrintImageAreaHyperlink areaHyperlink = (JRPrintImageAreaHyperlink) it.next(); JRPrintImageArea area = areaHyperlink.getArea(); writer.write(" \n"); } if (mainHyperlink.getHyperlinkTypeValue() != NONE) { writer.write(" \n"); } writer.write("\n"); } protected void writeImageAreaCoordinates(JRPrintImageArea area) { int[] coords = area.getCoordinates(); if (coords != null && coords.length > 0) { StringBuffer coordsEnum = new StringBuffer(coords.length * 4); coordsEnum.append(coords[0]); for (int i = 1; i < coords.length; i++) { coordsEnum.append(','); coordsEnum.append(coords[i]); } writer.write(" coords=\"" + coordsEnum + "\""); } } protected void writeImageAreaHyperlink(JRPrintHyperlink hyperlink) { String href = getHyperlinkURL(hyperlink); if (href == null) { writer.write(" nohref=\"nohref\""); } else { writer.write(" href=\"" + href + "\""); String target = getHyperlinkTarget(hyperlink); if (target != null) { writer.write(" target=\""); writer.write(target); writer.write("\""); } } if (hyperlink.getHyperlinkTooltip() != null) { writer.write(" title=\""); writer.write(JRStringUtil.xmlEncode(hyperlink.getHyperlinkTooltip())); writer.write("\""); } } /**

    - #### 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(java.awt.Color color)

    - #### restoreBackcolor

          protected void restoreBackcolor()

    - #### startHyperlink

          protected boolean startHyperlink(JRPrintHyperlink link,
                               boolean isText)

    - #### getHyperlinkTarget

          protected java.lang.String getHyperlinkTarget(JRPrintHyperlink link)

    - #### getHyperlinkURL

          protected java.lang.String getHyperlinkURL(JRPrintHyperlink link)

    - #### endHyperlink

          protected void endHyperlink(boolean isText)

    - #### insertBookmark

          protected void insertBookmark(java.lang.String bookmark,
                            BaseHelper helper)

    - #### ensureInput

          protected void ensureInput()

      Overrides:
        `ensureInput` in class `JRAbstractExporter<DocxReportConfiguration,DocxExporterConfiguration,OutputStreamExporterOutput,JRDocxExporterContext>`

    - #### getExporterKey

          public java.lang.String getExporterKey()

      Specified by:
        `getExporterKey` in class `JRAbstractExporter<DocxReportConfiguration,DocxExporterConfiguration,OutputStreamExporterOutput,JRDocxExporterContext>`

    - #### getExporterPropertiesPrefix

          public java.lang.String getExporterPropertiesPrefix()

      Description copied from class: `JRAbstractExporter`
      Returns the properties prefix for the current exporter.
      Specified by:
        `getExporterPropertiesPrefix` in class `JRAbstractExporter<DocxReportConfiguration,DocxExporterConfiguration,OutputStreamExporterOutput,JRDocxExporterContext>`
      Returns:
        the properties prefix for the current exporter

© 2001-2010 Jaspersoft Corporation www.jaspersoft.com