问题描述
下面的代码工作。它会将我的工作表重命名为单元格的值。但就新项目而言,该单元的价值恰巧是2012年8月4日的日期。如果我运行下面的代码,表格会重命名为Sat Aug 04 2012 02:00:00 GMT-0500(CDT)。如何调整下面的代码,所以表的名称只反映8/4/2012
//下面的代码会将活动工作表重命名为上一个生产周的日期
var myValue = SpreadsheetApp.getActiveSheet().getRange(P1)。getValue();
SpreadsheetApp.getActiveSpreadsheet()。renameActiveSheet(myValue);
您应该使用以获得您想要的格式。
在你的代码中应该是
pre $ SpreadsheetApp.getActiveSpreadsheet()。renameActiveSheet(Utilities.formatDate( myValue,GMT,MM / dd / yyyy));
如果您不在GMT,请不要忘记更改,因为即使您没有使用小时它有时会弄乱你的日期; - )
The below code works. It will rename my worksheet to a cell's value. But in the case of a new project, the cell's value happens to be a date 8/4/2012 for example. If i run the below code, the sheet gets renamed to "Sat Aug 04 2012 02:00:00 GMT-0500 (CDT)".
How can i adjust the below code so the sheet's name reflects only "8/4/2012"
// The code below will rename the active sheet to last production week's date
var myValue = SpreadsheetApp.getActiveSheet( ).getRange("P1").getValue();
SpreadsheetApp.getActiveSpreadsheet().renameActiveSheet(myValue);
You should use Utilities.formatDate() to get the format you want.
in your code it should be
SpreadsheetApp.getActiveSpreadsheet().renameActiveSheet(Utilities.formatDate(myValue, "GMT", "MM/dd/yyyy"));
if you're not in GMT don't forget to change that since even if you don't use hours it will mess up your dates sometimes ;-)
这篇关于将工作表重命名为单元格值保持格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!