Class ExcelContext

java.lang.Object
java.util.AbstractMap<String,Object>
pro.verron.officestamper.excel.ExcelContext
All Implemented Interfaces:
Map<String,Object>

public final class ExcelContext extends AbstractMap<String,Object>

ExcelContext exposes a lazy, query-oriented view over an XLSX workbook.

  • Sheets are accessible by index via the sheets list, each as a SheetContext.
  • Sheets are also accessible by name at the root level, resolving to their default table (first row = headers).
  • Cells on a sheet can be queried using A1 notation via sheet.get("A1").
  • A sheet's default table is available via the special key "rows" on a SheetContext.
  • Named tables, when present, are exposed at the root level by their table name, each as a list of records mapping header names to row values.

The underlying XLSX data is accessed lazily: no pre-loading of all sheets occurs in the constructor; data is read only when a property is actually queried.

  • Method Details

    • from

      public static ExcelContext from(org.docx4j.openpackaging.packages.SpreadsheetMLPackage spreadsheet)
      Create a new context from a SpreadsheetMLPackage.
      Parameters:
      spreadsheet - SpreadsheetMLPackage to use
      Returns:
      a new ExcelContext instance
    • from

      public static ExcelContext from(Path path)
      Create a new context from a path to an .xlsx file.
      Parameters:
      path - Path to the Excel workbook file
      Returns:
      a new ExcelContext instance
      Throws:
      ExcelException - if the file cannot be read
    • from

      public static ExcelContext from(InputStream inputStream)

      Create a new context from an input stream containing an .xlsx file.

      The input stream is consumed during construction.

      Parameters:
      inputStream - Input stream of an Excel workbook
      Returns:
      a new ExcelContext instance
      Throws:
      ExcelException - if the stream cannot be parsed
    • joinAllSheets

      public List<Map<String,String>> joinAllSheets(String joinKey)
      Merges all sheets in the workbook into a single list of records using an inner join.
      Parameters:
      joinKey - the column name to join on. If null or empty, the first column of the first sheet is used.
      Returns:
      a list of joined records
    • get

      public Object get(Object key)
      Specified by:
      get in interface Map<String,Object>
      Overrides:
      get in class AbstractMap<String,Object>
    • entrySet

      public @NonNull Set<Map.Entry<String,Object>> entrySet()
      Specified by:
      entrySet in interface Map<String,Object>
      Specified by:
      entrySet in class AbstractMap<String,Object>