简体   繁体   English

无法将我的 output 文件保存为基于谷歌应用脚本中电子表格单元格的名称

[英]Having trouble save my output file as name based on cell from spreadsheet in google apps scripts

Here's my code which was done mostly by a much talented coder then me:这是我的代码,主要由一位才华横溢的编码人员完成,然后是我:

function SaveSpreadsheetAs(){
  
var Sheet=SpreadsheetApp.getActiveSpreadsheet();
var Peter=Sheet.getSheetByName("Peter");        
var Filename=Peter.getRange(2,2,1,1).getValue();
  //Folder to save pay periods on google drive
 var destFolder = DriveApp.getFolderById("es3424kbjb4j32wbryujb3r"); 
              
 DriveApp.getFileById("093hnweuibf2873bfuiww").makeCopy(Filename,destFolder); 

 }

My question is why is (var Filename)'s output not the value of the B2 cell from the sheet name "Peter"?我的问题是为什么(var Filename)的 output 不是工作表名称“Peter”中 B2 单元格的值? I know I am making a very basic level mistake as I am very new to this but what am I missing.我知道我犯了一个非常基本的错误,因为我对此很陌生,但我错过了什么。 The code works if you change the (var Filename) with a text entry.如果您使用文本条目更改 (var Filename),则该代码有效。 Thank you in advanced.提前谢谢你。

I ran it this way.我是这样运行的。 It runs fine.它运行良好。

function SaveSpreadsheetAs() {
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const sh = ss.getSheetByName(gobj.globals.targetsh);
  const Filename = Utilities.formatDate(new Date(sh.getRange(2, 2).getValue()),ss.getSpreadsheetTimeZone(),"MMM-dd-yyyy HH:mm:ss");
  const destFolder = DriveApp.getFolderById(gobj.globals.testfolderid);
  const file=DriveApp.getFileById(gobj.globals.testsourceid).makeCopy(Filename, destFolder);
  Logger.log(file.getName());
}

Execution log
5:40:56 PM  Notice  Execution started
5:41:01 PM  Info    Apr-25-2021 17:40:41
5:41:01 PM  Notice  Execution completed

gobj is a global object I use so that I don't have to remove my ids gobj 是我使用的全局 object,因此我不必删除我的 ID

Data Sheet:数据表:

4/25/2021 17:40:41 2021 年 4 月 25 日 17:40:41

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

相关问题 Google Apps脚本-上传文件并将数据发布到电子表格 - Google Apps Scripts- Upload File And Post Data To Spreadsheet Google Apps 脚本 - 将 gmail 中的数据提取到电子表格中 - Google Apps Scripts - Extract data from gmail into a spreadsheet 在我的脚本中基于布尔值更新DOM时遇到问题 - Having trouble updating DOM based on boolean value in my scripts 将 json/csv 文件(从 API 获取)保存到电子表格文档而不使用循环 - Google Apps 脚本 - Save a json/csv file (fetched from an API) to a spreadsheet document without using a loop - Google Apps Script Google Apps电子表格脚本会随机停止? - Google Apps Spreadsheet Scripts Randomly Stopping? Google脚本会根据日期将范围从一个电子表格复制到另一个电子表格 - Google scripts copy range from one spreadsheet to another based on date 表格脚本 - 另存为 PDF - 从单元格中提取文件名 - Sheets Scripts- Save As PDF- Pull File Name from Cell 在 Google Apps 脚本中处理日期时遇到问题 - Having trouble working with dates in Google Apps Script Google Apps 脚本(电子表格) - 根据单元格中的条件选择电子表格中的数组 - Google Apps Script (Spreadsheet) - selecting an array in spreadsheet based on a condition in cells 根据单元格的内容隐藏行-Google Spreadsheet - Hide Rows Based on Content of a Cell - Google Spreadsheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM