导出CSV的时候,要做一些特殊处理需要克隆一个spread,但是克隆的spread数据丢失了,所以我重新设置了一下。为什么会丢失呢?有特殊对象的原因?
export function spreadJsCsvDownload(spread, fileName,data,colInfos,flg) {
if (!fileName) {
return false;
}
if (!spread) {
return false;
}
var newSpread = new GC.Spread.Sheets.Workbook();
newSpread.fromJSON(JSON.parse(JSON.stringify(spread.toJSON())));
let sheet = newSpread.getActiveSheet();
//sheet.setDataSource(data);
//sheet.bindColumns(colInfos);
sheet.addRows(0, 1);
sheet.setRowVisible(0, false, GC.Spread.Sheets.SheetArea.viewport);
for (var col = 0; col < sheet.getColumnCount(); col++) {
sheet.setValue(
0,
col,
sheet.getText(0, col, GC.Spread.Sheets.SheetArea.colHeader)
);
if(flg){
if(!sheet.getColumnVisible(col)){
sheet.deleteColumns(col, 1);
}
}
}
let options = {
columnHeadersAsFrozenRows: false,
encoding: "UTF-8",
rowDelimiter: "\r\n",
columnDelimiter: ",",
sheetIndex: 0,
};
options.fileType = GC.Spread.Sheets.FileType.csv;
newSpread.export(
function (blob) {
saveAs(blob, fileName);
},
function () {},
options
);
}spread对象:
下在的CSV:
datasourceModel:[
{ name: 'CODE', age: 27,account:210,subject:">>", birthday: '19850820', position: '0',check:true},
{ name: 'CODE', age: 27,account:80,subject:null, birthday: '19850820', position: '1',check:true},
{ name: 'CODE', age: 27,account:70,subject:"数", birthday: '19850820', position: '1',check:true},
{ name: 'CODE', age: 27,account:60,subject:"语", birthday: '19850820', position: '1',check:true},
]
colInfos: [
{ name: 'name', displayName: 'CODE', size: 120},
{ name: 'account', displayName: '隐藏列', size: 120, visible: false},
{ name: 'subject', displayName: '科目', size: 80,},
{ name: 'position', displayName: '时间', size: 100,},
{ name: 'birthday', displayName: '日期', formatter: 'yy/MM/dd', size: 120 },
{ name: 'age', displayName: '数据', size: 120, formatter: '0.00%',resizable: false },
{ name: 'check', displayName: '選択', size: 120,},
],
|