3
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

xlwingsのAPIリファレンス一覧

Last updated at Posted at 2020-01-04

xlwingsのPyton APIを一覧化してみました。公式ドキュメントの体裁を整えただけです。思ったよりも見やすくはならなかったなぁ。
~~説明部分は公式を和訳したら日本語表記にします(...そのうち)。~~この前公式を日本語化したので、そっちを見ましょう⇒Python API

Top-level functions

メンバ 説明
xlwings.view(obj, sheet=None) 新規ブックを開き、デフォルトでは最初のシートに、引数objを表示します。引数sheetにSheet オブジェクトを指定すれば、そのワークシートをクリアしてから、objを表示します。

Object model

Apps

コンストラクター

メンバ 説明
Apps(impl) A collection of all app objects:

データ アトリビュート

メンバ 説明
active Returns the active app.
count Returns the number of apps.

メソッド

メンバ 説明
add() Creates a new App. The new App becomes the active one. Returns an App object.
keys() ExcelインスタンスのPIDを返します。PIDはAppsコレクションのキーとなります。

App

コンストラクター

メンバ 説明
App(visible=None, spec=None, add_book=True, impl=None) An app corresponds to an Excel instance. 
データ アトリビュート
メンバ 説明
api Returns the native object (pywin32 or appscript obj) of the engine being used.
books A collection of all Book objects that are currently open.
calculation Returns or sets a calculation value that represents the calculation mode. Modes: 'manual', 'automatic', 'semiautomatic'
display_alerts The default value is True. Set this property to False to suppress prompts and alert messages while code is running; when a message requires a response, Excel chooses the default response.
hwnd Returns the Window handle (Windows-only).
pid Returns the PID of the app.
screen_updating Turn screen updating off to speed up your script. You won't be able to see what the script is doing, but it will run faster. Remember to set the screen_updating property back to True when your script ends.
selection Returns the selected cells as Range.
version Returns the Excel version number object.
visible Gets or sets the visibility of Excel to True or False.
メソッド
メンバ 説明
activate (steal_focus=False) Activates the Excel app.
calculate () Calculates all open books.
kill() Forces the Excel app to quit by killing its process.
macro(name) Runs a Sub or Function in Excel VBA that are not part of a specific workbook but e.g. are part of an add-in.
quit() Quits the application without saving any workbooks.
range(cell1, cell2=None) Range object from the active sheet of the active book, see Range().

Books

コンストラクター

メンバ 説明
Books(impl) A collection of all book objects:
データ アトリビュート
メンバ 説明
active Returns the active Book.
メソッド
メンバ 説明
add() Creates a new Book. The new Book becomes the active Book. Returns a Book object.
open(fullname, update_links=None, read_only=None, format=None, password=None, write_res_password=None, ignore_read_only_recommended=None, origin=None, delimiter=None, editable=None, notify=None, converter=None, add_to_mru=None, local=None, corrupt_load=None) Opens a Book if it is not open yet and returns it. If it is already open, it doesn't raise an exception but simply returns the Book object.

Book

コンストラクター

メンバ 説明
Book(fullname=None, update_links=None, read_only=None, format=None, password=None, write_res_password=None, ignore_read_only_recommended=None, origin=None, delimiter=None, editable=None, notify=None, converter=None, add_to_mru=None, local=None, corrupt_load=None, impl=None) A book object is a member of the books collection
データ アトリビュート
メンバ 説明
api Returns the native object (pywin32 or appscript obj) of the engine being used.
app Returns an app object that represents the creator of the book.
fullname Returns the name of the object, including its path on disk, as a string. Read-only String.
name Returns the name of the book as str.
names Returns a names collection that represents all the names in the specified book (including all sheet-specific names).
selection Returns the selected cells as Range.
sheets Returns a sheets collection that represents all the sheets in the book.
メソッド
メンバ 説明
activate(steal_focus=False) Activates the book.
classmethodcaller() References the calling book when the Python function is called from Excel via RunPython.
close() Closes the book without saving it.
macro(name) Runs a Sub or Function in Excel VBA.
staticopen_template() Creates a new Excel file with the xlwings VBA module already included. This method must be called from an interactive Python shell:
save(path=None) Saves the Workbook. If a path is being provided, this works like SaveAs() in Excel. 
set_mock_caller() Sets the Excel file which is used to mock xw.Book.caller() when the code is called from Python and not from Excel via RunPython.

Sheets

コンストラクター

メンバ 説明
Sheets(impl) A collection of all sheet objects:
データ アトリビュート
メンバ 説明
active Returns the active Sheet.
メソッド
メンバ 説明
add(name=None, before=None, after=None) Creates a new Sheet and makes it the active sheet.

