Automatically generate filled-in reports in PDF with data from MSSQL Server using Mail Merge & Python
- python 3.9
- poetry ^1.1 (
pip install poetry
) Documentation - MSSQL Server ODBC 17 on macOS, Linux, Windows
- MS Word
cd [path-of-the-repository-root-directory]
poetry env use [path-of-python3.9-executable-file]
poetry install
poetry run python src/gen-report.py \
--host [database host server]\
--db [database name]\
--username [username]\
--password [password]\
--query [SQL Query]\
--template [template filename.docx]\
--output [filename without extension, see remark 3]\
--pdf_password [password for the generated pdf file]
cd [path-of-the-repository-root-directory]
[path-of-python3.9-executable-file] -m pip install -r requirements.txt
[path-of-python3.9-executable-file] python src/gen-report.py
[argument the same as using Peotry]
- Please replace contents between
[...]
appropriately. - If you are using windows, please use
"
instead of'
to quote arguments. - The argument for
--output
will be parsed to python functionstrftime
, which allow user to timestamp, e.g.%H:%M:%S
, in the PDF filename. See https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior for the complete list of available format.