[]
        
(Showing Draft Content)

ITables

Interface ITables

All Superinterfaces:
Iterable<ITable>

public interface ITables extends Iterable<ITable>
Represents the collection of all ITable objects in a worksheet.

Each ITable object represents a table in the worksheet. Use this interface to access existing tables, add new tables, and enumerate the tables returned by IWorksheet.getTables().


 worksheet.getRange("A1:B3").setValue(new Object[][] {
     {"Name", "Value"},
     {"Test", 100}
 });
 ITables tables = worksheet.getTables();
 ITable table = tables.add(worksheet.getRange("A1:B3"), true);
 
  • Method Summary

    Modifier and Type
    Method
    Description
    add(IRange range)
    Creates a table that includes the specified range of cells.
    add(IRange range, boolean containsHeader)
    Creates a table that includes the specified range of cells.
    void
    Loads the table collection from the specified JSON string.
    get(int index)
    Gets the ITable at the specified index.
    get(String name)
    Gets the ITable with the specified name.
    int
    Gets the number of ITable objects in this collection.
    Generates a JSON string from the tables in the worksheet.

    Methods inherited from interface java.lang.Iterable

    forEach, iterator, spliterator
  • Method Details

    • get

      ITable get(String name)
      Gets the ITable with the specified name.

      Use this method to retrieve an existing table from the collection returned by IWorksheet.getTables().

      
       IRange range = worksheet.getRange("A1:B3");
       range.setValue(new Object[][] {
           {"Product", "Amount"},
           {"Apple", 10},
           {"Pear", 20}
       });
       ITable table = worksheet.getTables().add(range, true);
       table.setName("SalesTable");
       ITable namedTable = worksheet.getTables().get("SalesTable");
       
      Parameters:
      name - The name of the ITable to retrieve.
      Returns:
      The ITable object with the specified name.
    • get

      ITable get(int index)
      Gets the ITable at the specified index.

      Use this method to retrieve an existing table from the collection returned by IWorksheet.getTables().

      
       IRange range = worksheet.getRange("A1:B3");
       range.setValue(new Object[][] {
           {"Name", "Value"},
           {"Apple", 100},
           {"Pear", 200}
       });
       worksheet.getTables().add(range, true);
       ITable table = worksheet.getTables().get(0);
       
      Parameters:
      index - The zero-based index of the table to retrieve.
      Returns:
      The ITable object at the specified index.
    • getCount

      int getCount()
      Gets the number of ITable objects in this collection.

      Use this method to get the number of tables defined on the worksheet.

      
       worksheet.getRange("A1:B3").setValue(new Object[][] {
           {"Name", "Value"},
           {"A", 100},
           {"B", 200}
       });
       ITables tables = worksheet.getTables();
       tables.add(worksheet.getRange("A1:B3"), true);
       int count = tables.getCount();
       
      Returns:
      The number of ITable objects in this collection.
    • add

      ITable add(IRange range)
      Creates a table that includes the specified range of cells.

      Use this method to create a table from an existing worksheet range and add it to the collection returned by IWorksheet.getTables().

      
       worksheet.getRange("A1:B3").setValue(new Object[][] {
           {"Product", "Amount"},
           {"Apple", 100},
           {"Orange", 200}
       });
       ITable table = worksheet.getTables().add(worksheet.getRange("A1:B3"));
       
      Parameters:
      range - The cell range to include in the table; must not be null.
      Returns:
      The newly created ITable object.
    • add

      ITable add(IRange range, boolean containsHeader)
      Creates a table that includes the specified range of cells.

      Use this method to convert a worksheet range into a table. Set containsHeader to true when the first row in the range should be used as the table header row.

      
       IRange range = worksheet.getRange("A1:B3");
       range.setValue(new Object[][] {
           {"Name", "Value"},
           {"Apple", 100},
           {"Pear", 200}
       });
       ITable table = worksheet.getTables().add(range, true);
       
      Parameters:
      range - The cell range to include in the table; must not be null.
      containsHeader - true if the first row of the range contains header cells; otherwise, false.
      Returns:
      The newly created ITable object.
      Throws:
      IllegalArgumentException - if range is null.
    • fromJson

      void fromJson(String json)
      Loads the table collection from the specified JSON string.
      
       worksheet.getRange("A1:B3").setValue(new Object[][] {{"Name", "Value"}, {"A", 100}, {"B", 200}});
       ITables tables = worksheet.getTables();
       tables.add(worksheet.getRange("A1:B3"), true);
       String json = tables.toJson();
       tables.fromJson(json);
       
      Parameters:
      json - The JSON string used to load the table collection.
    • toJson

      String toJson()
      Generates a JSON string from the tables in the worksheet.
      
       worksheet.getRange("A1:B3").setValue(new Object[][] {{"Name", "Value"}, {"A", 100}, {"B", 200}});
       ITables tables = worksheet.getTables();
       tables.add(worksheet.getRange("A1:B3"), true);
       String json = tables.toJson();
       
      Returns:
      The JSON string generated from the tables in the worksheet.