找回密码
 立即注册

QQ登录

只需一步,快速开始

qianduoduo

注册会员

3

主题

5

帖子

18

积分

注册会员

积分
18

微信认证勋章

最新发帖
qianduoduo
注册会员   /  发表于:2024-5-10 15:37  /   查看:126  /  回复:3
1金币
我的导出代码是这么写的?难道获取表格数据不对么?

  1. const workbook = new GC.Spread.Sheets.Workbook(document.getElementById("ssvp_vp"));
  2.            const json = JSON.stringify(workbook.toJSON());
  3.            console.log("🚀 ~ myFunction ~ json:", json)
  4.             const excelIO = new GC.Spread.Excel.IO();
  5.             excelIO.save(json, function (blob) {
  6.                 if (isSafari) {
  7.                     const reader = new FileReader();
  8.                     reader.onloadend = function () {
  9.                         $("#download").show();
  10.                         const link = $("#downloadlink");
  11.                         link[0].href = reader.result;
  12.                     };
  13.                     reader.readAsDataURL(blob);
  14.                 } else {
  15.                     saveAs(blob, "123.xlsx");
  16.                 }
  17.             }, function (e) {
  18.                 alert(JSON.stringify(e));
  19.             }, {password: ''});
复制代码


最佳答案

查看完整内容

我解决了我把我代码贴一下:

3 个回复

倒序浏览
最佳答案
最佳答案
qianduoduo
注册会员   /  发表于:2024-5-10 15:37:50
来自 3#
Richard.Huang 发表于 2024-5-10 15:55
您好,请问您说的“但是导出总是空数据。”指的是通过数据绑定上去的内容丢失了吗?如果是的话,您需要在to ...

我解决了我把我代码贴一下:
  1. var exceldata;
  2.             function exportExcel() {
  3.                 var json =  window.spread.toJSON({ includeBindingSource: true });
  4.                 const jsondata = exceldata || json;
  5.                 console.log("🚀 ~ exportExcel ~ json:", jsondata);
  6.                 const excelIO = new GC.Spread.Excel.IO();
  7.                 excelIO.save(jsondata, function (blob) {
  8.                     if (isSafari) {
  9.                         const reader = new FileReader();
  10.                         reader.onloadend = function () {
  11.                             $("#download").show();
  12.                             const link = $("#downloadlink");
  13.                             link[0].href = reader.result;
  14.                         };
  15.                         reader.readAsDataURL(blob);
  16.                     } else {
  17.                         saveAs(blob, "acca.xlsx");
  18.                     }
  19.                 }, function (e) {
  20.                     alert(JSON.stringify(e));
  21.                 }, { password: '' });
  22.             }

  23.             //传输JSON
  24.             $(document).ready(function () {
  25.                 var spreadNS = GC.Spread.Sheets;
  26.                 window.spreadNS = spreadNS
  27.                 window.spread = spread
  28.                 spread.bind(spreadNS.Events.SelectionChanging, function () {
  29.                     var json = spread.toJSON({ includeBindingSource: true })
  30.                     exceldata = json;
  31.                     vm.s = JSON.stringify(json);
  32.                 });
  33.                 //初始化excel中的内容以及禁止用户新开sheet
  34.                 // var sheet = spread.getActiveSheet()
  35.                 // sheet.setValue(0,0,'2017');
  36.                 // sheet.setValue(1,1,'omg,shit,wtf');
  37.                 // sheet.setArray(4, 2, [[1, 2, 3], [4, 5, 6], [7, 8, 9]]);
  38.                 spread.options.newTabVisible = false;
  39.                 $('#selectBar').on('change', (e) => {
  40.                     var sheet = spread.getActiveSheet();
  41.                     let num = $('#selectBar option:selected').val();
  42.                     console.log(num);
  43.                     sheet.zoom(num)
  44.                 })
  45.             });
复制代码

评分

参与人数 1金币 +500 收起 理由
Joestar.Xu + 500 赞一个!

查看全部评分

回复 使用道具 举报
Richard.HuangSpreadJS 开发认证
超级版主   /  发表于:2024-5-10 15:55:43
2#
您好,请问您说的“但是导出总是空数据。”指的是通过数据绑定上去的内容丢失了吗?如果是的话,您需要在toJSON时将includeBindingSource设置为true。
const json = JSON.stringify(workbook.toJSON({includeBindingSource: true}));
回复 使用道具 举报
Joestar.XuSpreadJS 开发认证
超级版主   /  发表于:2024-5-10 18:03:58
4#
好的,那就先结贴了,后续有其他问题的话随时开新帖提问。
SpreadJS 17.0.9 | GcExcel 7.1.2 已发布~
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部