Suc*_*hae 3 google-sheets google-apps-script
我想要复制当前工作表到新工作表和工作表名称更改.
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sourceSheet = ss.getSheetByName('sheet_name'); <=== question 1
var copy = sourceSheet.copyTo(ss);
ss.setActiveSheet(copy);// set it active
ss.moveActiveSheet(ss.getNumSheets());// move it to the last position
copy.setName(' newSheetName is add 1 from current sheet name'); <== question 2
Run Code Online (Sandbox Code Playgroud)
问题1:
我需要当前的工作表名称或ID.
问题2:
如果当前工作表名称为"10",则为新工作表名称添加1
我不知道如何添加工作表名称的字符串类型.
Pie*_*ard 13
问题1:
Id指的是电子表格,名称参考表格.如果要获取工作表的名称,请查看sheet.getName()方法上的文档.
要获取活动工作表的名称:
var actualSheetName = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getName();
Run Code Online (Sandbox Code Playgroud)
问题2:
您可以使用substring方法获取sourceSheet字符串的最后一个字符,并使用parseInt方法将字符作为int值进行操作.
示例:您的工作表名称为"10".你只需要parseInt方法,如:
var temp = parseInt(sourceSheet);
temp += 1;
copy.setName(temp.toString());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11526 次 |
| 最近记录: |