In order to use xlwings, creating a workbook object is always the first thing to do:
Workbook connects an Excel Workbook with Python. You can create a new connection from Python with
If you want to create the connection from Excel through the xlwings VBA module, use:
wb = Workbook()
Parameters: | fullname (string, default None) – If you want to connect to an existing Excel file from Python, use the fullname, e.g: r'C:\path\to\file.xlsx' |
---|
Activates the given sheet.
Parameters: | sheet (string or integer) – Sheet name or index. |
---|
Returns the currently selected Range from Excel as xlwings Range object.
Parameters: | asarray (boolean, default False) – returns a NumPy array where empty cells are shown as nan |
---|---|
Return type: | xlwings Range object |
The range method gets and sets the Range object with the following arguments:
range('A1') range('Sheet1', 'A1') range(1, 'A1')
range('A1:C3') range('Sheet1', 'A1:C3') range(1, 'A1:C3')
range((1,2)) range('Sheet1, (1,2)) range(1, (1,2))
range((1,1), (3,3)) range('Sheet1', (1,1), (3,3)) range(1, (1,1), (3,3))
range('NamedRange') range('Sheet1', 'NamedRange') range(1, 'NamedRange')
If no worksheet name is provided as first argument (as name or index), it will take the range from the active sheet.
Please check the available methods/properties directly under the Range object.
Parameters: |
|
---|---|
Returns: | xlwings Range object |
Return type: | Range |
The chart method gives access to the chart object and can be called with the following arguments:
chart(1) chart('Sheet1', 1) chart(1, 1)
chart('Chart 1') chart('Sheet1', 'Chart 1') chart(1, 'Chart 1')
If no worksheet name is provided as first argument (as name or index), it will take the Chart from the active sheet.
To insert a new Chart into Excel, create it as follows:
wb.chart().add()
Parameters: | *args – Definition of sheet (optional) and chart in the above described combinations. |
---|
Clears the content of a whole sheet but leaves the formatting.
Parameters: | sheet (string or integer, default None) – Sheet name or index. If sheet is None, the active sheet is used. |
---|
Clears the content and formatting of a whole sheet.
Parameters: | sheet (string or integer, default None) – Sheet name or index. If sheet is None, the active sheet is used. |
---|
Closes the Workbook without saving it