Google 电子表格 - Google 脚本中两个日期之间的工作日数,假期除外
Google Spreadsheet - Number of working days between two dates in Google Script except holiday
谁能帮我计算两个日期之间的天数(周六、周日和节假日除外)天数?
当我 select 在 C 列完成时,Google 电子表格在下方,D 列将显示当天,但我如何才能
https://docs.google.com/spreadsheets/d/1kaYpK9LNxXptXf5WVHstYQdQm2Lc8aDoh778-I0EgoQ/edit#gid=0
/**
* Date Stamp for Task Completion and Number of Days, When Status is Updated to Complete.
*/
//CORE VARIABLES
// The column you want to check if something is entered.
var COLUMNTOCHECK = 3;
// Where you want the date time stamp offset from the input location. [row, column]
var DATETIMELOCATION = [0,1];
// Sheet you are working on
var SHEETNAME = 'PROJECTS'
// Value condition.
var VALUETOCHECK = 'Completed';
// InComing date column
var INCOMINGDATE = 1;
// Complated date column
var COMPLATEDATE = 4;
// Working days column
var WORKINGDAYLOCATION = [0,1];
function onEdit(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
//checks that we’re on the correct sheet.
if( sheet.getSheetName() == SHEETNAME ) {
var selectedCell = ss.getActiveCell();
//checks the column to ensure it is on the one we want to cause the date to appear.
if( selectedCell.getColumn() == COLUMNTOCHECK) {
if(selectedCell.getValue() == VALUETOCHECK){
var dateTimeCell = selectedCell.offset(DATETIMELOCATION[0],DATETIMELOCATION[1]);
dateTimeCell.setValue(Utilities.formatDate(new Date(), "GMT-5", "MMMM dd"))
}
}
}
}
在 E 列计算两天之间的工作天数。
非常感谢
在单元格 E1 中,输入 =NETWORKDAYS(C1, D1)
。
在E2中,=NETWORKDAYS(C2, D2)
,以此类推。
有关详细信息,请参阅此 link。
下面的脚本运行良好,但方法很聪明!
/**
* 任务完成日期戳和天数,状态更新为完成时。
*/
//CORE VARIABLES
// The column you want to check if something is entered.
var COLUMNTOCHECK = 3;
// Where you want the date time stamp offset from the input location. [row, column]
var DATETIMELOCATION = [0,1];
// Sheet you are working on
var SHEETNAME = 'PROJECTS'
// Value condition.
var VALUETOCHECK = 'Completed';
// InComing date column
var INCOMINGDATE = 1;
// Complated date column
var COMPLATEDATE = 4;
// Working days column
var WORKINGDAYLOCATION = [0,2];
function onEdit(e) {
var ss = SpreadsheetApp.getActive();
var sheet = ss.getActiveSheet();
//checks that we’re on the correct sheet.
//checks the column to ensure it is on the one we want to cause the date to appear.
if (sheet.getSheetName() == SHEETNAME) {
var selectedCell = ss.getActiveCell();
var dateTimeCell = selectedCell.offset(DATETIMELOCATION[0],DATETIMELOCATION[1]);
var dayNumberCell = selectedCell.offset(WORKINGDAYLOCATION[0],WORKINGDAYLOCATION[1]);
if (selectedCell.getColumn() == COLUMNTOCHECK){
if (selectedCell.getValue() == VALUETOCHECK) {
dateTimeCell.setValue(Utilities.formatDate(new Date(), "GMT-5", "MMMM dd"));
var incomeRow = selectedCell.getRow();
dayNumberCell.setValue("=NETWORKDAYS(A" + incomeRow + ",D" + incomeRow + ",TempDataSet!Y2:Y17)");
}
else
{
dateTimeCell.setValue("");
dayNumberCell.setValue("");
}
}
return 0;
}
}
谁能帮我计算两个日期之间的天数(周六、周日和节假日除外)天数?
当我 select 在 C 列完成时,Google 电子表格在下方,D 列将显示当天,但我如何才能
https://docs.google.com/spreadsheets/d/1kaYpK9LNxXptXf5WVHstYQdQm2Lc8aDoh778-I0EgoQ/edit#gid=0
/**
* Date Stamp for Task Completion and Number of Days, When Status is Updated to Complete.
*/
//CORE VARIABLES
// The column you want to check if something is entered.
var COLUMNTOCHECK = 3;
// Where you want the date time stamp offset from the input location. [row, column]
var DATETIMELOCATION = [0,1];
// Sheet you are working on
var SHEETNAME = 'PROJECTS'
// Value condition.
var VALUETOCHECK = 'Completed';
// InComing date column
var INCOMINGDATE = 1;
// Complated date column
var COMPLATEDATE = 4;
// Working days column
var WORKINGDAYLOCATION = [0,1];
function onEdit(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
//checks that we’re on the correct sheet.
if( sheet.getSheetName() == SHEETNAME ) {
var selectedCell = ss.getActiveCell();
//checks the column to ensure it is on the one we want to cause the date to appear.
if( selectedCell.getColumn() == COLUMNTOCHECK) {
if(selectedCell.getValue() == VALUETOCHECK){
var dateTimeCell = selectedCell.offset(DATETIMELOCATION[0],DATETIMELOCATION[1]);
dateTimeCell.setValue(Utilities.formatDate(new Date(), "GMT-5", "MMMM dd"))
}
}
}
}
在 E 列计算两天之间的工作天数。
非常感谢
在单元格 E1 中,输入 =NETWORKDAYS(C1, D1)
。
在E2中,=NETWORKDAYS(C2, D2)
,以此类推。
有关详细信息,请参阅此 link。
下面的脚本运行良好,但方法很聪明!
/**
* 任务完成日期戳和天数,状态更新为完成时。
*/
//CORE VARIABLES
// The column you want to check if something is entered.
var COLUMNTOCHECK = 3;
// Where you want the date time stamp offset from the input location. [row, column]
var DATETIMELOCATION = [0,1];
// Sheet you are working on
var SHEETNAME = 'PROJECTS'
// Value condition.
var VALUETOCHECK = 'Completed';
// InComing date column
var INCOMINGDATE = 1;
// Complated date column
var COMPLATEDATE = 4;
// Working days column
var WORKINGDAYLOCATION = [0,2];
function onEdit(e) {
var ss = SpreadsheetApp.getActive();
var sheet = ss.getActiveSheet();
//checks that we’re on the correct sheet.
//checks the column to ensure it is on the one we want to cause the date to appear.
if (sheet.getSheetName() == SHEETNAME) {
var selectedCell = ss.getActiveCell();
var dateTimeCell = selectedCell.offset(DATETIMELOCATION[0],DATETIMELOCATION[1]);
var dayNumberCell = selectedCell.offset(WORKINGDAYLOCATION[0],WORKINGDAYLOCATION[1]);
if (selectedCell.getColumn() == COLUMNTOCHECK){
if (selectedCell.getValue() == VALUETOCHECK) {
dateTimeCell.setValue(Utilities.formatDate(new Date(), "GMT-5", "MMMM dd"));
var incomeRow = selectedCell.getRow();
dayNumberCell.setValue("=NETWORKDAYS(A" + incomeRow + ",D" + incomeRow + ",TempDataSet!Y2:Y17)");
}
else
{
dateTimeCell.setValue("");
dayNumberCell.setValue("");
}
}
return 0;
}
}