Sheet

class Sheet(sheet=None, impl=None)

sheetオブジェクトは sheets コレクションのメンバーです:

>>> import xlwings as xw
>>> wb = xw.Book()
>>> wb.sheets[0]
<Sheet [Book1]Sheet1>
>>> wb.sheets['Sheet1']
<Sheet [Book1]Sheet1>
>>> wb.sheets.add()
<Sheet [Book1]Sheet2>

バージョン 0.9.0 で変更.

activate()

シートをアクティブにして返します。

property api

使用しているエンジンのネイティブ オブジェクト(pywin32 オブジェクトまたは appscript オブジェクト)を返します。

Added in version 0.9.0.

autofit(axis=None)

シート全体の列、行または両方の幅を自動調整します。

Arguments

axisstring, default None
  • 行を自動調整するには以下を指定します: rows or r

  • 列を自動調整するには以下を指定します: columns or c

  • 何も指定しなければ行と列を自動調整します

>>> import xlwings as xw
>>> wb = xw.Book()
>>> wb.sheets['Sheet1'].autofit('c')
>>> wb.sheets['Sheet1'].autofit('r')
>>> wb.sheets['Sheet1'].autofit()

Added in version 0.2.3.

property book

このシートを含むBookを返します。読み取り専用。

property cells

Sheetオブジェクト上のすべてのセルを表すRangeオブジェクトを返します(現在使っているセルではありません)。

Added in version 0.9.0.

property charts

Charts を参照

Added in version 0.9.0.

clear()

シート内のすべての値と書式をクリアーします。

clear_contents()

シート内のすべての値をクリアーしますが、書式は残します。

clear_formats()

Clears the format of the whole sheet but leaves the content.

Added in version 0.26.2.

copy(before=None, after=None, name=None)

同一ブック内または新規ブックにシートをコピーします。デフォルトでは、同一ブックの一番右側にコピーします。コピー後のシートを返します。

Added in version 0.22.0.

Arguments

beforesheet object, default None

ここで指定したシートの左にコピーします

aftersheet object, default None

ここで指定したシートの右にコピーします。

namestr, default None

コピー後のシート名

Returns

Sheet object: Sheet

The copied sheet

# Create two books and add a value to the first sheet of the first book
first_book = xw.Book()
second_book = xw.Book()
first_book.sheets[0]['A1'].value = 'some value'

# Copy to same Book with the default location and name
first_book.sheets[0].copy()

# Copy to same Book with custom sheet name
first_book.sheets[0].copy(name='copied')

# Copy to second Book requires to use before or after
first_book.sheets[0].copy(after=second_book.sheets[0])
delete()

シートを削除します。

Added in version 0.6.0.

property index

シートのインデックスを返します(Excel同様1から始まるもの)。

property name

シート名を取得または設定します。

property names

このシート内のすべての名前("SheetName!" から始まるよう定義された名前)を表すnamesコレクションを返します。

Added in version 0.9.0.

property page_setup

Returns a PageSetup object.

Added in version 0.24.2.

property pictures

Pictures を参照

Added in version 0.9.0.

range(cell1, cell2=None)

アクティブなブックのアクティブなシートからRangeオブジェクトを返します。Range() を参照。

Added in version 0.9.0.

render_template(**data)

このメソッドはxlwings PRO でのみ使用できます。

Replaces all Jinja variables (e.g {{ myvar }}) in the sheet with the keyword argument that has the same name. Following variable types are supported:

strings, numbers, lists, simple dicts, NumPy arrays, Pandas DataFrames, PIL Image objects that have a filename and Matplotlib figures.

Added in version 0.22.0.

Parameters

data: kwargs

All key/value pairs that are used in the template.

>>> import xlwings as xw
>>> book = xw.Book()
>>> book.sheets[0]['A1:A2'].value = '{{ myvar }}'
>>> book.sheets[0].render_template(myvar='test')
select()

シートを選択します。このメソッドはブックがアクティブのときのみ機能します。

Added in version 0.9.0.

property shapes

Shapes を参照

Added in version 0.9.0.

property tables

Tables を参照

Added in version 0.21.0.

to_html(path=None)

Export a Sheet as HTML page.

Parameters

pathstr or path-like, default None

Path where you want to save the HTML file. Defaults to Sheet name in the current working directory.

Added in version 0.28.1.

to_pdf(path=None, layout=None, show=False, quality='standard')

シートをPDFファイルで出力します。

Parameters

pathstr or path-like object, default None

PDFファイルのパス。デフォルトはワークブックと同じディレクトリーにシート名で保存します。未保存のワークブックの場合は、カレント ワーキング ディレトリーに保存します。

layoutstr or path-like object, default None

This argument requires xlwings PRO.

Path to a PDF file on which the report will be printed. This is ideal for headers and footers as well as borderless printing of graphics/artwork. The PDF file either needs to have only 1 page (every report page uses the same layout) or otherwise needs the same amount of pages as the report (each report page is printed on the respective page in the layout PDF).

Added in version 0.24.3.

showbool, default False

Once created, open the PDF file with the default application.

Added in version 0.24.6.

qualitystr, default 'standard'

Quality of the PDF file. Can either be 'standard' or 'minimum'.

Added in version 0.26.2.

>>> wb = xw.Book()
>>> sheet = wb.sheets[0]
>>> sheet['A1'].value = 'PDF'
>>> sheet.to_pdf()

xlwings.Book.to_pdf() を参照

Added in version 0.22.3.

property used_range

シートで使用しているRange。

Returns

xw.Range

Added in version 0.13.0.

property visible

シートの表示/非表示(bool値)を取得または設定します。

Added in version 0.21.1.