alasql如何以样式下载.xlsx格式的excel

时间:2018-06-20 21:29:09

标签: javascript excel alasql

我在做什么 我正在使用alasql库在客户端生成excel。我从API获取JSON数据,然后将该数据传递给alasql库以获取具有样式的excel。

正在做什么 下载的文件将保存为.xls扩展名,并应用所有样式(粗体,彩色等)

什么不起作用 如果我尝试使用alasql库将文件保存为.xlsx格式,则在打开excel文件时收到以下错误消息。 “ Excel无法打开文件,因为文件格式或文件扩展名无效,请验证文件未损坏并且文件扩展名与文件格式匹配

目的 我要使用.xlsx而不是.xls的原因是因为打开文件时,文件的大小减小了,并且没有其他消息弹出(不是来自受信任的来源...)

代码

// A: This gives warning error unsafe to open. NOT good
alasql('SELECT name AS [Name], email AS [Email Address], dob AS [Date of Birth] INTO XLS("A.xls",?) FROM ?', [opts, Apidata]);
// B: File corrupted. BAD
alasql('SELECT name AS [Name], email AS [Email Address], dob AS [Date of Birth] INTO XLS("B.xlsx",?) FROM ?', [opts, Apidata]);
// C: This gives warning error unsafe to open. NOT good
alasql('SELECT name AS [Name], email AS [Email Address], dob AS [Date of Birth] INTO XLSX("C.xls",?) FROM ?', [opts, Apidata]);
// D: No styling. NOT good
alasql('SELECT name AS [Name], email AS [Email Address], dob AS [Date of Birth] INTO XLSX("D.xlsx",?) FROM ?', [opts, Apidata]);
// E: This gives warning error unsafe to open. NOT good
alasql('SELECT name AS [Name], email AS [Email Address], dob AS [Date of Birth] INTO XLSXML("E.xls",?) FROM ?', [opts, Apidata]);
// F: File corrupted. BAD
alasql('SELECT name AS [Name], email AS [Email Address], dob AS [Date of Birth] INTO XLSXML("F.xlsx",?) FROM ?', [opts, Apidata]);

演示
http://jsfiddle.net/6sd7zwjp/

请帮忙!

0 个答案:

没有答案