Class SpreadSheetHelper

  • Direct Known Subclasses:
    DatasetUtils

    public class SpreadSheetHelper
    extends SpreadSheetUtils
    A helper class for spreadsheet operations.
    Version:
    $Revision$
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    • Constructor Detail

      • SpreadSheetHelper

        public SpreadSheetHelper()
    • Method Detail

      • append

        public static SpreadSheet append​(SpreadSheet first,
                                         SpreadSheet second,
                                         boolean noCopy)
        Appends two spreadsheets.
        Parameters:
        first - the first spreadsheet
        second - the second spreadsheet
        noCopy - whether to work with a copy of the first spreadsheet rather than appending the second one directly to it
        Returns:
        the combined spreadsheet
      • compareCells

        protected static String compareCells​(Cell first,
                                             Cell second)
        Compares the two cells.
        Parameters:
        first - the first cell
        second - the second cell
        Returns:
        null if the same, otherwise message on difference
      • compare

        public static String compare​(SpreadSheet first,
                                     SpreadSheet second)
        Compares two spreadsheets.
        Parameters:
        first - the first spreadsheet
        second - the second spreadsheet
        Returns:
        null if the same, otherwise message indicating (first) difference
      • mapToSpreadSheet

        public static SpreadSheet mapToSpreadSheet​(Map map,
                                                   String[] header)
        Turns the map into a spreadsheet.
        Parameters:
        map - the map to convert
        header - the header names, use null for default
        Returns:
        the generated spreadsheet
      • convertToNumeric

        public static SpreadSheet convertToNumeric​(SpreadSheet sheet,
                                                   Map<Integer,​Map<String,​Integer>> mappings,
                                                   Double missing,
                                                   double unhandled)
        Turns non-numeric cells into numeric ones. Missing cells can get skipped. Booleans gets turned into 0/1 (false/true). Date/time types get turned into numeric ones by using their Java epoch. Strings (per column) get a 0-based index assigned in the order they appear. Any other cell type get flagged as missing or, if provided, set to the unhandled value.
        Parameters:
        sheet - the spreadsheet to convert
        mappings - the mappings (empty or already filled from previous run): col-index - (string - integer)
        missing - the value to replace missing values with, null if to keep missing cells
        unhandled - the value to use for replacing unhandled cell types
        Returns:
        the converted spreadsheet (copy)