首页 > 解决方案 > openpyxl 无法处理写入 lxml.etree._ElementUnicodeResult

问题描述

该脚本仅用于演示目的,通常在解析一些数据时会给出 lxml.etree._ElementUnicodeResult 类型。由于某种原因,无法使用 openpyxl 将这种类型的字符串写入 Excel。这是这种类型的字符串的某种错误或预期行为吗?

from openpyxl import Workbook
import lxml

string_to_write = lxml.etree._ElementUnicodeResult("just a string")

outfile = Workbook()
ws = outfile["Sheet"]

ws.cell(row=1, column=1).value = "just a string"
ws.cell(row=1, column=2).value = string_to_write

outfile.save("output.xlsx")

标签: lxmlopenpyxl

解决方案


推荐阅读