Backend & AI

What is python-docx and openpyxl (Word and Excel files)

What it is

Python libraries that build real .docx and .xlsx files with formatting, tables and sheets. People open them in the Word or Excel they know and never notice that a program made the file.

How we use it

python-docx builds documents for signature from Markdown in the accepted layout (A4, Times New Roman 12) โ€” that is how the network survey set for a museum complex is produced. openpyxl exports the electronic queue to Excel for the lecturer and the finance assistant's operations to XLSX.

Where it helps a business

  • Documents for management must be in familiar Word, in the accepted layout, and preparing them by hand takes time.
  • Lists and reports from a bot need to go out as Excel: to a lecturer, an accountant, a manager.

How we use it

  • Word from Markdown. In the network survey of a museum complex every document's source is Markdown in git, and python-docx builds the docx for signature: A4, Times New Roman 12, a 1.25 cm first-line indent. The whole set builds with one command.
  • A queue in Excel. In the electronic queue the group leader exports the list with a button, and the lecturer gets a table with the sign-up order and statuses.
  • Operations in XLSX. The finance assistant exports operations to CSV and XLSX and accepts XLSX as a fallback statement format.

Common problems

  • An edit in Word gets overwritten. If a document is built from a source, the source is what you edit: a change made in Word disappears with the next build.
  • Matching the house style. Font, margins and indents are set once in the script, so every document comes out the same.

When you do not need it

If there is one document that changes once a year, making it in Word by hand is simpler. Building from a source pays off when there are many documents or they change often.

โ† All terms

Need a website, a bot or automation?

Terms explained โ€” now let's get to work: tell us about the task and we'll turn it into a clear work plan.