python - 以电子表格格式转换 python 输出
问题描述
在这里,我需要从用户那里获取两个值并将该输出保存为电子表格格式。我的代码的 mcve 是:
while True:
a=input('enter the string')
print(a)
b=input('enter the number')
print(b)
示例输出为:
enter the stringa
a
enter the number2
2
enter the stringb
b
enter the number4
4
enter the string
我需要将每个整数值分配给电子表格中的相应字符串
解决方案
尝试使用 openpyxl 将输出保存在 excel 表中
from openpyxl import Workbook
book = Workbook()
sheet = book.active
a = input('enter the string')
print(a)
b = input('enter the number')
print(b)
sheet['A1'] = a
sheet['B1'] = b
book.save("test.xlsx")
推荐阅读
- tableau-api - 获取表格中链接字段的完整日期范围
- java - 如何在redhat服务中运行一个由python包装的java程序
- javascript - 如何更新“componentDidUpdate”中的 React 元素?
- javascript - 如何分配数组中的所有对象?
- git - 尝试从 git 历史记录中删除大文件时,refs/heads/master 未更改
- compatibility - 如何在 avro 模式中向嵌套映射添加新类型时保持 FULL_TRANSITIVE 兼容性?
- bash - 创建函数来执行显示时间算术
- html - 限制引导页面的总宽度?
- mysql - 当 LIKE 条件包含多个非通配符时,准备查询无法返回结果
- python - Tensorflow CUDA - CUPTI 错误:无法加载 CUPTI 或找不到符号