Class JxlsTemplateFillerBuilder<SELF extends JxlsTemplateFillerBuilder<SELF>>

java.lang.Object
org.jxls.builder.JxlsTemplateFillerBuilder<SELF>

public class JxlsTemplateFillerBuilder<SELF extends JxlsTemplateFillerBuilder<SELF>> extends Object
This builder is the starting point for creating reports using Jxls. After setting the options using the with... methods, call build(). This results in a TemplateFiller with a fill() method. See website for detailed explanations of all options. You must call withTransformerFactory() and withTemplate().
  • Field Details

    • DEFAULT_EXPRESSION_BEGIN

      public static final String DEFAULT_EXPRESSION_BEGIN
      See Also:
    • DEFAULT_EXPRESSION_END

      public static final String DEFAULT_EXPRESSION_END
      See Also:
    • expressionNotationBegin

      protected String expressionNotationBegin
    • expressionNotationEnd

      protected String expressionNotationEnd
    • logger

      protected JxlsLogger logger
    • updateCellDataArea

      protected boolean updateCellDataArea
      old name: formulaProcessingRequired
    • ignoreColumnProps

      protected boolean ignoreColumnProps
    • ignoreRowProps

      protected boolean ignoreRowProps
    • recalculateFormulasBeforeSaving

      protected boolean recalculateFormulasBeforeSaving
      old name: evaluateFormulas
    • recalculateFormulasOnOpening

      protected boolean recalculateFormulasOnOpening
      old name: fullFormulaRecalculationOnOpening
    • keepTemplateSheet

      protected KeepTemplateSheet keepTemplateSheet
      old names: deleteTemplateSheet, hideTemplateSheet
    • commands

      protected final Map<String,Class<? extends Command>> commands
    • clearTemplateCells

      protected boolean clearTemplateCells
    • template

      protected InputStream template
    • needsContextList

      protected final List<NeedsPublicContext> needsContextList
    • preWriteActions

      protected final List<PreWriteAction> preWriteActions
    • runVarAccess

      protected RunVarAccess runVarAccess
  • Constructor Details

    • JxlsTemplateFillerBuilder

      public JxlsTemplateFillerBuilder()
  • Method Details

    • newInstance

      public static JxlsTemplateFillerBuilder<?> newInstance()
      Returns:
      new builder instance
    • build

      public JxlsTemplateFiller build()
      Returns:
      JxlsTemplateFiller with all options and the template
    • buildAndFill

      public void buildAndFill(Map<String,Object> data, JxlsOutput output)
      Builds template filler, creates Excel report with given data and saves it to output.
      Parameters:
      data - not null
      output - not null
    • buildAndFill

      public void buildAndFill(Map<String,Object> data, File outputFile)
      Builds template filler, creates Excel report with given data and saves it to given output file.
      Parameters:
      data - -
      outputFile - -
    • buildAndFill

      public byte[] buildAndFill(Map<String,Object> data)
      Builds template filler, creates Excel report with given data and returns Excel file as byte array.
      Parameters:
      data - -
      Returns:
      byte[]
    • getOptions

      public JxlsOptions getOptions()
      Creates internal used options object for template filler
      Returns:
      JxlsOptions
    • withExpressionEvaluatorFactory

      public SELF withExpressionEvaluatorFactory(ExpressionEvaluatorFactory expressionEvaluatorFactory)
      Defines a factory class with which ExpressionEvaluator classes are created during report creation. It is recommended to use new ExpressionEvaluatorFactoryJexlImpl(false, true, JxlsJexlPermissions.RESTRICTED) in production use.
      Parameters:
      expressionEvaluatorFactory - not null. Default is ExpressionEvaluatorFactoryJexlImpl with settings: silent=true, strict=false, JxlsJexlPermissions.UNRESTRICTED.
      Returns:
      this
    • getExpressionEvaluatorFactory

      public ExpressionEvaluatorFactory getExpressionEvaluatorFactory()
    • withExpressionNotation

      public SELF withExpressionNotation(String begin, String end)
      Expressions in Excel cells are inside ${ and }. Use this method to change those Strings.
      Parameters:
      begin - You can use null for the default value "${".
      end - You can use null for the default value "}".
      Returns:
      this
    • withLogger

      public SELF withLogger(JxlsLogger logger)
      Defines which class should be used for logging and throwing exceptions.
      Parameters:
      logger - not null
      Returns:
      this
    • withFormulaProcessor

      public SELF withFormulaProcessor(FormulaProcessor formulaProcessor)
      Parameters:
      formulaProcessor - null for disabling formula processing, default: StandardFormulaProcessor
      Returns:
      this
    • getFormulaProcessor

      public FormulaProcessor getFormulaProcessor()
    • withFastFormulaProcessor

      public SELF withFastFormulaProcessor()
      Sets FastFormulaProcessor which is 10 times faster but can handle only simple templates.
      Returns:
      this
    • withUpdateCellDataArea

      public SELF withUpdateCellDataArea(boolean updateCellDataArea)
      Cell reference tracking
      Parameters:
      updateCellDataArea - false to turn this feature off
      Returns:
      this
    • withIgnoreColumnProps

      public SELF withIgnoreColumnProps(boolean ignoreColumnProps)
      See website
      Parameters:
      ignoreColumnProps - default is false
      Returns:
      this
    • withIgnoreRowProps

      public SELF withIgnoreRowProps(boolean ignoreRowProps)
      See website
      Parameters:
      ignoreRowProps - default is false
      Returns:
      this
    • withRecalculateFormulasBeforeSaving

      public SELF withRecalculateFormulasBeforeSaving(boolean recalculateFormulasBeforeSaving)
      Call this method with argument false if you don't need an extra recalculation of all formula results before saving the Excel file.
      Parameters:
      recalculateFormulasBeforeSaving - default is true
      Returns:
      this
    • withRecalculateFormulasOnOpening

      public SELF withRecalculateFormulasOnOpening(boolean recalculateFormulasOnOpening)
      Call this method with argument true if you all formula results should be recalculated while opening the report file using Microsoft Excel.
      Parameters:
      recalculateFormulasOnOpening - default is false
      Returns:
      this
    • withKeepTemplateSheet

      public SELF withKeepTemplateSheet(KeepTemplateSheet keepTemplateSheet)
      This is for the multisheet feature. The template sheet is deleted by default. Call this method with argument KEEP if you want to keep the template sheet. Call this method with argument HIDE if you just want to hide the template sheet.
      Parameters:
      keepTemplateSheet - default is DELETE, null will be ignored.
      Returns:
      this
    • withAreaBuilder

      public SELF withAreaBuilder(AreaBuilder areaBuilder)
      See website
      Parameters:
      areaBuilder - not null. Default is XlsCommentAreaBuilder.
      Returns:
      this
    • getAreaBuilder

      public AreaBuilder getAreaBuilder()
    • withCommand

      public SELF withCommand(String name, Class<? extends Command> commandClass)
      Adds a command.
      Parameters:
      name - command name without "jx": prefix
      commandClass - -
      Returns:
      this
    • withClearTemplateCells

      public SELF withClearTemplateCells(boolean clearTemplateCells)
      Parameters:
      clearTemplateCells - true (default): cells where the expression can not be evaluated will be cleared, false: cells where the expression can not be evaluated will keep the expression.
      Returns:
      this
    • withTransformerFactory

      public SELF withTransformerFactory(JxlsTransformerFactory transformerFactory)
      See website
      Parameters:
      transformerFactory - -
      Returns:
      this
    • getTransformerFactory

      public JxlsTransformerFactory getTransformerFactory()
    • withStreaming

      public SELF withStreaming(JxlsStreaming streaming)
      Use streaming if you have large sheets. However, not all features can be used. See website.
      Parameters:
      streaming - Default is STREAMING_OFF for no streaming. STREAMING_ON: streaming for all sheets. AUTO_DETECT: streaming for sheets which have the exact text sheetStreaming="true" in its jx:area command.
      Returns:
      this
    • getStreaming

      public JxlsStreaming getStreaming()
    • needsPublicContext

      public SELF needsPublicContext(NeedsPublicContext needsPublicContext)
      If you are adding an object to the data map which needs PublicContext access, implement the NeedsPublicContext interface and call this method.
      Parameters:
      needsPublicContext - your class which implements NeedsPublicContext for getting the PublicContext instance during report creation
      Returns:
      this
    • withPreWriteAction

      public SELF withPreWriteAction(PreWriteAction preWriteAction)
      Parameters:
      preWriteAction - code to be executed before transformer.write() is executed
      Returns:
      this
    • withRunVarAccess

      public SELF withRunVarAccess(RunVarAccess runVarAccess)
      Change the behavior for accessing run vars.
      Parameters:
      runVarAccess - code that retrieves the value for a given key from the given data map
      Returns:
      this
    • withTemplate

      public SELF withTemplate(InputStream templateInputStream)
      Parameters:
      templateInputStream - Excel template as InputStream
      Returns:
      this
    • withTemplate

      public SELF withTemplate(URL templateURL) throws IOException
      Parameters:
      templateURL - Excel template as file defined by an URL
      Returns:
      this
      Throws:
      IOException
    • withTemplate

      public SELF withTemplate(File templateFile) throws FileNotFoundException
      Parameters:
      templateFile - Excel template file
      Returns:
      this
      Throws:
      FileNotFoundException
    • withTemplate

      public SELF withTemplate(String templateFileName) throws FileNotFoundException
      Parameters:
      templateFileName - Excel template file name
      Returns:
      this
      Throws:
      FileNotFoundException