导出HTML表到Excel JavaScript函数添加选择的文件名 [英] Export HTML table to Excel JavaScript function add select file name
本文介绍了导出HTML表到Excel JavaScript函数添加选择的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下函数输出一个HTML擅长:
I have the following function that exports an HTML to excel:
function generateexcel(tableid) {
var table= document.getElementById(tableid);
var html = table.outerHTML;
window.open('data:application/vnd.ms-excel,' + encodeURIComponent(html));
}
问题是,我不能把一个特定的文件名保存为让用户获得类似:
The problem is that, i can't put a specific file name to save as so the user gets something like:
您要保存%3Ctable%20id%3D%22tableRslts%22%20tabindex%3D%2235%22%20个文件?
Do you want to save %3Ctable%20id%3D%22tableRslts%22%20tabindex%3D%2235%22%20 file?
和保存的文件是这样的:
And the saved file is like:
IytvT8Jo.xls.part.xls
(至少在Firefox这是我们将使用目标浏览器)
IytvT8Jo.xls.part.xls
(at least in Firefox which is the target browser we will use)
你会如何解决这个问题?
How would you fix this?
推荐答案
有两个选项你可以看看其中:
There are two options which you could look into:
- Filesaver API 是新的HTML5功能,允许/正好/本。只是有一个小问题:相关的部分是不能在Firefox被支持。如果你想用这个有一个很好的包装库,这使得这更容易为你: filesaver.js
- Downloadify 是它正是这种创造,以及闪光灯的工具,你可以在这里找到。 ('缺点':闪光)
- Filesaver API is new 'HTML5' functionality allowing /exactly/ this. There is just one small problem: the relevant part isn't supported yet in firefox. If you want to use this there is a nice wrapper library which makes this easier for you: filesaver.js
- Downloadify is a flash tool which is created for exactly this as well, you can find it here. ('Disadvantage': flash)
这篇关于导出HTML表到Excel JavaScript函数添加选择的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文