简体   繁体   中英

Is there a way of editing xlsx workbooks containing images in Python?

Is there a way to edit and save xlsx-workbooks that contain images, charts, figures etc. through Python?

A few things I've tried:

  • openpyxl :

    openpyxl does currently not read all possible items in an Excel file so images and charts will be lost from existing files if they are opened and saved with the same name.

  • xlwt :

    xlwt is a library for writing data and formatting information to older Excel files (ie: .xls)

  • xlutils :

    Utilities for working with Excel files that require both xlrd and xlwt

Related.

The XLWings module seems to be the only module that supports this: http://docs.xlwings.org/en/stable/quickstart.html . Unlike other Python / Excel modules it seems to use COM automation under the hood to connect to Excel.

import xlwings as xw
wb = xw.Book()  # this will create a new workbook
wb = xw.Book('FileName.xlsx')  # connect to an existing file in the current working directory
wb = xw.Book(r'C:\path\to\file.xlsx')  # on Windows: use raw strings to escape backslashes
app = xw.App()  # or something like xw.apps[0] for existing apps
wb = app.books['Book1']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM