Class DOCXFormatter

java.lang.Object
com.nomagic.magicreport.format.DefaultFormatter
com.nomagic.magicreport.format.DOCXFormatter
All Implemented Interfaces:
IFormatter

@OpenApiAll public class DOCXFormatter extends DefaultFormatter
The Velocity engine support for Docx.
Since:
Nov 16, 2009
  • Constructor Details

    • DOCXFormatter

      public DOCXFormatter(ITemplateEngine templateEngine)
      Create a Docx formatter with specific properties.
      Parameters:
      templateEngine - template engine
    • DOCXFormatter

      public DOCXFormatter(Properties properties)
      Create a Docx formatter with specific properties.
      Parameters:
      properties - template properties
  • Method Details

    • format

      public Object format(Object value)
      Convert an Object value into HTML format.
      Specified by:
      format in interface IFormatter
      Overrides:
      format in class DefaultFormatter
      Parameters:
      value - converting value
      Returns:
      object in default format.
    • createImage

      protected ITool.RetainedString createImage(Image image) throws IOException
      Create a DOCX image string from given Image object.
      Parameters:
      image - an Image object
      Returns:
      The String in DOCX image format.
      Throws:
      IOException - when IO error occurs
    • createImage

      protected ITool.RetainedString createImage(Image image, float width, float height, int flag) throws IOException
      Create a DOCX image string from given Image object.
      Parameters:
      image - an Image object
      width - the target image width
      height - the target image height
      flag - scaling image flag
      Returns:
      The String in DOCX image format.
      Throws:
      IOException - when IO error occurs
    • getPageSize

      public float[] getPageSize()
      Calculation for total paper width and total paper height after minus margin of page.
      Returns:
      float[] array of paper width and paper height
    • adjustImage

      protected float[] adjustImage(Image image, float w, float h, int flag)
      Returns [imageWidth, imageHeight, imageRotate, effectL, effectT, effectR, effectB ] the image will be rotated if necessary 914,400 EMU per inch 12,700 EMU in a point360,000 EMU per cm.
      Parameters:
      image - image object
      w - image width
      h - image height
      flag - scaling image flag
      Returns:
      the new dimension of image
    • createBookmark

      protected ITool.RetainedString createBookmark(Bookmark bookmark) throws IOException
      Create a DOCX bookmark string from given Bookmark object.
      Parameters:
      bookmark - an Bookmark object
      Returns:
      The String in DOCX bookmark format.
      Throws:
      IOException - when IO error occurs
    • createLink

      protected ITool.RetainedString createLink(Link link) throws IOException
      Create a DOCX link string from given Link object.
      Parameters:
      link - an Link object
      Returns:
      The String in DOCX link format.
      Throws:
      IOException - when IO error occurs
    • handleRef

      protected ITool.RetainedString handleRef(TextReference bookmark) throws IOException
      Handle TextReference for REF in DOCX
      Parameters:
      bookmark - an TextReference object
      Returns:
      The String in DOCX of bookmark or REF format.
      Throws:
      IOException
    • openRef

      protected ITool.RetainedString openRef(TextReference bookmark) throws IOException
      Create a DOCX ref string from given TextReference object.
      Parameters:
      bookmark - an TextReference object
      Returns:
      The String in DOCX bookmark format.
      Throws:
      IOException - when IO error occurs
    • createRef

      protected ITool.RetainedString createRef(TextReference bookmark) throws IOException
      Create a DOCX bookmark string for REF from given TextReference object.
      Parameters:
      bookmark - an TextReference object
      Returns:
      The String in DOCX bookmark for REF format.
      Throws:
      IOException - when IO error occurs
    • createGridSpan

      protected ITool.RetainedString createGridSpan(GridSpan span)
      Create a DOCX gridspan (merge columns horizontally) string from given GridSpan object.
      Parameters:
      span - an GridSpan object
      Returns:
      The String in DOCX for gridspan format.
    • createChart

      protected ITool.RetainedString createChart(Chart chart)
      Create a DOCX chart string from given Chart object.
      Parameters:
      span - an Chart object
      Returns:
      The String in DOCX for chart format.
    • createGridRowSpan

      protected ITool.RetainedString createGridRowSpan(GridRowSpan span)
      Create a DOCX gridrowspan (merge columns vertically) string from given GridRowSpan object.
      Parameters:
      span - an GridRowSpan object
      Returns:
      The String in DOCX for gridrowspan format.
    • getPaperWidth

      protected double getPaperWidth()
    • getPropertyPageWidth

      protected double getPropertyPageWidth()
    • getPaperHeight

      protected double getPaperHeight()
    • getPropertyPageHeight

      protected double getPropertyPageHeight()