Updated
You can use wb.app.quit()
when you want to close Excel and the associated workbook. Assume that wb
is your workbook. Keep in mind that wb.app.quit()
does’t work if you used wb.close()
before wb.app.quit()
. Here’s an example:
import xlwings as xw
path = r"test.xlsx"
wb = xw.Book(path)
wb.app.quit()
But also consider to open and close workbooks by using with xw.App() as app
(since version 0.24.3), I can only recommend it:
import xlwings as xw
with xw.App() as app:
wb = xw.Book("test.xlsx")
# Do some stuff e.g.
wb.sheets[0]["A1"].value = 12345
wb.save("test.xlsx")
wb.close()
The with
statement ensures proper acquisition and release of resources. The with
statement prevents, when an error occurs before closing Excel properly, the problem that Excel stays open and has possibly hidden excel processes left over in the background (because of xw.App(visible=False)
, if it is used). The with
statement has also the advantage that you don’t need app.quit()
anymore, because Excel closes anyway at the end of the with block. But wb.close()
at the end of the with block is usable (but not necessary) – it achieves that the next time you open Excel, Excel will not display the message that Excel has recovered data that you may want to keep (as explained here).
As a side note, I had a situation where app.quit()
did not work. In this case I used app.kill()
instead.
I need to open and close the same workbook in a python for
loop without necessarily saving the workbook. I tried the following in xlwings
:
import xlwings as xw
for i in range(5):
print(i)
book = xw.Book()
book.app.quit()
However this will only run for the first iteration. At the second iteration I get an error:
Traceback (most recent call last):
File "D:/TEMP/SE/python/ref.py", line 5, in <module>
book = xw.Book('tree_template.xlsx')
File "C:UsersaboufiraAppDataLocalContinuumminiconda3envsSElibsite-packagesxlwingsmain.py", line 533, in __init__
for wb in app.books:
File "C:UsersaboufiraAppDataLocalContinuumminiconda3envsSElibsite-packagesxlwingsmain.py", line 374, in books
return Books(impl=self.impl.books)
File "C:UsersaboufiraAppDataLocalContinuumminiconda3envsSElibsite-packagesxlwings_xlwindows.py", line 397, in books
return Books(xl=self.xl.Workbooks)
File "C:UsersaboufiraAppDataLocalContinuumminiconda3envsSElibsite-packagesxlwings_xlwindows.py", line 313, in xl
self._xl = get_xl_app_from_hwnd(self._hwnd)
File "C:UsersaboufiraAppDataLocalContinuumminiconda3envsSElibsite-packagesxlwings_xlwindows.py", line 222, in get_xl_app_from_hwnd
ptr = accessible_object_from_window(child_hwnd)
File "C:UsersaboufiraAppDataLocalContinuumminiconda3envsSElibsite-packagesxlwings_xlwindows.py", line 190, in accessible_object_from_window
res = oledll.oleacc.AccessibleObjectFromWindow(
File "_ctypes/callproc.c", line 948, in GetResult
OSError: [WinError -2147467259] Unspecified error
Why does this occur? How can I get xlwings to exit out of the application without causing any problems?
Содержание
- Python API¶
- Top-level functions¶
- Object model¶
- Books¶
- PageSetup¶
- Sheets¶
- Sheet¶
- Range¶
- RangeRows¶
- RangeColumns¶
- Shapes¶
- Shape¶
- Charts¶
- Chart¶
- Pictures¶
Python API¶
Top-level functions¶
Opens a new workbook and displays an object on its first sheet by default. If you provide a sheet object, it will clear the sheet before displaying the object on the existing sheet.
Only use this in an interactive context like e.g. a Jupyter notebook! Don’t use this in a script as it depends on the active book.
Parameters: |
|
---|
Changed in version 0.22.0.
Loads the selected cell(s) of the active workbook into a pandas DataFrame. If you select a single cell that has adjacent cells, the range is auto-expanded (via current region) and turned into a pandas DataFrame. If you don’t have pandas installed, it returns the values as nested lists.
Only use this in an interactive context like e.g. a Jupyter notebook! Don’t use this in a script as it depends on the active book.
Parameters: |
|
---|
Changed in version 0.23.1.
Object model¶
A collection of all app objects:
Returns the active app.
New in version 0.9.0.
Creates a new App. The new App becomes the active one. Returns an App object.
Returns the number of apps.
New in version 0.9.0.
Provides the PIDs of the Excel instances that act as keys in the Apps collection.
New in version 0.13.0.
An app corresponds to an Excel instance and should normally be used as context manager to make sure that everything is properly cleaned uup again and to prevent zombie processes. New Excel instances can be fired up like so:
An app object is a member of the apps collection:
Parameters: |
|
---|
Mac-only, use the full path to the Excel application, e.g. /Applications/Microsoft Office 2011/Microsoft Excel or /Applications/Microsoft Excel
On Windows, if you want to change the version of Excel that xlwings talks to, go to Control Panel > Programs and Features and Repair the Office version that you want as default.
On Mac, while xlwings allows you to run multiple instances of Excel, it’s a feature that is not officially supported by Excel for Mac: Unlike on Windows, Excel will not ask you to open a read-only version of a file if it is already open in another instance. This means that you need to watch out yourself so that the same file is not being overwritten from different instances.
Activates the Excel app.
Parameters: | steal_focus (bool, default False) – If True, make frontmost application and hand over focus from Python to Excel. |
---|
New in version 0.9.0.
Returns the native object ( pywin32 or appscript obj) of the engine being used.
New in version 0.9.0.
A collection of all Book objects that are currently open.
New in version 0.9.0.
Calculates all open books.
New in version 0.3.6.
Returns or sets a calculation value that represents the calculation mode. Modes: ‘manual’ , ‘automatic’ , ‘semiautomatic’
Changed in version 0.9.0.
This function requires xlwings PRO .
This is a convenience wrapper around mysheet.render_template
Writes the values of all key word arguments to the output file according to the template and the variables contained in there (Jinja variable syntax). Following variable types are supported:
strings, numbers, lists, simple dicts, NumPy arrays, Pandas DataFrames, pictures and Matplotlib/Plotly figures.
Parameters: |
|
---|---|
Returns: |
cut_copy_mode ¶
Gets or sets the status of the cut or copy mode. Accepts False for setting and returns None , copy or cut when getting the status.
New in version 0.24.0.
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.
New in version 0.9.0.
True if events are enabled. Read/write boolean.
New in version 0.24.4.
Returns the Window handle (Windows-only).
New in version 0.9.0.
True if Excel is in interactive mode. If you set this property to False , Excel blocks all input from the keyboard and mouse (except input to dialog boxes that are displayed by your code). Read/write Boolean. Note: Not supported on macOS.
New in version 0.24.4.
Forces the Excel app to quit by killing its process.
New in version 0.9.0.
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.
Parameters: | name (Name of Sub or Function with or without module name, e.g. ‘Module1.MyMacro’ or ‘MyMacro’ ) – |
---|
This VBA function:
can be accessed like this:
New in version 0.9.0.
Returns the PID of the app.
New in version 0.9.0.
Context manager that allows you to easily change the app’s properties temporarily. Once the code leaves the with block, the properties are changed back to their previous state. Note: Must be used as context manager or else will have no effect. Also, you can only use app properties that you can both read and write.
New in version 0.24.4.
Quits the application without saving any workbooks.
New in version 0.3.3.
Range object from the active sheet of the active book, see Range() .
New in version 0.9.0.
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.
New in version 0.3.3.
Returns the selected cells as Range.
New in version 0.9.0.
Returns the path to XLSTART which is where the xlwings add-in gets copied to by doing xlwings addin install .
New in version 0.19.4.
Gets or sets the value of the status bar. Returns False if Excel has control of it.
New in version 0.20.0.
Returns the Excel version number object.
Changed in version 0.9.0.
Gets or sets the visibility of Excel to True or False .
New in version 0.3.3.
Books¶
A collection of all book objects:
New in version 0.9.0.
Returns the active Book.
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 that has been opened.
A book object is a member of the books collection:
The easiest way to connect to a book is offered by xw.Book : it looks for the book in all app instances and returns an error, should the same book be open in multiple instances. To connect to a book in the active app instance, use xw.books and to refer to a specific app, use:
Parameters: |
|
---|---|
Returns: |
xw.Book | xw.books | |
---|---|---|
New book | xw.Book() | xw.books.add() |
Unsaved book | xw.Book(‘Book1’) | xw.books[‘Book1’] |
Book by (full)name | xw.Book(r’C:/path/to/file.xlsx’) | xw.books.open(r’C:/path/to/file.xlsx’) |
Parameters: |
|
---|
activate ( steal_focus=False ) ¶
Activates the book.
Parameters: | steal_focus (bool, default False) – If True, make frontmost window and hand over focus from Python to Excel. |
---|
api ¶
Returns the native object ( pywin32 or appscript obj) of the engine being used.
New in version 0.9.0.
Returns an app object that represents the creator of the book.
New in version 0.9.0.
References the calling book when the Python function is called from Excel via RunPython . Pack it into the function being called from Excel, e.g.:
To be able to easily invoke such code from Python for debugging, use xw.Book.set_mock_caller() .
New in version 0.3.0.
Closes the book without saving it.
New in version 0.1.1.
Returns the name of the object, including its path on disk, as a string. Read-only String.
Runs a Sub or Function in Excel VBA.
Parameters: | name (Name of Sub or Function with or without module name, e.g. ‘Module1.MyMacro’ or ‘MyMacro’ ) – |
---|
This VBA function:
can be accessed like this:
New in version 0.7.1.
Returns the name of the book as str.
Returns a names collection that represents all the names in the specified book (including all sheet-specific names).
Changed in version 0.9.0.
Saves the Workbook. If a path is being provided, this works like SaveAs() in Excel. If no path is specified and if the file hasn’t been saved previously, it’s being saved in the current working directory with the current filename. Existing files are overwritten without prompting.
Parameters: | path (str or path-like object, default None) – Full path to the workbook |
---|
New in version 0.3.1.
Returns the selected cells as Range.
New in version 0.9.0.
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 .
New in version 0.3.1.
Returns a sheets collection that represents all the sheets in the book.
New in version 0.9.0.
Exports the whole Excel workbook or a subset of the sheets to a PDF file. If you want to print hidden sheets, you will need to list them explicitely under include .
Parameters: |
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). New in version 0.24.3. Sheet names that start with this character/string will not be printed. New in version 0.24.4. Once created, open the PDF file with the default application. New in version 0.24.6. New in version 0.21.1. PageSetup¶Returns the native object ( pywin32 or appscript obj) of the engine being used. New in version 0.24.2. Gets or sets the range address that defines the print area. New in version 0.24.2. Sheets¶A collection of all sheet objects: New in version 0.9.0. Returns the active Sheet. Creates a new Sheet and makes it the active sheet.
Sheet¶A sheet object is a member of the sheets collection: Changed in version 0.9.0. Activates the Sheet and returns it. Returns the native object ( pywin32 or appscript obj) of the engine being used. New in version 0.9.0. Autofits the width of either columns, rows or both on a whole Sheet.
New in version 0.2.3. Returns the Book of the specified Sheet. Read-only. Returns a Range object that represents all the cells on the Sheet (not just the cells that are currently in use). New in version 0.9.0. New in version 0.9.0. Clears the content and formatting of the whole sheet. Clears the content of the whole sheet but leaves the formatting. Copy a sheet to the current or a new Book. By default, it places the copied sheet after all existing sheets in the current Book. Returns the copied sheet. New in version 0.22.0. Sheet object – The copied sheet Deletes the Sheet. Returns the index of the Sheet (1-based as in Excel). Gets or sets the name of the Sheet. Returns a names collection that represents all the sheet-specific names (names defined with the “SheetName!” prefix). New in version 0.9.0. Returns a PageSetup object. New in version 0.24.2. New in version 0.9.0. Returns a Range object from the active sheet of the active book, see Range() . New in version 0.9.0. This method requires 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. New in version 0.22.0.
Selects the Sheet. Select only works on the active book. New in version 0.9.0. New in version 0.9.0. New in version 0.21.0. Exports the sheet to a PDF file.
New in version 0.4.0. Returns a RangeColumns object that represents the columns in the specified range. New in version 0.9.0. Copy a range to a destination range or clipboard.
copy_picture ( appearance=’screen’, format=’picture’ ) ¶ Copies the range to the clipboard as picture.
count ¶ Returns the number of cells. 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. It corresponds to Ctrl-* on Windows and Shift-Ctrl-Space on Mac.
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. Equivalent to pressing Ctrl+Up, Ctrl+down, Ctrl+left, or Ctrl+right.
New in version 0.9.0. Expands the range according to the mode provided. Ignores empty top-left cells (unlike Range.end() ).
New in version 0.9.0. Gets or sets the formula for the given Range. Gets or sets the formula2 for the given Range. Gets or sets an array formula for the given Range. New in version 0.7.1. Returns the address of the range in the specified format. address can be used instead if none of the defaults need to be changed. New in version 0.2.3. Are we part of an Array formula? Returns the height, in points, of a Range. Read-only.
New in version 0.4.0. Returns the hyperlink address of the specified Range (single Cell only) New in version 0.3.0. Insert a cell or range of cells into the sheet.
last_cell ¶ Returns the bottom right cell of the specified range. Read-only.
New in version 0.3.5. Returns the distance, in points, from the left edge of column A to the left edge of the range. Read-only.
New in version 0.6.0. Creates a merged cell from the specified Range object.
merge_area ¶ Returns a Range object that represents the merged Range containing the specified cell. If the specified cell isn’t in a merged range, this property returns the specified cell. Returns True if the Range contains merged cells, otherwise False Sets or gets the name of a Range. New in version 0.4.0. Returns a Note object. Before the introduction of threaded comments, a Note was called a Comment. New in version 0.24.2. Gets and sets the number_format of a Range. New in version 0.2.3. Returns a Range object that represents a Range that’s offset from the specified range.
New in version 0.3.0. Allows you to set a converter and their options. Converters define how Excel Ranges and their values are being converted both during reading and writing operations. If no explicit converter is specified, the base converter is being applied, see Converters and Options . convert (object, default None) – A converter, e.g. dict , np.array , pd.DataFrame , pd.Series , defaults to default converter |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Keyword Arguments: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
=> For converter-specific options, see Converters and Options . New in version 0.7.0. Pastes a range from the clipboard into the specified 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. This can be helpful if speed is an issue but naturally will be engine specific, i.e. might remove the cross-platform compatibility. resize ( row_size=None, column_size=None ) ¶ Resizes the specified Range Range object New in version 0.3.0. Returns the number of the first row in the specified range. Read-only.
New in version 0.3.5. Gets or sets the height, in points, of a Range. If all rows in the Range have the same height, returns the height. If rows in the Range have different heights, returns None. row_height must be in the range: 0 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Returns: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Return type: | float |
New in version 0.4.0.
Returns a RangeRows object that represents the rows in the specified range.
New in version 0.9.0.
Selects the range. Select only works on the active book.
New in version 0.9.0.
Tuple of Range dimensions.
New in version 0.3.0.
Returns the Sheet object to which the Range belongs.
New in version 0.9.0.
Number of elements in the Range.
New in version 0.3.0.
Returns a Table object if the range is part of one, otherwise None .
New in version 0.21.0.
Exports the range as PNG picture.
Parameters: |
|
---|
top ¶
Returns the distance, in points, from the top edge of row 1 to the top edge of the range. Read-only.
Returns: | |
---|---|
Return type: | float |
New in version 0.6.0.
Separates a merged area into individual cells.
Gets and sets the values for the given Range. See see xlwings.Range.options() about how to set options, e.g. to transform it into a DataFrame or how to set a chunksize.
Returns: | object |
---|---|
Return type: | returned object depends on the converter being used, see xlwings.Range.options() |
width ¶
Returns the width, in points, of a Range. Read-only.
Returns: | |
---|---|
Return type: | float |
New in version 0.4.0.
Returns True if the wrap_text property is enabled and False if it’s disabled. If not all cells have the same value in a range, on Windows it returns None and on macOS False .
New in version 0.23.2.
RangeRows¶
Represents the rows of a range. Do not construct this class directly, use Range.rows instead.
Autofits the height of the rows.
Returns the number of rows.
New in version 0.9.0.
RangeColumns¶
Represents the columns of a range. Do not construct this class directly, use Range.columns instead.
Autofits the width of the columns.
Returns the number of columns.
New in version 0.9.0.
Shapes¶
A collection of all shape objects on the specified sheet:
New in version 0.9.0.
Returns the native object ( pywin32 or appscript obj) of the engine being used.
Returns the number of objects in the collection.
Shape¶
The shape object is a member of the shapes collection:
Changed in version 0.9.0.
Activates the shape.
New in version 0.5.0.
Returns the native object ( pywin32 or appscript obj) of the engine being used.
New in version 0.19.2.
Deletes the shape.
New in version 0.5.0.
Returns or sets the number of points that represent the height of the shape.
New in version 0.5.0.
Returns or sets the number of points that represent the horizontal position of the shape.
New in version 0.5.0.
Returns or sets the name of the shape.
New in version 0.5.0.
Returns the parent of the shape.
New in version 0.9.0.
New in version 0.19.2.
New in version 0.19.2.
Returns or sets the text of a shape.
New in version 0.21.4.
Returns or sets the number of points that represent the vertical position of the shape.
New in version 0.5.0.
Returns the type of the shape.
New in version 0.9.0.
Returns or sets the number of points that represent the width of the shape.
New in version 0.5.0.
Charts¶
A collection of all chart objects on the specified sheet:
New in version 0.9.0.
Creates a new chart on the specified sheet.
Returns the native object ( pywin32 or appscript obj) of the engine being used.
Returns the number of objects in the collection.
Chart¶
The chart object is a member of the charts collection:
Returns the native object ( pywin32 or appscript obj) of the engine being used.
New in version 0.9.0.
Returns and sets the chart type of the chart. The following chart types are available:
3d_area , 3d_area_stacked , 3d_area_stacked_100 , 3d_bar_clustered , 3d_bar_stacked , 3d_bar_stacked_100 , 3d_column , 3d_column_clustered , 3d_column_stacked , 3d_column_stacked_100 , 3d_line , 3d_pie , 3d_pie_exploded , area , area_stacked , area_stacked_100 , bar_clustered , bar_of_pie , bar_stacked , bar_stacked_100 , bubble , bubble_3d_effect , column_clustered , column_stacked , column_stacked_100 , combination , cone_bar_clustered , cone_bar_stacked , cone_bar_stacked_100 , cone_col , cone_col_clustered , cone_col_stacked , cone_col_stacked_100 , cylinder_bar_clustered , cylinder_bar_stacked , cylinder_bar_stacked_100 , cylinder_col , cylinder_col_clustered , cylinder_col_stacked , cylinder_col_stacked_100 , doughnut , doughnut_exploded , line , line_markers , line_markers_stacked , line_markers_stacked_100 , line_stacked , line_stacked_100 , pie , pie_exploded , pie_of_pie , pyramid_bar_clustered , pyramid_bar_stacked , pyramid_bar_stacked_100 , pyramid_col , pyramid_col_clustered , pyramid_col_stacked , pyramid_col_stacked_100 , radar , radar_filled , radar_markers , stock_hlc , stock_ohlc , stock_vhlc , stock_vohlc , surface , surface_top_view , surface_top_view_wireframe , surface_wireframe , xy_scatter , xy_scatter_lines , xy_scatter_lines_no_markers , xy_scatter_smooth , xy_scatter_smooth_no_markers
New in version 0.1.1.
Deletes the chart.
Returns or sets the number of points that represent the height of the chart.
Returns or sets the number of points that represent the horizontal position of the chart.
Returns or sets the name of the chart.
Returns the parent of the chart.
New in version 0.9.0.
Sets the source data range for the chart.
Parameters: |
|
---|---|
Returns: |
Parameters: | source (Range) – Range object, e.g. xw.books[‘Book1’].sheets[0].range(‘A1’) |
---|
to_png ( path=None ) ¶
Exports the chart as PNG picture.
Parameters: |
|
---|
top ¶
Returns or sets the number of points that represent the vertical position of the chart.
Returns or sets the number of points that represent the width of the chart.
Pictures¶
A collection of all picture objects on the specified sheet:
New in version 0.9.0.
Adds a picture to the specified sheet.
Parameters: |
The xlwings Range object of where you want to insert the picture. If you use anchor , you must not provide values for top / left . Источник Читайте также: Как настроить биос uefi на ноутбуке Adblock |
---|
I need to open and close the same workbook in a python for
loop without necessarily saving the workbook. I tried the following in xlwings
:
import xlwings as xw
for i in range(5):
print(i)
book = xw.Book()
book.app.quit()
However this will only run for the first iteration. At the second iteration I get an error:
Traceback (most recent call last):
File "D:/TEMP/SE/python/ref.py", line 5, in <module>
book = xw.Book('tree_template.xlsx')
File "C:UsersaboufiraAppDataLocalContinuumminiconda3envsSElibsite-packagesxlwingsmain.py", line 533, in __init__
for wb in app.books:
File "C:UsersaboufiraAppDataLocalContinuumminiconda3envsSElibsite-packagesxlwingsmain.py", line 374, in books
return Books(impl=self.impl.books)
File "C:UsersaboufiraAppDataLocalContinuumminiconda3envsSElibsite-packagesxlwings_xlwindows.py", line 397, in books
return Books(xl=self.xl.Workbooks)
File "C:UsersaboufiraAppDataLocalContinuumminiconda3envsSElibsite-packagesxlwings_xlwindows.py", line 313, in xl
self._xl = get_xl_app_from_hwnd(self._hwnd)
File "C:UsersaboufiraAppDataLocalContinuumminiconda3envsSElibsite-packagesxlwings_xlwindows.py", line 222, in get_xl_app_from_hwnd
ptr = accessible_object_from_window(child_hwnd)
File "C:UsersaboufiraAppDataLocalContinuumminiconda3envsSElibsite-packagesxlwings_xlwindows.py", line 190, in accessible_object_from_window
res = oledll.oleacc.AccessibleObjectFromWindow(
File "_ctypes/callproc.c", line 948, in GetResult
OSError: [WinError -2147467259] Unspecified error
Why does this occur? How can I get xlwings to exit out of the application without causing any problems?
0 / 0 / 1 Регистрация: 28.12.2016 Сообщений: 56 |
|
1 |
|
03.05.2018, 12:29. Показов 4945. Ответов 12
Здравствуйте! Работаю с файлом Excel: записываю информацию на разные листы. Затем сохраняю файл с помощью функции save() и закрываю с помощью функции close(). Файл сохраняется и закрывается, но остается открытым само приложение Excel…
0 |
1289 / 906 / 479 Регистрация: 05.12.2013 Сообщений: 3,061 |
|
03.05.2018, 12:46 |
2 |
но остается открытым само приложение Excel Не удается добиться такого поведения, Excel закрывается, приведите минимальный код который не закрывает Excel
0 |
4607 / 2028 / 359 Регистрация: 17.03.2012 Сообщений: 10,085 Записей в блоге: 6 |
|
03.05.2018, 16:20 |
3 |
xl.quit()?
0 |
daria13 0 / 0 / 1 Регистрация: 28.12.2016 Сообщений: 56 |
||||
12.05.2018, 19:58 [ТС] |
4 |
|||
минимальный код который не закрывает Excel Код:
Закрывает файл, но остается то, что на приложенной картинке. Может быть есть способ открывать файл Excel вообще в фоновом режиме?
xl.quit() он ее не понимает с такой библиотекой. Миниатюры
0 |
4607 / 2028 / 359 Регистрация: 17.03.2012 Сообщений: 10,085 Записей в блоге: 6 |
|
14.05.2018, 11:05 |
5 |
daria13, а вы точно вызываете quit у объекта-приложения, а не книги?
0 |
Garry Galler 5406 / 3830 / 1214 Регистрация: 28.10.2013 Сообщений: 9,554 Записей в блоге: 1 |
||||||||
14.05.2018, 14:04 |
6 |
|||||||
На винде нужно либо делать app.kill(), либо удалять объект приложения после quit():
Добавлено через 47 минут
не работает.
0 |
4607 / 2028 / 359 Регистрация: 17.03.2012 Сообщений: 10,085 Записей в блоге: 6 |
|
14.05.2018, 14:21 |
7 |
app.quit() Я как-то сто лет назад с подобным сталкивался. Добавлено через 2 минуты
0 |
daria13 0 / 0 / 1 Регистрация: 28.12.2016 Сообщений: 56 |
||||
24.05.2018, 11:50 [ТС] |
8 |
|||
app = xw.App(visible=False) # режим без видимого GUI У меня вообще ничего не получилось… Ни с невидимостью, ни с kill().Я так поняла, это потому что я вызываю книгу… Он говорит что для Book() он не знает App()
0 |
4607 / 2028 / 359 Регистрация: 17.03.2012 Сообщений: 10,085 Записей в блоге: 6 |
|
24.05.2018, 13:27 |
9 |
чего-чего он говорит?
0 |
0 / 0 / 1 Регистрация: 28.12.2016 Сообщений: 56 |
|
24.05.2018, 13:33 [ТС] |
10 |
чего-чего он говорит? Забыла прикрепить ошибку
0 |
4607 / 2028 / 359 Регистрация: 17.03.2012 Сообщений: 10,085 Записей в блоге: 6 |
|
24.05.2018, 14:05 |
11 |
Но я не вижу, чтобы атрибут App где-то запрашивался.
0 |
Garry Galler 5406 / 3830 / 1214 Регистрация: 28.10.2013 Сообщений: 9,554 Записей в блоге: 1 |
||||
24.05.2018, 14:09 |
12 |
|||
Сообщение было отмечено daria13 как решение Решениеdaria13,
у вас приложение сначала запустится в видимом режиме и только через 1-2 секунды станет невидимым.
1 |
0 / 0 / 1 Регистрация: 28.12.2016 Сообщений: 56 |
|
30.05.2018, 10:13 [ТС] |
13 |
Естественно, такого атрибута у книги нет Спасибо большое)
0 |