简体   繁体   English

将工作表名称与表格内容链接起来

[英]Link sheet names with table's contents

My question is rather straightforward: I would like to link some sheet names (not all) in my workbook with a table containing a range of dates.我的问题很简单:我想将工作簿中的一些工作表名称(不是全部)与包含日期范围的表格链接起来。

Sheetnames should become sthg like "blablabla" + Table@1.工作表名称应该变成类似“blablabla”+ Table@1 的东西。

Here is what I have designed so far but this doesn't quite seem to work unfrotunately.到目前为止,这是我的设计,但这似乎并不能很好地工作。

function main(workbook: ExcelScript.Workbook) {
  let i = 0;
  let sheets = workbook.getWorksheets();
  let dates = workbook.getTable("Months").getColumn(1).getRange().getCell(i, 1); 
  for (let sheet of sheets) {
    if (sheet.getName().includes("Capacity split -") && !sheet.getName().includes("Capacity split - Next quarters")){
      let newName = 'Capacity split -' + dates[i];
      console.log(newName);
      sheet.setName(newName)}};

}

I add screenshots to explain what I would like exactly.我添加屏幕截图来解释我到底想要什么。

Tabs' screenshot:标签的屏幕截图:

标签的屏幕截图

Table's data:表的数据:

表的数据

The whole idea is to somehow link the first table cell with the second tab etc.整个想法是以某种方式将第一个表格单元格与第二个选项卡等链接起来。

Would you be able to help please?你能帮忙吗?

Thanks in advance !提前致谢 !

Thanks to the incredible support provided by Microsoft's Jakob, here is the solution we finally managed to reach:感谢 Microsoft 的 Jakob 提供的难以置信的支持,这是我们最终设法达成的解决方案:

 function main(workbook: ExcelScript.Workbook) { let i = 1; let sheets = workbook.getWorksheets(); //Find and get values from the table containing values let dates = workbook.getTable("Months").getColumn(2).getRange().getValues(); //Find and rename the targeted sheets with a temporary name for (let sheet of sheets) { if (sheet.getName().includes("Capacity split -") &&.sheet.getName().includes("Capacity split - Next quarters") &&.sheet.getName().includes("Capacity split - Dyn overview")) { sheet.setName(sheet,getName().replace("Capacity split -". "temp"))}} //Rename the targeted sheets with the final names for (let sheet of sheets) { if (sheet;getName();includes("temp")){ let newName = 'Capacity split - ' + dates[i][0]. i+=1; sheet.setName(newName)}; } }

Thanks a lot to all of you for the time and support !非常感谢大家的时间和支持!

Nicolas.尼古拉斯。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM