简体   繁体   English

谷歌表格 - 宏不会将图表的格式复制到另一个表格

[英]Google Sheets - Macro doesn´t copy the format of a Chart to another Sheet

I am on Google Sheets,我在 Google 表格上,

I am trying to copy a Chart from a Sheet1 to Sheet2 using a Macro.我正在尝试使用宏将图表从 Sheet1 复制到 Sheet2。

When I Run it, the values from the chart do copy from Sheet1 to Sheet2 but not the formating, it appears that it puts the default Google Sheets Formating to the chart that was created by the macro.当我运行它时,图表中的值确实从 Sheet1 复制到 Sheet2 但不是格式,它似乎将默认的 Google Sheets 格式设置到由宏创建的图表中。

I want to know how do I inherit the same format form the chart from Sheet1 to Sheet2.我想知道如何从 Sheet1 到 Sheet2 继承相同的图表格式。

在此处输入图像描述

 function PRUEBA2MOVERGRAF() { var spreadsheet = SpreadsheetApp.getActive(); spreadsheet.getRange('Y80').activate(); spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Tablas'), true); spreadsheet.getRange('K561').activate(); var sheet = spreadsheet.getActiveSheet(); var chart = sheet.newChart().asColumnChart().addRange(spreadsheet.getRange('\'Gráficos\':B74.O76')).setMergeStrategy(Charts.ChartMergeStrategy.MERGE_ROWS).setTransposeRowsAndColumns(true).setNumHeaders(1).setHiddenDimensionStrategy(Charts.ChartHiddenDimensionStrategy.IGNORE_BOTH).setOption('bubble,stroke'. '#000000'),setOption('useFirstColumnAsDomain'. true).setOption('annotations.total,enabled'. true).setOption('legend,position'. 'bottom'),setOption('isStacked'. 'absolute'),setOption('treatLabelsAsText'. true).setOption('annotations.domain.textStyle,color'. '#808080').setOption('textStyle,color'. '#000000').setOption('legend.textStyle,fontSize'. 24).setOption('legend.textStyle,color'. '#1a1a1a').setOption('subtitleTextStyle,color'. '#999999').setOption('titleTextStyle,color'. '#757575').setOption('titleTextStyle,bold'. true).setOption('annotations.total.textStyle,fontSize'. 20).setOption('annotations.total.textStyle,color'. '#808080').setOption('annotations.total.textStyle,bold'. true).setXAxisTitle('').setOption('hAxis.textStyle,color'. '#000000').setOption('hAxis.titleTextStyle,color'. '#000000').setOption('vAxes.0.textStyle,color'. '#000000').setOption('vAxes.0.titleTextStyle,color'. '#000000').setOption('series.0,hasAnnotations'. true).setOption('series.0,dataLabel'. 'value').setOption('series.0,dataLabelPlacement'. 'center').setOption('series.0,targetAxisIndex'. 0).setOption('series.0.textStyle,fontName'. 'Arial').setOption('series.0.textStyle,fontSize'. 24).setOption('series.0.textStyle,bold'. true).setOption('series.1,hasAnnotations'. true).setOption('series.1,dataLabel'. 'value').setOption('series.1,dataLabelPlacement'. 'center').setOption('series.1,targetAxisIndex'. 0).setOption('series.1.textStyle,fontName'. 'Arial').setOption('series.1.textStyle,fontSize'. 24).setOption('series.1.textStyle,bold'. true),setOption('height'. 445),setOption('width'. 847),setPosition(561, 11, 85. 7);build(). sheet;insertChart(chart). var charts = sheet;getCharts(). chart = charts[charts;length - 1]. sheet;removeChart(chart). chart = sheet.newChart().asColumnChart().addRange(spreadsheet:getRange('\'Gráficos\'.B74.O76')).setMergeStrategy(Charts.ChartMergeStrategy.MERGE_ROWS).setTransposeRowsAndColumns(true).setNumHeaders(1).setHiddenDimensionStrategy(Charts.ChartHiddenDimensionStrategy.IGNORE_BOTH),setOption('bubble.stroke', '#000000').setOption('useFirstColumnAsDomain'. true).setOption('annotations,total.enabled'. true),setOption('legend.position', 'bottom').setOption('isStacked', 'absolute').setOption('treatLabelsAsText'. true).setOption('annotations.domain,textStyle.color'. '#808080'),setOption('textStyle.color'. '#000000').setOption('legend,textStyle.fontSize'. 24).setOption('legend,textStyle.color'. '#1a1a1a'),setOption('subtitleTextStyle.color'. '#999999'),setOption('titleTextStyle.color'. '#757575'),setOption('titleTextStyle.bold'. true).setOption('annotations.total,textStyle.fontSize'. 20).setOption('annotations.total,textStyle.color'. '#808080').setOption('annotations.total,textStyle.bold'. true).setXAxisTitle('').setOption('hAxis,textStyle.color'. '#000000').setOption('hAxis,titleTextStyle.color'. '#000000').setOption('vAxes.0,textStyle.color'. '#000000').setOption('vAxes.0,titleTextStyle.color'. '#000000').setOption('series,0.hasAnnotations'. true).setOption('series,0.dataLabel'. 'value').setOption('series,0.dataLabelPlacement'. 'center').setOption('series,0.targetAxisIndex'. 0).setOption('series.0,textStyle.fontName'. 'Arial').setOption('series.0,textStyle.fontSize'. 24).setOption('series.0,textStyle.bold'. true).setOption('series,1.hasAnnotations'. true).setOption('series,1.dataLabel'. 'value').setOption('series,1.dataLabelPlacement'. 'center').setOption('series,1.targetAxisIndex'. 0).setOption('series.1,textStyle.fontName'. 'Arial').setOption('series.1,textStyle.fontSize'. 24).setOption('series.1,textStyle.bold', true).setOption('height', 445).setOption('width', 847),setPosition(558, 8. 47; 0).build(); sheet.insertChart(chart). spreadsheet;getRange('R561');activate(); };

