根据单元格自动重命名 sheet
Automatically rename sheet based on cell
我只是用脚本创建一个按钮来从模板创建新的 sheet,我可以获取代码来根据 C2:C58 之间的编号 ID 创建新名称 sheet 吗?
这是我用宏创建的代码:
function Qfull() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange('J12:J13').activate();
spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Q Full'), true);
spreadsheet.duplicateActiveSheet();
spreadsheet.moveActiveSheet(86);
spreadsheet.getActiveSheet().setName('New Quotation');
};
请查看此处的屏幕截图:
嘿,我建议进行以下修改:
- 创建一个列来检查选项卡是否已在检查器之类的东西之前创建。在我的示例中,如果它已经
,我使用 ColB 来标记 'created'
- 使用forEach 循环读取每一行并检查之前是否已创建名称在ColC 中的选项卡。如果尚未创建,请使用模板 'Q Full' 创建一个新选项卡并使用 ColC.
中的名称重命名它
我已经创建了一个 MVP 来匹配你的情况:https://docs.google.com/spreadsheets/d/1vrZJmlkQGD-7zujf55b0oUqQ8AXdwai5MY3Rmw2076A/edit#gid=0
关于 forEach 循环:https://spreadsheet.dev/foreach-loop-in-apps-script
我会按如下方式为您编写代码:
function Qfull() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheetByName('Summary 2022'); //get the sheet which you want to extract names from
const check = sheet.getDataRange().getValues();
ss.setActiveSheet(ss.getSheetByName('Q Full'),true); //set your template for duplication
check.forEach(function(row,col){
if(col == "") return;
if(row[1] == "created") return; //if ColB shows 'created' skip
ss.duplicateActiveSheet().setName(row[2]); //create sheet with name from ColC
sheet.getRange(col + 1,2).setValue('created'); //after creating put 'created' in ColB so it won't create the next round
});
}
我只是用脚本创建一个按钮来从模板创建新的 sheet,我可以获取代码来根据 C2:C58 之间的编号 ID 创建新名称 sheet 吗?
这是我用宏创建的代码:
function Qfull() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange('J12:J13').activate();
spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Q Full'), true);
spreadsheet.duplicateActiveSheet();
spreadsheet.moveActiveSheet(86);
spreadsheet.getActiveSheet().setName('New Quotation');
};
请查看此处的屏幕截图:
嘿,我建议进行以下修改:
- 创建一个列来检查选项卡是否已在检查器之类的东西之前创建。在我的示例中,如果它已经 ,我使用 ColB 来标记 'created'
- 使用forEach 循环读取每一行并检查之前是否已创建名称在ColC 中的选项卡。如果尚未创建,请使用模板 'Q Full' 创建一个新选项卡并使用 ColC. 中的名称重命名它
我已经创建了一个 MVP 来匹配你的情况:https://docs.google.com/spreadsheets/d/1vrZJmlkQGD-7zujf55b0oUqQ8AXdwai5MY3Rmw2076A/edit#gid=0
关于 forEach 循环:https://spreadsheet.dev/foreach-loop-in-apps-script
我会按如下方式为您编写代码:
function Qfull() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheetByName('Summary 2022'); //get the sheet which you want to extract names from
const check = sheet.getDataRange().getValues();
ss.setActiveSheet(ss.getSheetByName('Q Full'),true); //set your template for duplication
check.forEach(function(row,col){
if(col == "") return;
if(row[1] == "created") return; //if ColB shows 'created' skip
ss.duplicateActiveSheet().setName(row[2]); //create sheet with name from ColC
sheet.getRange(col + 1,2).setValue('created'); //after creating put 'created' in ColB so it won't create the next round
});
}