openpyxl — Python Technical Interview Questions & Answers
openpyxl
openpyxl
- openpyxl is about tabular files. csv is in the stdlib. Excel usually needs openpyxl or pandas. Always with open(...) so the file closes.
- For openpyxl read: csv.reader or DictReader (column names). Write: writer / DictWriter. Don’t load a 2 GB file into memory if you can stream rows.
- openpyxl on the board: one row name,marks → Asha,90. Print it back. Same idea for Excel cells.
- openpyxl — output: Asha 90. Cell A1 is that value.
Technical Interview Tip: stdlib csv vs Excel library. One sentence + tiny row example.
Code Examples for openpyxl
Example
# openpyxl
print("Asha", 90)
# wb = Workbook(); ws['A1']='Asha'; wb.save('marks.xlsx')
openpyxl — output: Asha 90. Cell A1 is that value.
How to Explain openpyxl to an Interviewer
Explain openpyxl as if you are teaching a junior — definition, then one tiny script.
openpyxl reads or writes table files. openpyxl — with open + csv/openpyxl.
What does the example print, and why?
openpyxl — output: Asha 90
What mistake do freshers make with openpyxl?
openpyxl — DictReader uses column names.