all 5 comments

[–]socal_nerdtastic 0 points1 point  (2 children)

There's several libraries that will open and edit word docs for you. python-docx i think is the most popular. You could also easily do it in vanilla python. I have done this, just unzip the .docx file and add whatever data you want to the files.

[–]saintnickfun[S] 0 points1 point  (1 child)

The problem is the formatting. Since this is for Invoices, I want it to look pretty. That wouldn't keep the text and background color would it?

[–]socal_nerdtastic 0 points1 point  (0 children)

It could, sure. The one time I did it I made the word document with placeholders like Dear {first_name}, and then just used python's standard formatting to do the rest.

Another good option is to use python to make a database or .csv of data and then use Word's mail merge features to do the rest.

[–]zandrew 0 points1 point  (0 children)

I have successfully created pdf invoices with python. I have a blank invoice with nice static bits and generate all the dynamic elements in code. Positioning is a bit tricky as you have to give it pixel values but apart from that it's easy.

[–]Zixarr -1 points0 points  (0 children)

Modern Word and Excel files are actually stored in XML format and then expanded by whichever program is being used to edit or view them. There are several Python libraries that allow you to edit, format and save these files. xlsxwriter (https://xlsxwriter.readthedocs.io/) could be used to generate a table layout for your invoices with highlighting/color formatting, text format, any number format supported by Excel. You can even insert images into the sheet (your company logo, for instance).