Tables

class Tables(impl)

A collection of all table objects 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=None, name=None, source_type=None, link_source=None, has_headers=True, destination=None, table_style_name='TableStyleMedium2')

指定したシートに新しいTableを作成します。

パラメータ:
  • source (Range | None) -- データ ソースを表すxlwingsのrangeオブジェクト。

  • name (str | None) -- テーブルの名前。デフォルトはExcelが自動生成する名前。

  • source_type (str | None) -- 現在のところ、デフォルトは xlSrcRange 。つまり、xlwingsのrangeオブジェクトの使用を前提とするものです。他のオプションは使用できません。

  • link_source (bool | None) -- source_typexlSrcExternal の時に使用するものなので、現在時点では実装されていません。

  • has_headers (bool | str) -- Indicates whether the data being imported has column labels. Defaults to True. Possible values: True, False, 'guess'

  • destination (Range | None) -- source_typexlSrcExternal の時に使用するものなので、現在時点では実装されていません。

  • table_style_name (str) -- Possible strings: 'TableStyleLightN' (where N is 1-21), 'TableStyleMediumN' (where N is 1-28), 'TableStyleDarkN' (where N is 1-11)

サンプル

>>> 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>>