?原因:
设置行高、列宽的命令分别是:
row =ws.row_dimensions[1]
row.height = 15
col = ws.column_dimensions['E']
col.width = 10
这里特别要注意row_dimensions[1]中,方括号里的数字代表行序号,是个数字,没有引号
而column_dimensions['e']中,方括号里的字母是列序号,是有引号的,如果忘了,把行高参数中的数字加了引号写成row_dimensions[‘1’],就会产生下面的错误,文件保存失败。
File "D:\anaconda3\Lib\site-packages\openpyxl\workbook\workbook.py", line 407, in save ? ? save_workbook(self, filename) ? File "D:\anaconda3\Lib\site-packages\openpyxl\writer\excel.py", line 293, in save_workbook ? ? writer.save() ? File "D:\anaconda3\Lib\site-packages\openpyxl\writer\excel.py", line 275, in save ? ? self.write_data() ? File "D:\anaconda3\Lib\site-packages\openpyxl\writer\excel.py", line 75, in write_data ? ? self._write_worksheets() ? File "D:\anaconda3\Lib\site-packages\openpyxl\writer\excel.py", line 215, in _write_worksheets ? ? self.write_worksheet(ws) ? File "D:\anaconda3\Lib\site-packages\openpyxl\writer\excel.py", line 200, in write_worksheet ? ? writer.write() ? File "D:\anaconda3\Lib\site-packages\openpyxl\worksheet\_writer.py", line 359, in write ? ? self.write_rows() ? File "D:\anaconda3\Lib\site-packages\openpyxl\worksheet\_writer.py", line 124, in write_rows ? ? for row_idx, row in self.rows(): ? File "D:\anaconda3\Lib\site-packages\openpyxl\worksheet\_writer.py", line 117, in rows ? ? return sorted(rows.items()) TypeError: '<' not supported between instances of 'str' and 'int' Error in atexit._run_exitfuncs: Traceback (most recent call last): ? File "D:\anaconda3\Lib\site-packages\openpyxl\worksheet\_writer.py", line 32, in _openpyxl_shutdown ? ? os.remove(path) PermissionError: [WinError 32] 另一个程序正在使用此文件,进程无法访问。
|