Class Spreadsheet

java.lang.Object
com.adobe.acs.commons.data.Spreadsheet

@ProviderType public class Spreadsheet extends Object
Simple abstraction of reading a single spreadsheet of values. Expects a header row of named columns (case-sensitive) If provided, will also filter data rows missing required columns to prevent processing errors.
  • Field Details

  • Constructor Details

    • Spreadsheet

      public Spreadsheet(boolean convertHeaderNames, String... headerArray)
      Simple constructor used for unit testing purposes
      Parameters:
      convertHeaderNames - If true, header names are converted
      headerArray - List of strings for header columns
    • Spreadsheet

      public Spreadsheet(boolean convertHeaderNames, List<String> caseInsensitiveHeaders, String... headerArray)
      Simple constructor used for unit testing purposes
      Parameters:
      convertHeaderNames - If true, header names are converted
      caseInsensitiveHeaders - Header names that will be ignored during conversion
      headerArray - List of strings for header columns
    • Spreadsheet

      public Spreadsheet(boolean convertHeaderNames, InputStream file, String... required)
    • Spreadsheet

      public Spreadsheet(boolean convertHeaderNames, org.apache.sling.api.request.RequestParameter file, String... required) throws IOException
      Throws:
      IOException
    • Spreadsheet

      public Spreadsheet(InputStream file, String... required)
    • Spreadsheet

      public Spreadsheet(org.apache.sling.api.request.RequestParameter file, String... required) throws IOException
      Throws:
      IOException
    • Spreadsheet

      public Spreadsheet(org.apache.sling.api.request.RequestParameter file, List<String> caseInsensitiveHeaders, String... required) throws IOException
      Throws:
      IOException
  • Method Details

    • buildSpreadsheet

      public Spreadsheet buildSpreadsheet() throws IOException
      Parse out the input file synchronously for easier unit test validation. This overload will implicitly use the default JVM locale for numeric and date/time conversions.
      Returns:
      List of files that will be imported, including any renditions
      Throws:
      IOException - if the file couldn't be read
    • buildSpreadsheet

      public Spreadsheet buildSpreadsheet(Locale locale) throws IOException
      Parse out the input file synchronously for easier unit test validation
      Parameters:
      locale - The locale to be used for numeric and date/time conversions.
      Returns:
      List of files that will be imported, including any renditions
      Throws:
      IOException - if the file couldn't be read
    • getFileName

      public String getFileName()
      Returns:
      the fileName
    • getRowCount

      public int getRowCount()
      Returns:
      the rowCount
    • getHeaderRow

      public List<String> getHeaderRow()
      Returns:
      the headerRow
    • getDataRowsAsCompositeVariants

      public List<Map<String,CompositeVariant>> getDataRowsAsCompositeVariants()
      Returns:
      the dataRows
    • sortRows

      public void sortRows(String columnName)
      Sort the data rows by the provided column name
    • appendData

      public void appendData(List<Map<String,CompositeVariant>> dataRows)
      Append data to the sheet.
      Parameters:
      dataRows - the data to append
    • getRowNum

      public Long getRowNum(Map<String,CompositeVariant> row)
    • getRequiredColumns

      public List<String> getRequiredColumns()
      Returns:
      the requiredColumns
    • convertHeaderName

      public String convertHeaderName(String str)