According to our survey from the beginning of 2019, the majority of users are using xlwings for reporting (amongst other things). I'll show a few tricks for a better reporting experience and present our new add-on "xlwings REPORTS" for even more power! xlwings reports makes use of a smart Excel template directly in your Spreadsheet.
2. Agenda
1. Excel for Reporting – but why?!
2. Alternatives to Excel
3. Excel Writer Libraries
4. Code vs. Template
5. Reporting with xlwings CE
6. Reporting with xlwings REPORTS
2
8. What do you use xlwings for?
8
Source: xlwings Survey 2019 (Multiple answers were possible).
0% 10% 20% 30% 40% 50% 60% 70% 80%
Gradually migrate away from Excel
Write addins in Python
Machine Learning
Interactive session
As VBA replacement
Interfacing with external applications/databases/APIs
Use numpy/scipy etc.
Reports
9. One day on LinkedIn
9
“Hi, I just wanted to let you know that
xlwings has saved me hundreds of
hours in my current role. I replaced
the VBA reporting with it and
pyodbc and instead of taking 20-30
hours a month I can get the reports
run in 6-7. Thank you!”
Research Analyst, State Street
10. Over a cup of coffee
10
“We need a
better reporting
experience with
xlwings!”
Christian Fischer, Head of Investment
Analytics at Pension Fund of Credit Suisse
Group (Switzerland)
12. Alternative 1: HTML
12
There are some excellent web frameworks for
reporting available, like e.g. Dash
Source: https://dash-gallery.plotly.host/dash-financial-report/
13. Alternative 2: Direct PDF
13
ReportLab is a library to create high quality PDF
reports.
Source: https://www.reportlab.com/docs/reportlab-userguide.pdf
data = [['00', '01', '02', '03', '04’], ['10', '11', '12', '13', '14’],
['20', '21', '22', '23', '24’], ['30', '31', '32', '33', '34’]]
t = Table(data)
t.setStyle(TableStyle([('BACKGROUND', (1, 1), (-2, -2), colors.green),
('TEXTCOLOR', (0, 0), (1, -1), colors.red)]))
16. Excel writer libraries
16
• OpenPyXL (xlsx/xlsm)
• XlsxWriter (xlsx/xlsm)
• xlwt (xls)
• Pandas (uses one of the above under the
hood)
17. Issues with writer libraries
17
• Formatting: If you use xlwt or XlsxWriter:
You have to do all the formatting in Python
• Editing: Only OpenPyXL can “edit” (i.e.
copy/write) xlsx files but has limitations: E.g.
Charts lose some formatting
• xlsb: None of the libraries can handle xlsb
files
18. Use writer libraries if you can
18
• Unlike xlwings, they run on your Linux server
and don’t require an installation of Excel. I.e.
they are scalable, and you won’t run into any
Excel automation issues.
• However, they’re having similar shortcomings
with regards to reporting like xlwings CE
25. Idea: Use named ranges
25
wb.sheets["report"]["mytable"].value = df
Pros:
• Moves around with cells
Cons:
• “invisible”
• You may need many for the same variable
28. How to get it
28
1) pip install xlwings-reports
2) Get a trial license key under:
www.xlwings.org/trial
Homepage & Docs: www.xlwings.org/reporting
29. xlwings REPORTS
29
• Complete separation of code and design
• Template variables (Jinja), e.g. {{ today }}
• Frames for dynamic tables
• Supports DataFrames, text, pictures etc.
• Customizable via xlwings CE
33. Next Meetup: 24 March 2020
33
• Using in-memory objects to integrate Python in
Excel, Julij Jegorov
• Machine Learning and Excel, Colan Walsh (Founder
at Achilleon Consulting)
• Deployment of xlwings powered spreadsheets,
Felix Zumstein (Creator of xlwings)