0

I want to export my data (which reside on the Page) into excel (xlsx) format. I have gone through couple of available libraries but none of them actually worked or helped me to achieve my requirement. Below are the required things which I want to do while export:

  • Header column (First row of the exported xlsx file) should be bold which clearly state it as header.

  • Every column should be defined which the type of data like date column, string column, number column.

  • I can set the width of the columns, when opening the exported xlsx file (optional thing, if it is achievable)

I have gone through various JS based framework but most of them are providing support for xls file not for xlsx. But there are some which provides xlsx support like js-xlsx, but there is no good documentation available to do that or how to achieve the excel export functionality with my requirements.

I have also looked into one more xlsx export framework (exceljs) which is very good with the documentation, but I doubt it is not available outside of nodejs, its a plugin of nodejs thus require nods js to run. Thus its not purely client side or on page side.

Can you please help me to achieve that with java-script.

Thanks

user2809299
  • 149
  • 2
  • 13
  • You do not need JS libraries, just output the page with table and set header to `Content-Type: application/vnd.ms-excel; charset=utf-8`. Also style the cells using [this formatting](http://cosicimiento.blogspot.co.at/2008/11/styling-excel-cells-with-mso-number.html) in order to define excel cell type. – skobaljic Oct 19 '16 at 09:41
  • @skobaljic, Thanks for your suggestion well I'm not aware about that process,Can you please explain this a little bit, means how can I do that. Also will it supports all major browsers. mostly IE, Safari and chrome – user2809299 Oct 19 '16 at 09:51
  • On your Excel download page, first output Excel header, filename and content size, than the HTML table with styles mentioned above and that's it. Also check [this answer](http://stackoverflow.com/questions/3831186/download-data-from-html-table-to-excel#answer-3831294) I found. Further on, it has nothing to do with browsers, but with Excel on your machine. A benefit, since you create this download page, you could add a **pdf** export easily in case you have [webkit html to pdf](http://wkhtmltopdf.org/) installed on your server. – skobaljic Oct 20 '16 at 10:10

1 Answers1

0

You can SheetJS xlsx library it will more help to you. Here is the example Table to Excel

Anil Talla
  • 709
  • 5
  • 19
  • I'm also pointing to this same framework in my question, this framework is not very detailed in instructions and also it is not fulfilling my requirement bullet points, like header as a bold text,and data type columns definition – user2809299 Oct 19 '16 at 09:53
  • Did you check this https://github.com/SheetJS/js-xlsx/blob/master/README.md – Anil Talla Oct 19 '16 at 09:59
  • In the sheetjs xlsx, readme file.. One section is there.. "Workbook / Worksheet / Cell Object Description" in this section it will be explained but it is some what high level. I Searched many libraries for exporting excel, at last I settled with this library. – Anil Talla Oct 19 '16 at 10:05
  • Yes, I have gone through with this, but didn't help me. – user2809299 Oct 19 '16 at 10:26
  • @user2809299 Can you provide example. Then I can help you more – Anil Talla Oct 19 '16 at 10:42