# Tables

### *class* Tables

A collection of all `table` objects on the specified sheet:

```pycon
>>> import xlwings as xw
>>> xw.books['Book1'].sheets[0].tables
Tables([<Table 'Table1' in Sheet1>,
        <Table 'Table2' in Sheet1>])
```

#### Versionadded
在 0.21.0 版本加入.

#### add(source=None, name=None, source_type=None, link_source=None, has_headers=True, destination=None, table_style_name='TableStyleMedium2')

Creates a Table to the specified sheet.

* **参数:**
  * **source** ([*Range*](range.md#xlwings.Range) *|* *None*) -- An xlwings range object, representing the data source.
  * **name** (*str* *|* *None*) -- The name of the Table. By default, it uses the autogenerated name that is
    assigned by Excel.
  * **source_type** (*str* *|* *None*) -- This currently defaults to `xlSrcRange`, i.e. expects an xlwings range
    object. No other options are allowed at the moment.
  * **link_source** (*bool* *|* *None*) -- Currently not implemented as this is only in case `source_type` is
    `xlSrcExternal`.
  * **has_headers** (*bool*) -- Whether the source range has column labels. Defaults to `True`. When `False`, Excel generates headers above the source data.
  * **destination** ([*Range*](range.md#xlwings.Range) *|* *None*) -- Currently not implemented as this is used in case `source_type` is
    `xlSrcExternal`.
  * **table_style_name** (*str*) -- Possible strings: `'TableStyleLightN'` (where N is 1-21),
    `'TableStyleMediumN'` (where N is 1-28),
    `'TableStyleDarkN'` (where N is 1-11)
* **返回类型:**
  [*Table*](table.md#xlwings.main.Table)

### 示例

```pycon
>>> import xlwings as xw
>>> sheet = xw.Book().sheets[0]
>>> sheet['A1'].value = [['a', 'b'], [1, 2]]
>>> table = sheet.tables.add(source=sheet['A1'].expand(), name='MyTable')
>>> table
<Table 'MyTable' in Sheet1>
```

#### *property* api *: Any*

Returns the native object (`pywin32` or `appscript` obj)
of the engine being used.

#### *property* count *: int*

返回集合中的对象数。
