Exporting data to Excel is a basic need for nearly every enterprise web application. Being a web developer, I too was strongly required to do that in various projects I had in my career. Every time, I saw a server-side solution, like export data using some custom Export to Excel server-side method to generate and dump an Excel file at some temporary location on the server and then download it. The entire process runs every time a user exports some data. This raises the following major concerns:

  1. Unwanted consumption of disk space on the server by creating these temporary files.
  2. Unwanted Postback to generate the Excel files.

To avoid these concerns, I decided to implement some client-side functionality to export data in my current project. And so as a genuine developer, I read many articles, blogs, and posts to find the best way to implement it. I got some JavaScript libraries that work fine in Chrome and Firefox but does not work in IE since the latter doesn’t support data URIs. You can find more info about IE Data URI here. I really tried many solutions but didn’t find a satisfactory one. After a completely failed operation, I still had one thing, that was how can this work? As per my understanding:

  1. Load data on the screen using the lightest control, in other words an HTML Table.
  2. Export this loaded data to an Excel file by transforming this HTML table using some data URI supported elements like an IFrame.

So, I began writing some code and came up with this solution. So far in this article, we have seen many theoretical aspects. Now it’s code time.

#javascript #html #excel

How to Export HTML Table Data to Excel with JavaScript
40.60 GEEK