我必须使用javascript自动保存动态创建的excel文件 [英] I have to auto save dynamic created excel file using javascript
本文介绍了我必须使用javascript自动保存动态创建的excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码
following code
<script type="text/javascript">
var tableToExcel = (function () {
var uri = 'data:application/vnd.ms-excel;base64,'
, template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
, base64 = function (s) { return window.btoa(unescape(encodeURIComponent(s))) }
, format = function (s, c) { return s.replace(/{(\w+)}/g, function (m, p) {return c[p]; }) }
return function (table, name) {
if (!table.nodeType) table = document.getElementById(table)
var ctx = { worksheet: name || 'Worksheet', table: table.innerHTML }
//alert(uri + base64(format(template, ctx)));
//alert(base64(format(template, ctx)));
window.location.href =uri + base64(format(template, ctx))
}
})()
</script>
我必须在D Drive中保存我动态创建的excel文件,请帮助我
谢谢你
I have to save my dynamic created excel file in D Drive please help me
Thank You
推荐答案
你好b $ b
这可能不是完美,但请在此处检查此源以在按钮单击时将表导出为excel,也许您可以在您的导出中包含该代码事件。只是一个想法...
https://github.com/jmaister/ excellentexport [ ^ ]
Hi
This might not be perfect, but check this source here to export a table to excel on button click, perhaps you can then include that code event in yours to export. Just a thought...
https://github.com/jmaister/excellentexport[^]
这篇关于我必须使用javascript自动保存动态创建的excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文