Python OpenPyxl
Python OpenPyxl
我正在处理一个大型 excel 文件(30MB+,xlsm)。很多都是在单元格评论里放照片,所以这个文件就占了这么多space。首先我打开一个文件来读取并获取特定的列名。我打开它:
self.wb = load_workbook(str(self.directory[0]), read_only=True, keep_vba=True, data_only=False)
self.ws = self.wb['BAZA_PRACOWNIKOW']
self.sheet = self.wb.active
找到合适的单元格后,我再次打开它添加相关数据:
self.wb = load_workbook(str(self.directory[0]), read_only=False, keep_vba=True, data_only=False)
self.ws = self.wb['BAZA_PRACOWNIKOW']
self.sheet = self.wb.active
当我完成这个文件时,我想保存它,所以:
self.wb.save('new.xlsm')
之后我得到一个错误:
D:\Anaconda\lib\site-packages\openpyxl\reader\worksheet.py:310:
UserWarning: Data Validation extension is not supported and will be
removed warn(msg)
The file size after saving decrease to 8mb. All photos in comments are not in new.xlsm file.
Can someone help me ?
http://openpyxl.readthedocs.io/en/latest/usage.html
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.
试试 lxlm 或 xlwings?
我正在处理一个大型 excel 文件(30MB+,xlsm)。很多都是在单元格评论里放照片,所以这个文件就占了这么多space。首先我打开一个文件来读取并获取特定的列名。我打开它:
self.wb = load_workbook(str(self.directory[0]), read_only=True, keep_vba=True, data_only=False)
self.ws = self.wb['BAZA_PRACOWNIKOW']
self.sheet = self.wb.active
找到合适的单元格后,我再次打开它添加相关数据:
self.wb = load_workbook(str(self.directory[0]), read_only=False, keep_vba=True, data_only=False)
self.ws = self.wb['BAZA_PRACOWNIKOW']
self.sheet = self.wb.active
当我完成这个文件时,我想保存它,所以:
self.wb.save('new.xlsm')
之后我得到一个错误:
D:\Anaconda\lib\site-packages\openpyxl\reader\worksheet.py:310: UserWarning: Data Validation extension is not supported and will be removed warn(msg) The file size after saving decrease to 8mb. All photos in comments are not in new.xlsm file. Can someone help me ?
http://openpyxl.readthedocs.io/en/latest/usage.html
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.
试试 lxlm 或 xlwings?