Sheet

コンストラクター

メンバ 説明
Sheet(sheet=None, impl=None) A sheet object is a member of the sheets collection
データ アトリビュート
メンバ 説明
api Returns the native object (pywin32 or appscript obj) of the engine being used.
book Returns the Book of the specified Sheet. Read-only.
cells Returns a Range object that represents all the cells on the Sheet (not just the cells that are currently in use).
charts See Charts
index Returns the index of the Sheet (1-based as in Excel).
name Gets or sets the name of the Sheet.
names Returns a names collection that represents all the sheet-specific names (names defined with the "SheetName!" prefix).
pictures See Pictures
shapes See Shapes
used_range Used Range of Sheet.
メソッド
メンバ 説明
activate() Activates the Sheet and returns it.
autofit(axis=None) Autofits the width of either columns, rows or both on a whole Sheet.
clear() Clears the content and formatting of the whole sheet.
clear_contents() Clears the content of the whole sheet but leaves the formatting.
delete() Deletes the Sheet.
range(cell1, cell2=None) Returns a Range object from the active sheet of the active book, see Range().
select() Selects the Sheet. Select only works on the active book.

Range

コンストラクター

メンバ 説明
Range(cell1=None, cell2=None, **options) Returns a Range object that represents a cell or a range of cells.
データ アトリビュート
メンバ 説明
address Returns a string value that represents the range reference. Use get_address() to be able to provide paramaters.
api Returns the native object (pywin32 or appscript obj) of the engine being used.
color Gets and sets the background color of the specified Range.
column Returns the number of the first column in the in the specified range. Read-only.
column_width Gets or sets the width, in characters, of a Range.
columns Returns a RangeColumns object that represents the columns in the specified range.
count Returns the number of cells.
current_region This property returns a Range object representing a range bounded by (but not including) any combination of blank rows and blank columns or the edges of the worksheet. 
formula Gets or sets the formula for the given Range.
formula_array Gets or sets an array formula for the given Range.
height Returns the height, in points, of a Range. Read-only.
hyperlink Returns the hyperlink address of the specified Range (single Cell only)
last_cell Returns the bottom right cell of the specified range. Read-only.
left Returns the distance, in points, from the left edge of column A to the left edge of the range. Read-only.
name Sets or gets the name of a Range.
number_format Gets and sets the number_format of a Range.
raw_value Gets and sets the values directly as delivered from/accepted by the engine that is being used (pywin32 or appscript) without going through any of xlwings' data cleaning/converting. 
row Returns the number of the first row in the specified range. Read-only.
row_height Gets or sets the height, in points, of a Range. I
rows Returns a RangeRows object that represents the rows in the specified range.
shape Tuple of Range dimensions.
sheet Returns the Sheet object to which the Range belongs.
size Number of elements in the Range.
top Returns the distance, in points, from the top edge of row 1 to the top edge of the range. Read-only.
value Gets and sets the values for the given Range.
width Returns the width, in points, of a Range. Read-only.
メソッド
メンバ 説明
add_hyperlink(address, text_to_display=None, screen_tip=None) Adds a hyperlink to the specified Range (single Cell)
autofit() Autofits the width and height of all cells in the range.
clear() Clears the content and the formatting of a Range.
clear_contents() Clears the content of a Range but leaves the formatting.
copy(destination=None) Copy a range to a destination range or clipboard.
delete(shift=None) Deletes a cell or range of cells.
end(direction) Returns a Range object that represents the cell at the end of the region that contains the source range. 
expand(mode='table') Expands the range according to the mode provided.
get_address(row_absolute=True, column_absolute=True, include_sheetname=False, external=False) Returns the address of the range in the specified format.
insert(shift=None, copy_origin='format_from_left_or_above') Insert a cell or range of cells into the sheet.
offset(row_offset=0, column_offset=0) Returns a Range object that represents a Range that's offset from the specified range.
options(convert=None, **options) Allows you to set a converter and their options.
paste(paste=None, operation=None, skip_blanks=False, transpose=False) Pastes a range from the clipboard into the specified range.
resize(row_size=None, column_size=None) Resizes the specified Range
select() Selects the range. Select only works on the active book.

RangeRows

コンストラクター

メンバ 説明
RangeRows(rng) Represents the rows of a range. Do not construct this class directly, use Range.rows instead.
データ アトリビュート
メンバ 説明
count Returns the number of rows.
メソッド
メンバ 説明
autofit() Autofits the height of the rows.

RangeColumns

コンストラクター

