[]
        
首页
开发者学堂
文档
论坛
市场
生态机会
活动
立即试用
(Showing Draft Content)

ITableStyleCollection

Interface ITableStyleCollection


public interface ITableStyleCollection
表示工作簿中包含的表样式集合。

提供对工作簿中内置和自定义 ITableStyle 对象的访问。使用此接口可以按名称或索引检索表样式、检查样式是否存在,或通过 Workbook.getTableStyles() 添加自定义表样式。


 ITableStyleCollection tableStyles = workbook.getTableStyles();
 ITableStyle customStyle = tableStyles.add("CustomStyle");
 ITableStyle builtInStyle = tableStyles.get("TableStyleMedium3");
 
  • Method Summary

    Modifier and Type
    Method
    Description
    add(String name)
    添加具有指定名称的自定义表样式。
    boolean
    确定集合是否包含具有指定名称的表样式。
    get(int index)
    获取指定索引处的 ITableStyle。
    get(String name)
    获取具有指定名称的 ITableStyle。
    int
    获取集合中表样式的数量。
  • Method Details

    • get

      ITableStyle get(String name)
      获取具有指定名称的 ITableStyle。

      使用此方法可以从 Workbook#getTableStyles() 返回的集合中检索内置或自定义表样式。

      
       ITableStyle tableStyle = workbook.getTableStyles().get("TableStyleLight11");
       worksheet.getTables().add(worksheet.getRange("A1:B3"), true).setTableStyle(tableStyle);
       
      Parameters:
      name - 要检索的表样式名称。
      Returns:
      具有指定名称的 ITableStyle 对象。使用此方法可以从 Workbook.getTableStyles() 返回的集合中检索内置或自定义表样式。
    • get

      ITableStyle get(int index)
      获取指定索引处的 ITableStyle。

      此方法使用从零开始的位置,从 Workbook#getTableStyles() 返回的集合中检索表样式。

      
       ITableStyleCollection tableStyles = workbook.getTableStyles();
       tableStyles.add("CustomTableStyle");
       ITableStyle tableStyle = tableStyles.get(tableStyles.getCount() - 1);
       
      Parameters:
      index - 要检索的表样式的从零开始的索引。
      Returns:
      指定索引处的 ITableStyle 对象。此方法使用从零开始的位置,从 Workbook.getTableStyles() 返回的集合中检索表样式。
      Throws:
      IndexOutOfBoundsException - 如果 index 小于 0,或大于等于 #getCount()。
    • getCount

      int getCount()
      获取集合中表样式的数量。

      此计数包括工作簿的 ITableStyleCollection 中当前可用的表样式。

      
       ITableStyleCollection tableStyles = workbook.getTableStyles();
       tableStyles.add("CustomTableStyle");
       int count = tableStyles.getCount();
       
      Returns:
      集合中表样式的数量。 此计数包括工作簿的 中当前可用的表样式。
    • add

      ITableStyle add(String name)
      添加具有指定名称的自定义表样式。

      使用此方法可以在 Workbook#getTableStyles() 返回的工作簿表样式集合中创建 ITableStyle。

      
       ITableStyle tableStyle = workbook.getTableStyles().add("CustomTableStyle");
       ITableStyleElement header = tableStyle.getTableStyleElements().get(TableStyleElementType.HeaderRow);
       header.getInterior().setColor(Color.GetBlue());
       
      Parameters:
      name - 要添加的表样式名称。不得为 null。
      Returns:
      新添加的 ITableStyle 对象。
      Throws:
      IllegalArgumentException - 如果 name 为 null,或已存在同名表样式。
    • contains

      boolean contains(String name)
      确定集合是否包含具有指定名称的表样式。

      使用此方法可以检查 Workbook.getTableStyles() 返回的集合中是否有可用的内置或自定义表样式。

      
       ITableStyleCollection tableStyles = workbook.getTableStyles();
       tableStyles.add("CustomStyle");
       boolean hasCustomStyle = tableStyles.contains("CustomStyle");
       
      Parameters:
      name - 要搜索的表样式名称。
      Returns:
      如果 contains 为真,则为 true;否则为 false。