完整代码请参考以下代码:
- var data = [
- {
- name: 111,
- value1: 1,
- value2: 2,
- value3: 3,
- value4: 4,
- value5: 5,
- },
- {
- name: 111,
- value1: 1,
- value2: 2,
- value3: 3,
- value4: 4,
- value5: 5,
- },
- {
- name: 222,
- value1: 1,
- value2: 2,
- value3: 3,
- value4: 4,
- value5: 5,
- },
- {
- name: 222,
- value1: 1,
- value2: 2,
- value3: 3,
- value4: 4,
- value5: 5,
- },
- {
- name: 222,
- value1: 1,
- value2: 2,
- value3: 3,
- value4: 4,
- value5: 5,
- },
- {
- name: 222,
- value1: 1,
- value2: 2,
- value3: 3,
- value4: 4,
- value5: 5,
- },
- {
- name: 222,
- value1: 5,
- value2: 2,
- value3: 3,
- value4: 4,
- value5: 5,
- },
- ];
- var spread = GC.Spread.Sheets.findControl("ss");
- spread.getActiveSheet().setDataSource(data);
- const excelIo = new GC.Spread.Excel.IO();
- const jsonStr = JSON.stringify(spread.toJSON({includeBindingSource: true}));
- const tempSpread = new GC.Spread.Sheets.Workbook();
- tempSpread.fromJSON(JSON.parse(jsonStr));
- tempSpread.getSheetFromName("Sheet2").deleteRows(2, data.length-3);
- const json = tempSpread.toJSON();
- // 下载ssjson文件方法
- var funDownload = function (content, filename) {
- var eleLink = document.createElement('a');
- eleLink.download = filename;
- eleLink.style.display = 'none';
- // 字符内容转变成blob地址
- var blob = new Blob([content]);
- eleLink.href = URL.createObjectURL(blob);
- // 触发点击
- document.body.appendChild(eleLink);
- eleLink.click();
- // 然后移除
- document.body.removeChild(eleLink);
- };
- funDownload(JSON.stringify(json), "download.ssjson");
- // here is excel IO API
- excelIo.save(json, function (blob) {
- saveAs(blob, "111.xlsx");
- }, function (e) {
- // process error
- console.log(e);
- }, {password: ""});
复制代码 |