带有图表的Sheet无法复制
本帖最后由 __贪心 于 2020-12-9 16:01 编辑带有图表的Sheet,无法通过 toJSON/fromJSON的方式复制
function copySheet(spread: GC.Spread.Sheets.Workbook, sheetName: string) {
const sheet = spread.getSheetFromName(sheetName);
const copySheetName = sheetName + '_copy';
// 拷贝数据
const newSheet = new GC.Spread.Sheets.Worksheet(copySheetName);
newSheet.fromJSON(sheet.toJSON());
newSheet.name(copySheetName);
spread.addSheet(0, newSheet);
}以上方式复制一个sheet,当源sheet中存在图表时,会报错:
Uncaught TypeError: Cannot read property 'getSheetFromName' of undefined
at Worksheet.GC.Spread.Sheets.Charts../dist/plugins/chart/chart-spreadjs.js.worksheetPrototype._GetSheet (index.js?3c41:6586)
at Series.GC.Spread.Sheets.Charts../dist/plugins/chart/series.js.Series.UpdateNameByRefer (index.js?3c41:19739)
at Series.GC.Spread.Sheets.Charts../dist/plugins/chart/series.js.Series.UpdateNameRefer (index.js?3c41:19630)
at Series.GC.Spread.Sheets.Charts../dist/plugins/chart/series.js.Series.SetNameRefer (index.js?3c41:19612)
at Series.GC.Spread.Sheets.Charts../dist/plugins/chart/series.js.Series.UpdateNameFormula (index.js?3c41:19558)
at Series.GC.Spread.Sheets.Charts../dist/plugins/chart/series.js.Series.FromCT_SerTx (index.js?3c41:21604)
at Series.GC.Spread.Sheets.Charts../dist/plugins/chart/series.js.Series.FromCT_CatValSerBase (index.js?3c41:21032)
at Series.GC.Spread.Sheets.Charts../dist/plugins/chart/series.js.Series.FromCT_BarSer (index.js?3c41:20703)
at Series.GC.Spread.Sheets.Charts../dist/plugins/chart/series.js.Series.FromOOModel (index.js?3c41:20522)
at SeriesCollection.GC.Spread.Sheets.Charts../dist/plugins/chart/series.js.SeriesCollection.RestoreSeriesImp (index.js?3c41:24470)
at SeriesCollection.GC.Spread.Sheets.Charts../dist/plugins/chart/series.js.SeriesCollection.RestoreSeries (index.js?3c41:24358)
at PlotArea.GC.Spread.Sheets.Charts../dist/plugins/chart/plotArea.js.PlotArea.FromOOModel (index.js?3c41:15938)
at ChartModel.GC.Spread.Sheets.Charts../dist/plugins/chart/chart.js.ChartModel.FromCT_Chart (index.js?3c41:8727)
at ChartModel.GC.Spread.Sheets.Charts../dist/plugins/chart/chart.js.ChartModel.FromOOModel (index.js?3c41:8607)
at Chart.GC.Spread.Sheets.Charts../dist/plugins/chart/chartview.js.Chart.fromJSON (index.js?3c41:13150)
at Worksheet.fromJsonAfterFormula (index.js?3c41:7051)
at Object.eval (index.js?603e:117048)
at _each (index.js?603e:168185)
at Worksheet.GC.Spread../dist/plugins/sheetsCalc/worksheet-formula.js.worksheetPrototype.formulaFromJSON (index.js?603e:117045)
at Worksheet.fromJson (index.js?603e:117614)
at Object.eval (index.js?603e:29517)
at _each (index.js?603e:168185)
at Worksheet.fromJSON (index.js?603e:29514)
您好,我这边测试是没问题的,没能重现您的问题
猜测是图表引用数据的公式问题,建议您发一个能够重现的demo,我们深入调查一下 ClarkPan 发表于 2020-11-27 17:58
您好,我这边测试是没问题的,没能重现您的问题
可以将您的demo发出来看一下不?我看看是不是绘图的方式不一样。另外,我用的是v13的版本 我是用在线表格编辑器进行重现的,没能重现,所以怀疑可能是您的图表数据的问题,建议您提供一个能够重现问题的demo,我们具体看看什么原因。 function copySheet(spread, sheetName) {
const sheet = spread.getSheetFromName(sheetName);
const copySheetName = sheetName + '_copy';
// 拷贝数据
const newSheet = new GC.Spread.Sheets.Worksheet(copySheetName);
newSheet.fromJSON(sheet.toJSON());
newSheet.name(copySheetName);
spread.addSheet(0, newSheet);
}
copySheet(GC.Spread.Sheets.findControl(document.querySelector('.ss')), 'Sheet2')
您好,我就是用你们的在线demo测试的呢 https://demo.grapecity.com.cn/SpreadJS/WebDesigner/。
您可以试试,新建一个sheet2,然后随便输入点数据绘制柱状图,然后在控制台运行上诉代码,就会出现如下报错
__贪心 发表于 2020-12-1 14:56
您好,我就是用你们的在线demo测试的呢 https://demo.grapecity.com.cn/SpreadJS/WebDesigner/。
您可以 ...
您好,您可以参考附件的代码,出现您描述的问题是因为您将addSheet放在fromJSON后,找不到对应的表单就会报错,下面是关键代码
function insertChart(spread) {
var activeSheet = spread.getActiveSheet();
var copySheetName = "sheet1" + '_copy';
var newSheet = new GC.Spread.Sheets.Worksheet(copySheetName);
spread.addSheet(0, newSheet);
var jsonString = JSON.stringify(activeSheet.toJSON());
// newSheet.from
console.log(jsonString)
newSheet.fromJSON(JSON.parse(jsonString));
newSheet.name(copySheetName);
}
DerrickJiao 发表于 2020-12-1 15:33
您好,您可以参考附件的代码,出现您描述的问题是因为您将addSheet放在fromJSON后,找不到对应的表单就会 ...
https://gcdn.grapecity.com.cn/data/attachment/forum/202012/09/160140i393i1br1n6ropr9.gif
我使用了您说的方式,调整addsheet的时机确实可以防止报错了。但测试了下,这样执行了后,原来的图标就失去了跟数据的绑定关系。具体您可以查看上面的动图 本帖最后由 DerrickJiao 于 2020-12-9 18:10 编辑
__贪心 发表于 2020-12-9 16:03
我使用了您说的方式,调整addsheet的时机确实可以防止报错了。但测试了下,这样执行了后,原来的图标 ...
问题已复现,我们会做进一步调研,有进展会更帖告知您,此贴为您改为保留处理。(SJS-6809) 您好,该问题已于14.2.0中修复,您可以升级后测试一下。
页:
[1]