メンバ 説明
RangeColumns(rng) Represents the columns of a range. Do not construct this class directly, use Range.columns instead.
データ アトリビュート
メンバ 説明
count Returns the number of columns.
メソッド
メンバ 説明
autofit() Autofits the width of the columns.

Shapes

コンストラクター

メンバ 説明
Shapes(impl) A collection of all shape objects on the specified sheet:
データ アトリビュート
メンバ 説明
api Returns the native object (pywin32 or appscript obj) of the engine being used.
count Returns the number of objects in the collection.
メソッド
メンバ 説明

Shape

コンストラクター

メンバ 説明
Shape(*args, **options) The shape object is a member of the shapes collection:
データ アトリビュート
メンバ 説明
height Returns or sets the number of points that represent the height of the shape.
left Returns or sets the number of points that represent the horizontal position of the shape.
name Returns or sets the name of the shape.
parent Returns the parent of the shape.
top Returns or sets the number of points that represent the vertical position of the shape.
type Returns the type of the shape.
width Returns or sets the number of points that represent the width of the shape.
メソッド
メンバ 説明
activate() Activates the shape.
delete() Deletes the shape.

Charts

コンストラクター

メンバ 説明
Charts(impl) A collection of all chart objects on the specified sheet
データ アトリビュート
メンバ 説明
api Returns the native object (pywin32 or appscript obj) of the engine being used.
count Returns the number of objects in the collection.
メソッド
メンバ 説明
add(left=0, top=0, width=355, height=211) Creates a new chart on the specified sheet.

Chart

コンストラクター

メンバ 説明
Chart(name_or_index=None, impl=None) The chart object is a member of the charts collection
データ アトリビュート
メンバ 説明
api Returns the native object (pywin32 or appscript obj) of the engine being used.
chart_type Returns and sets the chart type of the chart.
Deletes the chart.
height Returns or sets the number of points that represent the height of the chart.
left Returns or sets the number of points that represent the horizontal position of the chart.
name Returns or sets the name of the chart.
parent Returns the parent of the chart.
top Returns or sets the number of points that represent the vertical position of the chart.
width Returns or sets the number of points that represent the width of the chart.
delete() Deletes the chart.
set_source_data(source) Sets the source data range for the chart.

Pictures

コンストラクター

メンバ 説明
Pictures(impl) A collection of all picture objects on the specified sheet
データ アトリビュート
メンバ 説明
api Returns the native object (pywin32 or appscript obj) of the engine being used.
count Returns the number of objects in the collection.
メソッド
メンバ 説明
add(image, link_to_file=False, save_with_document=True, left=0, top=0, width=None, height=None, name=None, update=False) Adds a picture to the specified sheet.

Picture

コンストラクター

メンバ 説明
Picture(impl=None) The picture object is a member of the pictures collection
データ アトリビュート
メンバ 説明
api Returns the native object (pywin32 or appscript obj) of the engine being used.
height Returns or sets the number of points that represent the height of the picture.
left Returns or sets the number of points that represent the horizontal position of the picture.
name Returns or sets the name of the picture.
parent Returns the parent of the picture.
top Returns or sets the number of points that represent the vertical position of the picture.
width Returns or sets the number of points that represent the width of the picture.
メソッド
メンバ 説明
delete() Deletes the picture.
update(image) Replaces an existing picture with a new one, taking over the attributes of the existing picture.

Names

コンストラクター

メンバ 説明
Names(impl) A collection of all name objects in the workbook
データ アトリビュート
メンバ 説明
api Returns the native object (pywin32 or appscript obj) of the engine being used.
count Returns the number of objects in the collection.
メソッド
メンバ 説明
add(name, refers_to) Defines a new name for a range of cells.

Name

コンストラクター

メンバ 説明
Name(impl) The name object is a member of the names collection:
データ アトリビュート
メンバ 説明
api Returns the native object (pywin32 or appscript obj) of the engine being used.
name Returns or sets the name of the name object.
refers_to Returns or sets the formula that the name is defined to refer to, in A1-style notation, beginning with an equal sign.
refers_to_range Returns the Range object referred to by a Name object.
メソッド
メンバ 説明
delete() Deletes the name.

UDF decorators

メンバ 説明
xlwings.func(category="xlwings", volatile=False, call_in_wizard=True) Functions decorated with xlwings.func will be imported as Function to Excel when running "Import Python UDFs".
xlwings.sub() Functions decorated with xlwings.sub will be imported as Sub (i.e. macro) to Excel when running "Import Python UDFs".
xlwings.arg(arg, convert=None, **options) Apply converters and options to arguments, see also Range.options().
xlwings.ret(convert=None, **options) Apply converters and options to return values, see also Range.options().
3
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?