【发布时间】:2019-01-29 05:59:19
【问题描述】:
我怎样才能找回来
- openpyxl Read-only 工作表中的列名(第一行单元格的值)?
-
以下示例工作表中的
City、Population、Country
-
以下示例工作表中的
- openpyxl 只读工作簿中的所有列名?
-
City、Population、Country、工作表 1 中的框架和所有其他工作表中的其他列名称
-
Excel 工作表示例:
| City | Population | Country |
| -----------|------------ | ------------ |
| Madison | 252,551 | USA |
| Bengaluru | 10,178,000 | India |
| ... | ... | ... |
示例代码:
from openpyxl import load_workbook
wb = load_workbook(filename=large_file.xlsx, read_only=True)
sheet = wb.worksheets[0]
... (not sure where to go from here)
注意事项:
- 我必须使用只读,因为 Excel 文件有超过 100 万行(不要问)
- 我想要列名,以便最终推断列类型并将 Excel 数据导入 PostgreSQL 数据库
【问题讨论】:
-
您对“标题”一词的使用含糊不清。
-
好点,编辑了问题。
-
你还在谈论 print_titles 是不同的东西。页眉和页脚也是如此。
-
再次编辑问题。
-
那么,现在的问题是什么?
[c.value for c in ws.iter_rows(min_row=1, max_row=1)]不够?