Recently, I had to create a new web app, which would generate PDF reports based on data stored in excel worksheets. As usual, I used Django along with many other Python libraries for this.
It has following parts:
- HTML Form - To select excel files and upload it to server
- Parsing uploaded excel file - Basic validation followed by reading data from worksheets. I used
xlrdmodule from Python-Excel project for this.
- Data analysis and plots - I used
pandas, Python Data Analysis Library, and
matplotlib, a python 2D plotting library, for this.
- PDF Generation -
RMLfrom ReportLab along with awesomeness of Django Templates seems suitable for this job. I used
z3c.rml, an open source implementation of
RMLstandard by Zope Foundation.
So, everything was working like a charm, except the fact that web app was reading data from first worksheet by index whenever an excel workbook was uploaded. But, user should be able to tell which worksheet to read from, right?
For this, I needed to know sheet names for selected excel workbook and then show a select box to choose one sheet name. I also wanted to show data stored in that worksheet in a table, a preview.
js-xls, but I did not get
"for human beings" feeling from this (if you have see requests vs urllib2 then you know what I mean).
After 1-2 hours of walking through source code of
I have integrated this
XLSXReader in my web app along with AngularJS. It consists of following parts:
XLSXReaderService, an angular app service, written on top of
a web worker for reading excel files in a separate threadFirefox does not support
FileReaderapi for web workers, so not using it anymore,
- an AngularJS controller along with HTML template.
Code snippet for this integration is available at https://gist.github.com/psjinx/8252417.
You can see a demo of above code snippet at http://code.psjinx.com/xlsx.js/.
Use cases for this kind of library
- Showing list of sheet names to choose from
- Preview of data stored in worksheets
- Integration with excel like data grid editors, e.g. Handsontable
- Send JSON data to server instead of excel files
- Integration with D3.js and a lot more
P.S. - I have tested everything on Google Chrome and Mozilla Firefox only. Since, this web appliaction is for internal use, I don't have to deal with browser compatibility issues. But, it should work in all browsers supported by Lodash and SheetJS.