I'm trying to use this script to save a html table to an Excel file, and it works fine, however it doesn't come up in the proper name, but rather with a random string. And I can't see why .
I call it with:
code
var tableToExcel = (function() {
var uri = 'data:application/vnd.ms-excel;base64,'
, template = '
{table}
'
, 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}
window.location.href = uri + base64(format(template, ctx))
}
})()
答案如下:
意思是:可以使用a标签的download属性来设置下载的文件标题:
You can use download attribute supported by modern browsera for a anchor element. First modify your HTML by adding an invisible anchor:
/
/这里是在你点击导出的按钮上方增加一个隐藏的a标签,只是为了更改标题内容
Notice also that the call to function tableToExcel now has 3rd parameter - where you specify file name.
Now use this modified code of your original function:
//这里是将html内容转换成excel的方法
var tableToExcel = (function () {
var uri = 'data:application/vnd.ms-excel;base64,'
, template = '
{table}
'
, 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, filename) {
if (!table.nodeType) table = document.getElementById(table)
var ctx = { worksheet: name || 'Worksheet', table: table.innerHTML }
#include<iostream>
#include<cassert>
using namespace std;
template<class T, int SIZE = 50>
class Stack{
private:
T list[SIZE];//数组存放栈的元素
int top;//栈顶位置
public:
Stack(
Gson提供了丰富的预定义类型适配器,在对象和JSON串之间进行序列化和反序列化时,指定对象和字符串之间的转换方式,
DateTypeAdapter
public final class DateTypeAdapter extends TypeAdapter<Date> {
public static final TypeAdapterFacto