How could I retrieve
- the column names (values of the cells in the first row) in an openpyxl Read-only worksheet?
City
,Population
,Country
in 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
[c.value for c in ws.iter_rows(min_row=1, max_row=1)]
not sufficient? – Candideprint([c.value for c in ws.iter_rows(min_row=1, max_row=1)])
gave meAttributeError: 'tuple' object has no attribute 'value
– Lewes[c.value for c in next(ws.iter_rows(min_row=1, max_row=1))]
– Candide