不知名的天某人 2019-12-24 09:24 采纳率: 0%
浏览 1322
已采纳

openpyxl 生产xlsx文件报错

python 3.6 openpyxl 3.0.2

from openpyxl import Workbook
from openpyxl.utils import get_column_letter

wb = Workbook()

dest_filename = 'empty_book.xlsx'

ws1 = wb.active
ws1.title = "range names"

for row in range(1, 40):
    ws1.append(range(600))
    ws2 = wb.create_sheet(title="Pi")
    ws2['F5'] = 3.14

ws3 = wb.create_sheet(title="Data")
for row in range(10, 20):
    for col in range(27, 54):
         _ = ws3.cell(column=col, row=row, value="{0}".format(get_column_letter(col)))
print(ws3['AA10'].value)

wb.save(filename = dest_filename)

Traceback (most recent call last):

File "C:/Users/Administrator/Desktop/python 报价单生成脚本/111.py", line 36, in

wb.save(filename = dest_filename)

File "D:\Anaconda3\lib\site-packages\openpyxl\workbook\workbook.py", line 408, 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 354, in write

self.write_top()

File "D:\Anaconda3\lib\site-packages\openpyxl\worksheet_writer.py", line 98, in write_top

self.write_properties()

File "D:\Anaconda3\lib\site-packages\openpyxl\worksheet_writer.py", line 60, in write_properties

self.xf.send(props.to_tree())

File "D:\Anaconda3\lib\site-packages\openpyxl\worksheet_writer.py", line 294, in get_stream

xf.write(el)

File "src/lxml/serializer.pxi", line 1230, in lxml.etree._IncrementalFileWriter.write
TypeError: got invalid input value of type , expected string or Element

  • 写回答

2条回答 默认 最新

  • kedoneyes 2020-03-31 17:25
    关注

    安装3.03,解决问题

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 已采纳回答 7月27日

悬赏问题

  • ¥15 ansys fluent计算闪退
  • ¥15 有关wireshark抓包的问题
  • ¥15 Ubuntu20.04无法连接GitHub
  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
  • ¥15 向数据表用newid方式插入GUID问题
  • ¥15 multisim电路设计
  • ¥20 用keil,写代码解决两个问题,用库函数
  • ¥50 ID中开关量采样信号通道、以及程序流程的设计
  • ¥15 U-Mamba/nnunetv2固定随机数种子
  • ¥30 C++行情软件的tick数据如何高效的合成K线