Tables¶
- class Tables(impl: Any)¶
A collection of all
tableobjects on the specified sheet:>>> import xlwings as xw >>> xw.books['Book1'].sheets[0].tables Tables([<Table 'Table1' in <Sheet [Book11]Sheet1>>, <Table 'Table2' in <Sheet [Book11]Sheet1>>])
Added in version 0.21.0.
- add(source: Range | None = None, name: str | None = None, source_type: str | None = None, link_source: bool | None = None, has_headers: bool | str = True, destination: Range | None = None, table_style_name: str = 'TableStyleMedium2') Table¶
Creates a Table to the specified sheet.
Arguments¶
- sourcexlwings range, default None
An xlwings range object, representing the data source.
- namestr, default None
The name of the Table. By default, it uses the autogenerated name that is assigned by Excel.
- source_typestr, default None
This currently defaults to
xlSrcRange, i.e. expects an xlwings range object. No other options are allowed at the moment.- link_sourcebool, default None
Currently not implemented as this is only in case
source_typeisxlSrcExternal.- has_headersbool or str, default True
Indicates whether the data being imported has column labels. Defaults to
True. Possible values:True,False,'guess'- destinationxlwings range, default None
Currently not implemented as this is used in case
source_typeisxlSrcExternal.- table_style_namestr, default ‘TableStyleMedium2’
Possible strings:
'TableStyleLightN'(where N is 1-21),'TableStyleMediumN'(where N is 1-28),'TableStyleDarkN'(where N is 1-11)
Returns¶
Table
Examples¶
>>> 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 <Sheet [Book1]Sheet1>>