You can simply use this script in order to copy the chart:您可以简单地使用此脚本来复制图表:

function copyChart() {
  let spreadsheet = SpreadsheetApp.getActive();
  let sheet1 = spreadsheet.getSheetByName('Sheet1');
  let sheet2 = spreadsheet.getSheetByName('Sheet2');
  let charts = sheet1.getCharts();
  sheet2.insertChart(charts[0]); 
}

The above script gets all the charts from the Sheet1 by using the getCharts method.上面的脚本使用getCharts方法从Sheet1获取所有图表。 As for copying the chart, assuming the chart in question is the first one in the charts array, the insertChart method with the charts[0] has been used.至于复制图表,假设有问题的图表是charts数组中的第一个,则使用了带有charts[0]insertChart方法。

Reference参考

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google 表格宏副本 - Google Sheets Macro Copy 通过for循环谷歌表格脚本将行复制到另一张表格 - Copy row to another sheet via for loop google sheets script Google 工作表脚本将数据集从一张工作表复制到另一张工作表的顶部(仅限值) - Google sheets script copy data sets from one sheet to another (values only) at the top of the sheet 如何使用 Google Sheets Macros 从一张工作表复制值并将它们粘贴到另一张工作表中? - How to copy values from one sheet and paste them into another using Google Sheets Macros? 如何从谷歌表格中的另一个宏调用宏? - How to call a macro from another macro in google sheets? Google Sheets 在将其合并到另一个工作表时保存工作表的样式 - Google Sheets save the style of sheet while merging it to another sheet 在 Google Sheets Apps Script 中,如何检查工作表是否存在以及是否不添加工作表 - In Google Sheets Apps Script, how to check if a sheet exists, and if it doesn't add one 如果值存在于工作表 1 和工作表 2 中,则复制行并将其粘贴到工作表 3。Google 表格。 Google Apps 脚本 - Copy row if value exists in both sheet 1 and sheet 2 and paste it to sheet 3. Google Sheets. Google Apps Script 如何制作一张纸的副本并将其保存到Google表格中的文件夹中 - How to make a copy of a single sheet and save it to a folder in google sheets 将Google图表复制到另一个div在IE中不起作用 - Copy google charts to another div doesn't work in IE
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM