[]
        
(Showing Draft Content)

ITableColumns

Interface ITableColumns


public interface ITableColumns
Represents a collection of all ITableColumn objects in a specified ITable.

Each ITableColumn in the collection represents a column in the table. Use this interface to access table columns by index or name, and to work with the complete set of columns in a table.


 worksheet.getRange("A1:B3").setValue(new Object[][] {
     {"Name", "Value"},
     {"A", 100},
     {"B", 200}
 });
 ITable table = worksheet.getTables().add(worksheet.getRange("A1:B3"), true);
 ITableColumns columns = table.getColumns();
 ITableColumn column = columns.get(0);
 
  • Method Summary

    Modifier and Type
    Method
    Description
    add()
    Adds a new column to the end of the table and returns the created ITableColumn.
    add(int position)
    Adds a new column to the table at the specified relative position.
    void
    add(int position, int count)
    Adds one or more columns to the table at the specified relative position.
    void
    delete(int position, int count)
    Deletes one or more columns from the table.
    get(int index)
    Gets the ITableColumn at the specified index.
    get(String name)
    Gets the ITableColumn that corresponds to the specified column name.
    int
    Gets the number of ITableColumn objects in the collection.
  • Method Details

    • getCount

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

      Use this method to determine how many columns are currently defined in a table.

      
       worksheet.getRange("A1:C3").setValue(new Object[][] {
           {"Product", "Q1", "Q2"},
           {"Apple", 100, 120},
           {"Pear", 80, 95}
       });
       ITable table = worksheet.getTables().add(worksheet.getRange("A1:C3"), true);
       int count = table.getColumns().getCount();
       
      Returns:
      The number of ITableColumn objects in the collection.
    • get

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

      Use a zero-based index to retrieve a column from the table's column collection.

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

      ITableColumn get(String name)
      Gets the ITableColumn that corresponds to the specified column name.
      
       worksheet.getRange("A1:B3").setValue(new Object[][] {
           {"Product", "Amount"},
           {"Apple", 100},
           {"Pear", 200}
       });
       ITable table = worksheet.getTables().add(worksheet.getRange("A1:B3"), true);
       ITableColumn column = table.getColumns().get("Amount");
       
      Parameters:
      name - The column name.
      Returns:
      The ITableColumn object that corresponds to the specified column name.
    • add

      Adds a new column to the end of the table and returns the created ITableColumn.
      
       worksheet.getRange("A1:B3").setValue(new Object[][] {
           {"Name", "Score"},
           {"Alice", 90},
           {"Bob", 85}
       });
       ITable table = worksheet.getTables().add(worksheet.getRange("A1:B3"), true);
       ITableColumn column = table.getColumns().add();
       column.setName("Region");
       
      Returns:
      The created ITableColumn.
    • add

      ITableColumn add(int position)
      Adds a new column to the table at the specified relative position.

      The position is zero-based. The existing column at the specified position is shifted outward.

      
       worksheet.getRange("A1:B3").setValue(new Object[][] {
           {"Name", "Score"},
           {"Alice", 90},
           {"Bob", 85}
       });
       ITable table = worksheet.getTables().add(worksheet.getRange("A1:B3"), true);
       ITableColumn column = table.getColumns().add(1);
       
      Parameters:
      position - The zero-based relative position of the new column. The existing column at this position is shifted outward.
      Returns:
      The result.
    • add

      void add(int position, int count)
      Adds one or more columns to the table at the specified relative position.

      The position is zero-based. Existing columns at the specified position are shifted outward to make room for the new columns.

      
       worksheet.getRange("A1:B3").setValue(new Object[][] {
           {"Name", "Score"},
           {"Alice", 90},
           {"Bob", 85}
       });
       ITable table = worksheet.getTables().add(worksheet.getRange("A1:B3"), true);
       table.getColumns().add(1, 2);
       
      Parameters:
      position - The zero-based relative position at which to add the new column(s). Existing columns at this position are shifted outward.
      count - The number of columns to add.
    • delete

      void delete(int position, int count)
      Deletes one or more columns from the table.

      The position parameter is zero-based and is relative to the table. If count exceeds the number of columns available from position, only the remaining columns are deleted.

      
       worksheet.getRange("A1:C3").setValue(new Object[][] {
           {"Name", "Q1", "Q2"},
           {"Alice", 100, 120},
           {"Bob", 90, 110}
       });
       ITable table = worksheet.getTables().add(worksheet.getRange("A1:C3"), true);
       table.getColumns().delete(1, 1);
       
      Parameters:
      position - The zero-based relative position of the first column to delete.
      count - The number of columns to delete.