我用下面的代码实现把左侧的表格添加到右侧中,但是复制后富文本变成了正常的文字
var tempspread = new GC.Spread.Sheets.Workbook(document.getElementById("spread-temp"));
tempspread.fromJSON(spread.toJSON());
spreadR.addSheet(1, new GC.Spread.Sheets.Worksheet('Sheet2'));
var sheet1 = spreadR.getSheet(1);
var commonsheet1 = tempspread.getSheet(1);
var commonsheetJson1 = JSON.stringify(commonsheet1.toJSON({ignoreFormula: true}));
// 重命名设置样式
commonsheetJson1 = commonsheetJson1.replace(/\"style\":\"/g, '"style":"zdyysb');
commonsheetJson1 = commonsheetJson1.replace(/\"parentName\":\"/g, '"parentName":"zzs');
//重命名样式表
tempspread.getNamedStyles().forEach(function (namedStyle) {
namedStyle.name = "zdyysb" + namedStyle.name;
spreadR.addNamedStyle(namedStyle);
});
sheet1.fromJSON(JSON.parse(commonsheetJson1));
var rowNum = commonsheet1.getRowCount();
var colNum = commonsheet1.getColumnCount();
for(var i=0;i<rowNum;i++){
for(var j=0;j<colNum;j++){
var style = commonsheet1.getActualStyle(i,j);
sheet1.setStyle(i,j,style);
}
}
var fsheet = spreadR.getSheet(1);
var tsheet = spreadR.getSheet(0);
var fromRanges = [new GC.Spread.Sheets.Range(0, 0, fsheet.getRowCount(),fsheet.getColumnCount())];
var tempRow = tsheet.getRowCount();
tsheet.addRows(tsheet.getRowCount(),fsheet.getRowCount());
var pastedRange = [new GC.Spread.Sheets.Range(tempRow, 0, fsheet.getRowCount(),fsheet.getColumnCount())];
console.log("fromRanges",fromRanges);
console.log("pastedRange",pastedRange);
spreadR.commandManager().execute({
cmd: 'clipboardPaste',
sheetName: tsheet.name(),
fromSheet: fsheet,
fromRanges: fromRanges,
pastedRanges: pastedRange,
isCutting: false,
clipboardText: "",
pasteOption: GC.Spread.Sheets.ClipboardPasteOptions.all
});
var j=0;
for(var i=tempRow;i<tsheet.getRowCount();i++){
tsheet.setRowHeight(i,fsheet.getRowHeight(j));
j++;
}
目前的效果如下图:
希望达到的效果如下图:
这要怎么实现
|