首先为糟糕的礼仪或愚蠢的问题道歉,这是我第一次尝试在谷歌电子表格上编写脚本,我必须说我比在 excel 中使用 VBA 更加困难。无论如何我的问题;
我有一个四列五十三行的电子表格。列保持;周数(例如 33)、周开始日期(例如 2012 年 8 月 13 日)、工作时间(例如 31:15:00)和应付工资(例如 150.00 美元)。第一行有标题,第 2 到 53 行是一年中的第几周。露营太容易了。现在我已经设法编写了一个脚本,运行时会通过电子邮件向我发送一周的摘要电子邮件。我的代码如下;
function sendEmail() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Summary");
var startRow = 2; // First row of data to process
var numRows = sheet.getLastRow()-1; // Number of rows to process
// Fetch the range of cells A2:B3
var dataRange = sheet.getRange(startRow, 1, numRows, sheet.getLastColumn());
// Fetch values for each row in the Range.
var data = dataRange.getValues()
//Logger.log(data)
for (i in data) {
var row = data[i];
var date = new Date();
var sheetDate = new Date(row[1]);
Sdate=Utilities.formatDate(date,'GMT-1000','w')
SsheetDate=Utilities.formatDate(sheetDate,'GMT-1000', 'w')
//Logger.log(Sdate+' =? '+SsheetDate)
if (Sdate == SsheetDate){
var emailAddress = row[0]; // First column
var weeknum = row[0];
var week = row[1];
var hours = row[2];
var pay = row[3];
var subject = "Timesheet Report for Week " + weeknum;
MailApp.sendEmail('me@myemail.com',
subject,
"Chris, \n\nBased on the timesheet data you have submitted last week So and So has recorded the following hours and should be due the calculated pay.\n\n" +
"Week Beginning; " + week +
"\n\nTotal Hours Worked For The Week; " + hours +
"\n\nPay Due For The Week; " + pay);
//Logger.log('SENT :'+emailAddress+' '+subject+' '+message)
}
}
}
我现在的问题是我希望一周开始显示“8 月 13 日星期一”,总工作时间显示时间,支付显示为货币。但是,该脚本不保留电子表格中的格式。