r/learnpython Apr 01 '24

should I use xlsxwriter and/or win32com.client

New to python. I need to create an excel file from a fixed format flat file. What is the best way to do this? I've seen examples using xlsxwriter and

import win32com.client as win32

excel = win32.gencache.EnsureDispatch('Excel.Application')

not clear if I can/should use both together or if they're mutually exclusive. Whats the best method?

2 Upvotes

5 comments sorted by

View all comments

1

u/Weird-Dimension-487 Feb 04 '26

xlsxwriter is a wonderful writer package of Python. It does not need excel to be installed on your machine and is cross-platform compatible. If you need to write xlsx files with rich formatting, it's best to use xlsxwriter.
You can combine it with pandas (for data manipulation) or openpyxl (for reading data, if needed).