Ghana Finance

Jan 31 2018

Javascript: Export HTML Table to Excel With Custom File Name – Kubilay Erdogan Home Page

#mysql #excel #export


#

Javascript: Export HTML Table to Excel With Custom File Name

Web browser wars hurt developers hearts. It is mostly about CSS, sometimes about JavaScript, HTML etc

Thus I know how it feels when you expect something to get done easily appears a lot more harder than you expected.

Code below is tested only with Chrome (24+). It is making these processes:

  • Gets the HTML code of your table inside your div element.
  • Replaces the spaces in the code with correct syntax for Excel (otherwise spaces will be removed in your Excel sheet).
  • Generates a specific file name (for minutes) in order to avoid overriding old files and to supply archiving by date values.
  • And lastly and most importantly, saving the file with a custom file name.

Here s my combination of codes (from different SO questions or tutorials) if you want to save HTML table to client computer using JavaScript code.

Previous Article Generate DateTime Value in PHP for Using in MySQL Command

Next Article html2canvas- Take Screenshot of Web Page and Save It to Server (Javascript and PHP)

Excelent, thanks a lot works great

I have try this code. Please let me know where this file stored. I can t to able see this file.

This code is a JavaScript function. Make sure you have an input or button element in your page with btnExport id.

When you hit that button, this code will execute and a Save File dialog will pop-up.

That fiddle displays an html table correctly in the div, but the Click for save button only works in Chrome 30 (not in IE10 or Firefox 24).
Anyone know what the solution is?

I don t know where did you get this code but at least it works in Firefox, this was the problem in your case I guess.

However, you might need to ask for help in the page you found the code. As I mentioned in this topic, I ve tested in Google Chrome only, can t say about other browsers.

If you ask my advice, you should try something that is told to be working in other browsers, check the link in this comment: http://www.kubilayerdogan.net/?p=218#comment-2081

Hope this helps,
Regards.

i have problem in here.i save the script as excel.js, so in the html i put this code . when i run this program, there is a warning message window, it contains
Error: $ is undefined
i hope u can solve the problem, thanks and sry for my bad english

Did you include jQuery in the head section of your HTML page? It appears to be a jQuery problem, it either can t find the jQuery library or can t find the element with the id btnExport .

Would it be possible for you to post a sample html file which works with this? I d very much appreciate it.


Written by admin


Leave a Reply

Your email address will not be published. Required fields are marked *