How could I retrieve
- the column names (values of the cells in the first row) in an openpyxl Read-only worksheet?
City,Population,Countryin the below example worksheet
- all column names in an openpyxl Read-only workbook?
City,Population,Country, frames from worksheet 1 and the other column names from all other worksheets
Example Excel worksheet:
| City | Population | Country |
| -----------|------------ | ------------ |
| Madison | 252,551 | USA |
| Bengaluru | 10,178,000 | India |
| ... | ... | ... |
Example code:
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)
Notes:
- I have to use readonly because the Excel file has over 1 million rows (don't ask)
- I'd like the column names so I can eventually infer the column types and import the excel data into a PostgreSQL database

所有评论(0)