Class XlsxDocument

All Implemented Interfaces:
Serializable, Identified

@Component public class XlsxDocument extends XlsxContainer implements Identified
This class extends XlsxContainer and implements Identified.
This class represent the Excel document where are added in the XLSheet. It needs to represent a DBView for each sheet in an Excel file.
See Also:
  • Constructor Details

    • XlsxDocument

      public XlsxDocument()
  • Method Details

    • getOrCreateCellStyle

      public org.apache.poi.xssf.usermodel.XSSFCellStyle getOrCreateCellStyle(String styleName, @NotNull @NotNull Supplier<org.apache.poi.xssf.usermodel.XSSFCellStyle> cellStyleSupplier)
      Gets an existing cell style from the cache or creates a new one using the provided supplier. This method implements the core caching mechanism for Excel cell styles, providing significant performance improvements when generating large XLSX documents with repeated formatting patterns.

      Caching Strategy:

      • Cache Hit: If a style with the given name exists in the cache, returns the cached instance
      • Cache Miss: If no cached style exists, invokes the supplier to create a new style and caches it
      • No Caching: If styleName is null, blank, or empty, bypasses cache and directly invokes supplier

      Example Usage:

      
       // In a formatting class
       XSSFCellStyle headerStyle = document.getOrCreateCellStyle("table_header",
           () -> createHeaderStyle(sheet, component));
      
       // With variant naming
       XSSFCellStyle evenRowStyle = document.getOrCreateCellStyle("data_row_even",
           () -> createDataRowStyle(sheet, component, false));
       
      Parameters:
      styleName - The unique name for the cell style used as cache key. If null, blank, or empty, caching is bypassed and the supplier is invoked directly. Should be descriptive and consistent across similar formatting scenarios.
      cellStyleSupplier - A Supplier that creates a new XSSFCellStyle when invoked. This supplier is called only when the style is not found in the cache or when caching is bypassed. Must not be null and should return a valid style.
      Returns:
      An XSSFCellStyle instance, either retrieved from cache or newly created by the supplier. The returned style is ready for use and will be cached for future requests with the same name.
      Throws:
      NullPointerException - if cellStyleSupplier is null
    • setIdentity

      public void setIdentity(Identity identity)
      Description copied from interface: Identified
      Sets the Identity to the component
      Specified by:
      setIdentity in interface Identified
      Overrides:
      setIdentity in class XlsxComponent
      Parameters:
      identity - The Identity that must be associated to the component
    • getIdentity

      public Identity getIdentity()
      Description copied from interface: Identified
      Returns the Identity associated to the component
      Specified by:
      getIdentity in interface Identified
      Overrides:
      getIdentity in class XlsxComponent
      Returns:
      The Identity of the user currently logged in the application
    • setPASSWORD

      public void setPASSWORD(String s)
      Sets the password for the document.
      Parameters:
      s - The password to set.
    • setENCRYPTIONPASSWORD

      public void setENCRYPTIONPASSWORD(String s)
      Sets the document's password that will be encrypted. .
      Parameters:
      s - The password to set.
    • setENCRYPTIONALGORITHM

      public void setENCRYPTIONALGORITHM(String s)
      Sets the encrypt algorithm to use to encrypth the password.
      Parameters:
      s - Possible algoritm are:
      • rc4
      • crypto
      • xor
      • default
    • setZIP64MODE

      public void setZIP64MODE(String s)
      Sets the ZIP64 mode for the XLSX file generation.

      ZIP64 is an extension to the ZIP format that allows files larger than 4GB. This method configures how ZIP64 extensions are applied when creating XLSX files.

      Parameters:
      s - the ZIP64 mode as a string (case-insensitive). Valid values are:
      • "ALWAYS" - Always use ZIP64 extensions for all entries, regardless of size. This may cause compatibility issues with some external readers (e.g., DuckDB, older Excel versions).
      • "ALWAYSWITHCOMPATIBILITY" - Always use ZIP64 with additional compatibility measures.
      • "NEVER" - Never use ZIP64 extensions. Files larger than 4GB will fail.
      • Any other value (default) - Use ZIP64 only when needed (AsNeeded mode). This is the recommended setting for maximum compatibility.
      See Also:
      • Zip64Mode
    • getParent

      public UINode getParent()
      Description copied from class: UINode
      Returns the parent node of this UINode
      Overrides:
      getParent in class UINode
      Returns:
      The parent UINode
    • getRoot

      public UINode getRoot()
      Description copied from class: UINode
      Returns the root of the user interface component definition tree of this UINode
      Overrides:
      getRoot in class UINode
      Returns:
      The root UINode
    • getComponentFromRegistry

      public XlsxComponent getComponentFromRegistry(String name)
      Gets an XlsxComponent from a registry name passed by parameter.
      Parameters:
      name - The registry name that identify the XlsxComponent
      Returns:
      The XlsxComponent from a registry name passed by parameter.
    • getRegistry

      public HashGetter getRegistry()
      Gets the document's Registry.
      Returns:
      The registry of the document.
    • writeTo

      public void writeTo(WebResource out, WebResource template, String encoding)
      Creates the Excel document writing in the WebRsource Out and utilizing the Excel template from the WebRsource template.
      Parameters:
      out - Where to create the report
      template - It cannot be null
      encoding - It can be null only if the format is CP1252
    • writeTo

      public void writeTo(WebResource wr)
      Creates the Excel document writing in the WebRsource wr.
      Parameters:
      wr - Where to create the report
    • writeTo

      public void writeTo(OutputStream out, String encoding)
      Creates the Excel document writing in the OutputStream Out.
      Parameters:
      out - Where to create the report
      encoding - It can be null only if the format is CP1252
    • writeTo

      public void writeTo(OutputStream out, InputStream template, String encoding)
      Creates the Excel document writing in the WebRsource Out and utilizing the Excel template from the WebRsource template.
      Parameters:
      out - Where to create the report
      template - It cannot be null
      encoding - It can be null only if the format is CP1252
    • setSheetLabel

      public void setSheetLabel(String s)
      Sets the label to the active sheet.
      Parameters:
      s - The label to set.
    • setTitle

      public void setTitle(String s)
      Sets the titel to the active sheet.
      Parameters:
      s - The title to set.
    • setDataView

      public void setDataView(Object dbs)
      Sets the DataView into the active sheet.
      Parameters:
      dbs - The DataView to set.
    • setDataView

      public void setDataView(Object dbv, String tableName)
      Sets the DataView into a specific table in the active sheet.
      Parameters:
      dbv - The DataView to set.
      tableName - The table in which insert the Data View.