如何根据单元格信息更改Google表格文件名 [英] How to change Google Sheets file name based on cell information

查看:83
本文介绍了如何根据单元格信息更改Google表格文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据至少一个单元格的内容重命名我的Google表格文件名(理想情况下,它将是来自两个单元格B2和D2的信息的组合,但我可以使一个单元格的内容正常工作).

I am trying to rename my Google Sheets File name based on contents of at least one cell (ideally, it would be a combination of information from two cells: B2 and D2, but I can make contents of one cell work).

我能够从一个单元格的内容中更改工作表名称,但正在努力更改实际的文件名.

I am able to change the worksheet name from the contents of one cell, but am struggling to change the actual file name.

推荐答案

要更改电子表格的名称,您也将需要DriveApp并更改其文件名.试试这个例子:

To change the Spreadsheet's name you will need DriveApp too and change its filename. Try this example:

// get the active spreadsheet
var ss = SpreadsheetApp.getActiveSpreadsheet();

// get a value from the B2 cell on sheet "Sheet" as new filename
var newFileName = ss.getRange("Sheet!B2").getValue();

// get the spreadsheet ID
var ssID = ss.getId();

// get the spreadsheet file by ID
var ssFile = DriveApp.getFileById(ssID);

 // set new filename for the spreadsheet
ssFile.setName(newFileName);

这篇关于如何根据单元格信息更改Google表格文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