lxml - 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")
解决方案
推荐阅读
- swift - Swift 3:异步队列仍在阻塞主线程/冻结应用程序?
- amazon-web-services - 我可以将 AWS 用作虚拟计算机吗?
- angular - Angular Validators:我可以根据它们的验证器为表单元素添加样式吗?
- swift - Swift 4:转义闭包只能通过值显式捕获 inout 参数
- html - 我需要按中心制作“ul”(使用 Bootstrap)
- java - 计算字符串数组中的每个元素
- python - Python - 绘图模块的对象不可调用
- python - Pyplot / Matplotlib:如何实现压缩的 y 轴
- xamarin.android - 受到错误 CS0117 的困扰:“资源 *”不包含 * 的定义
- html - Bootstrap 导航栏布局错误