Class InCellLists


  • public class InCellLists
    extends Object
    This class contains code that demonstrates how to insert plain, numbered and bulleted lists into an Excel spreadsheet cell. Look at the code contained in the demonstrateMethodCalls() method. It calls other methods that create plain, numbered and bulleted single and multi-level lists. The demonstrateMethodCalls() method appears at the top of the class definition. Though different methods are provided to construct single and multi-level plain, numbered and bulleted lists, close examination will reveal that they are not strictly necessary. If the inputs to the listInCell() and multilLevelListInCell() methods are constructed to include the bullet character or the item numbers then these methods alone may be sufficient.
    • Constructor Detail

      • InCellLists

        public InCellLists()
    • Method Detail

      • demonstrateMethodCalls

        public void demonstrateMethodCalls​(String outputFilename)
        Call each of the list creation methods.
        Parameters:
        outputFilename - A String that encapsulates the name of and path to the Excel spreadsheet file this code will create.
      • bulletedItemInCell

        public void bulletedItemInCell​(HSSFWorkbook workbook,
                                       String listItem,
                                       HSSFCell cell)
        Inserts a single bulleted item into a cell.
        Parameters:
        workbook - A reference to the HSSFWorkbook that 'contains' the cell.
        listItem - An instance of the String class encapsulating the items text.
        cell - An instance of the HSSFCell class that encapsulates a reference to the spreadsheet cell into which the list item will be written.
      • listInCell

        public void listInCell​(HSSFWorkbook workbook,
                               List<String> listItems,
                               HSSFCell cell)
        Inserts a list of plain items - that is items that are neither numbered or bulleted - into a single cell.
        Parameters:
        workbook - A reference to the HSSFWorkbook that 'contains' the cell.
        listItems - An ArrayList whose elements encapsulate the text for the list's items.
        cell - An instance of the HSSFCell class that encapsulates a reference to the spreadsheet cell into which the list will be written.
      • numberedListInCell

        public void numberedListInCell​(HSSFWorkbook workbook,
                                       List<String> listItems,
                                       HSSFCell cell,
                                       int startingValue,
                                       int increment)
        Inserts a numbered list into a single cell.
        Parameters:
        workbook - A reference to the HSSFWorkbook that 'contains' the cell.
        listItems - An ArrayList whose elements encapsulate the text for the lists items.
        cell - An instance of the HSSFCell class that encapsulates a reference to the spreadsheet cell into which the list will be written.
        startingValue - A primitive int containing the number for the first item in the list.
        increment - A primitive int containing the value that should be used to calculate subsequent item numbers.
      • bulletedListInCell

        public void bulletedListInCell​(HSSFWorkbook workbook,
                                       List<String> listItems,
                                       HSSFCell cell)
        Insert a bulleted list into a cell.
        Parameters:
        workbook - A reference to the HSSFWorkbook that 'contains' the cell.
        listItems - An ArrayList whose elements encapsulate the text for the lists items.
        cell - An instance of the HSSFCell class that encapsulates a reference to the spreadsheet cell into which the list will be written.
      • multiLevelListInCell

        public void multiLevelListInCell​(HSSFWorkbook workbook,
                                         List<InCellLists.MultiLevelListItem> multiLevelListItems,
                                         HSSFCell cell)
        Insert a multi-level list into a cell.
        Parameters:
        workbook - A reference to the HSSFWorkbook that 'contains' the cell.
        multiLevelListItems - An ArrayList whose elements contain instances of the MultiLevelListItem class. Each element encapsulates the text for the high level item along with an ArrayList. Each element of this ArrayList encapsulates the text for a lower level item.
        cell - An instance of the HSSFCell class that encapsulates a reference to the spreadsheet cell into which the list will be written.
      • multiLevelNumberedListInCell

        public void multiLevelNumberedListInCell​(HSSFWorkbook workbook,
                                                 List<InCellLists.MultiLevelListItem> multiLevelListItems,
                                                 HSSFCell cell,
                                                 int highLevelStartingValue,
                                                 int highLevelIncrement,
                                                 int lowLevelStartingValue,
                                                 int lowLevelIncrement)
        Insert a multi-level list into a cell.
        Parameters:
        workbook - A reference to the HSSFWorkbook that 'contains' the cell.
        multiLevelListItems - An ArrayList whose elements contain instances of the MultiLevelListItem class. Each element encapsulates the text for the high level item along with an ArrayList. Each element of this ArrayList encapsulates the text for a lower level item.
        cell - An instance of the HSSFCell class that encapsulates a reference to the spreadsheet cell into which the list will be written.
        highLevelStartingValue - A primitive int containing the number for the first high level item in the list.
        highLevelIncrement - A primitive int containing the value that should be used to calculate the number of subsequent high level item.
        lowLevelStartingValue - A primitive int will containing the number for the first low level item associated with a high level item.
        lowLevelIncrement - A primitive int containing the value that should be used to calculate the number of subsequent low level item.
      • multiLevelBulletedListInCell

        public void multiLevelBulletedListInCell​(HSSFWorkbook workbook,
                                                 List<InCellLists.MultiLevelListItem> multiLevelListItems,
                                                 HSSFCell cell)
        Insert a bulleted multi-level list into a cell.
        Parameters:
        workbook - A reference to the HSSFWorkbook that 'contains' the cell.
        multiLevelListItems - An ArrayList whose elements contain instances of the MultiLevelListItem class. Each element encapsulates the text for the high level item along with an ArrayList. Each element of this ArrayList encapsulates the text for a lower level item.
        cell - An instance of the HSSFCell class that encapsulates a reference to the spreadsheet cell into which the list will be written.
      • main

        public static void main​(String[] args)
                         throws IOException
        The main entry point to the program. Demonstrates how to call the method that will create an Excel workbook containing many different sorts of lists.
        Parameters:
        args - the command line arguments.
        Throws:
        IOException