Table#
- class Table(*args, **options)#
tableオブジェクトは
tables
コレクションのメンバーです:>>> import xlwings as xw >>> sht = xw.books['Book1'].sheets[0] >>> sht.tables[0] # or sht.tables['TableName'] <Table 'Table 1' in <Sheet [Book1]Sheet1>>
バージョン 0.21.0 で追加.
- property api#
使用しているエンジンのネイティブ オブジェクト(
pywin32
オブジェクトまたはappscript
オブジェクト)を返します。
- property data_body_range#
ヘッダー行を除く、値のrangeを表すxlwingsのrangeオブジェクトを返します。
- property display_name#
指定したTableオブジェクトの表示名を取得または設定します。
- property header_row_range#
ヘッダーのrangeを表すxlwingsのrangeオブジェクトを返します。
- property insert_row_range#
データが挿入される行を表すxlwingsのrangeオブジェクトを返します。このメソッドはテーブルが空の場合のみ利用できます。それ以外の場合は
None
を返します。
- property name#
Tableの名前を取得または設定します。
- property parent#
tableの親オブジェクトを返します。
- property range#
tableのxlwingsのrangeオブジェクトを返します。
- resize(range)#
Resize a Table by providing an xlwings range object
バージョン 0.24.4 で追加.
- property show_autofilter#
オートフィルターのオン/オフを
True
またはFalse
で切り替える(読み取り/書き込み boolean)。
- property show_headers#
ヘッダーの表示または非表示(読み取り/書き込み)
- property show_table_style_column_stripes#
列方向ストライプのテーブル スタイルが使用されているかを取得または設定します(読み取り/書き込み boolean)。
- property show_table_style_first_column#
最初の列が書式設定されているかを取得または設定します(読み取り/書き込み boolean)。
- property show_table_style_last_column#
最後の列が書式設定されているかを取得または設定します(読み取り/書き込み boolean)。
- property show_table_style_row_stripes#
行方向ストライプのテーブル スタイルが使用されているかを取得または設定します(読み取り/書き込み boolean)。
- property show_totals#
集計行の表示/非表示のブール値を取得または設定します。
- property table_style#
テーブル スタイルを取得または設定します。設定可能な値は
Tables.add
を参照。
- property totals_row_range#
集計行を表すxlwingsのrangeオブジェクトを返します。
- update(data, index=True)#
引数dataでExcelテーブルを更新します。現在のところ、DataFrameのみ利用できます。
バージョン 0.24.0 で変更.
Arguments#
- datapandas DataFrame
Currently restricted to pandas DataFrames.
- indexbool, default True
Whether or not the index of a pandas DataFrame should be written to the Excel table.
Returns#
Table
例#
import pandas as pd import xlwings as xw sheet = xw.Book('Book1.xlsx').sheets[0] table_name = 'mytable' # Sample DataFrame nrows, ncols = 3, 3 df = pd.DataFrame(data=nrows * [ncols * ['test']], columns=['col ' + str(i) for i in range(ncols)]) # Hide the index, then insert a new table if it doesn't exist yet, # otherwise update the existing one df = df.set_index('col 0') if table_name in [table.name for table in sheet.tables]: sheet.tables[table_name].update(df) else: mytable = sheet.tables.add(source=sheet['A1'], name=table_name).update(df)