Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script Google电子表格中的重叠日期格式_Google Apps Script_Google Sheets_Google Spreadsheet Api - Fatal编程技术网

Google apps script Google电子表格中的重叠日期格式

Google apps script Google电子表格中的重叠日期格式,google-apps-script,google-sheets,google-spreadsheet-api,Google Apps Script,Google Sheets,Google Spreadsheet Api,我刚开始在谷歌文档上浏览这些电子表格脚本。我想编写一个脚本,查找项目之间的日期重叠(将给定单元格的bg颜色更改为红色),并创建一个新列,显示该项目类型上的冲突数。如果你能给我提供一些例子或方法,我将不胜感激 这是我的数据集 我试过的是这个。但这只适用于第一列 function formatting() { var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1'); // get the sheet

我刚开始在谷歌文档上浏览这些电子表格脚本。我想编写一个脚本,查找项目之间的日期重叠(将给定单元格的bg颜色更改为红色),并创建一个新列,显示该项目类型上的冲突数。如果你能给我提供一些例子或方法,我将不胜感激

这是我的数据集

我试过的是这个。但这只适用于第一列

function formatting() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1'); // get the sheet
  var columnF = sheet.getRange(1, 6, sheet.getLastRow(), 1).setBackgroundColor('white'); // get all the rows and clear colors
  var columnG = sheet.getRange(1, 7, sheet.getLastRow(), 1).setBackgroundColor('white'); // get all the rows and clear colors
  var fValues = columnF.getValues(); // get the values
  var gValues = columnG.getValues();
  var day = 24*3600*1000
  Logger.log(gValues)
  var startDay1 = parseInt(fValues[0][0].getTime()/day)
  var endDay1 = parseInt(gValues[0][0].getTime()/day)
  var startDay2 = parseInt(fValues[1][0].getTime()/day)
  var endDay2 = parseInt(gValues[1][0].getTime()/day)
  if (startDay1<endDay2 && startDay2<endDay1) {sheet.getRange(1, 6, 1, 1).setBackgroundColor('red')}
  else {sheet.getRange(1, 6, 1, 1).setBackgroundColor('green')}
  }
函数格式化(){
var sheet=SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');//获取工作表
var columnF=sheet.getRange(1,6,sheet.getLastRow(),1).setBackgroundColor('white');//获取所有行和清晰的颜色
var columnG=sheet.getRange(1,7,sheet.getLastRow(),1).setBackgroundColor('white');//获取所有行和清晰的颜色
var fValues=columnF.getValues();//获取值
var gValues=columnG.getValues();
var日=24*3600*1000
Logger.log(gValue)
var startDay1=parseInt(fValues[0][0].getTime()/day)
var endDay1=parseInt(gValue[0][0].getTime()/day)
var startDay2=parseInt(fValues[1][0].getTime()/天)
var endDay2=parseInt(gValue[1][0].getTime()/day)

if(startDay1循环遍历每一行所需的代码。不确定您要如何处理上一个项目,因为没有可与之比较的日期

保持标记为红色的项目计数的简单方法是创建一个javascript对象(多个项目),并存储每个项目及其计数。以下是一些有关javascript对象的文档:

函数格式化(){
试一试{
var sheet=SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');//获取工作表
//将需要项目类型的列
var项目={};
var eValues=sheet.getRange(1,5,sheet.getLastRow(),1.getValues();
var columnF=sheet.getRange(1,6,sheet.getLastRow(),1).setBackgroundColor('white');//获取所有行和清晰的颜色
var columnG=sheet.getRange(1,7,sheet.getLastRow(),1).setBackgroundColor('white');//获取所有行和清晰的颜色
var fValues=columnF.getValues();//获取值
var gValues=columnG.getValues();
var日=24*3600*1000
Logger.log(gValue)
//循环遍历数据集中的所有行
对于(var r=0;r<(fValues.length-1);r++){
var startDay1=parseInt(fValues[r][0].getTime()/day);
var endDay1=parseInt(gvalue[r][0].getTime()/day);
var startDay2=parseInt(fValues[(r+1)][0].getTime()/天;
var endDay2=parseInt(gValues[(r+1)][0].getTime()/day);

如果(开始日期1如果有人感兴趣,这里是答案

function formatting(m, d) {
    try {
        var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1'); // get the sheet
        var output = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet2'); // output sheet        
        output.clear()

        // Going to need the column for project type
        var counts = {};
        var eValues = sheet.getRange(1, 3, sheet.getLastRow(), 1).getValues();
        var columnF = sheet.getRange(1, 1, sheet.getLastRow(), 1).setBackgroundColor('white'); // get all the rows and clear colors
        var columnG = sheet.getRange(1, 2, sheet.getLastRow(), 1).setBackgroundColor('white'); // get all the rows and clear colors
        var columnD = sheet.getRange(1, 4, sheet.getLastRow(), 1).setBackgroundColor('white').clearContent(); // get all the rows and clear colors
        var columnCritical = sheet.getRange(1, 7, sheet.getLastRow(), 1).setBackgroundColor('white').clearContent(); // get all the rows and clear colors
        var fValues = columnF.getValues(); // get the values
        var gValues = columnG.getValues();
        var day = 24 * 3600 * 1000


        // loop through all the rows in the dataset


        for (var r = 0; r < (fValues.length - 1); r++) {

                var startDay1 = parseInt(fValues[r][0].getTime() / day);
                var endDay1 = parseInt(gValues[r][0].getTime() / day);

                // loop through all the rows for given date

                for (var z = 0; z < (fValues.length - 1); z++) {

                    var startDay2 = parseInt(fValues[(z)][0].getTime() / day);
                    var endDay2 = parseInt(gValues[(z)][0].getTime() / day);

                    // if the date is the same go to the next one
                    if (startDay1 == startDay2 && endDay2 == endDay1) continue;

                    // check for conflicts
                    else if (startDay1 < endDay2 && startDay2 < endDay1) {

                        //Here is our conflict!!!;



                        var projectn = r + 1
                        if (counts[projectn] !== undefined) { // strict(!) comparison
                            // add one to this projects count
                            counts[projectn] += 1;
                        } else {
                            // create the first count for this project
                            counts[projectn] = 1;
                        }
                    } else {
                    // if there is no conflict
                    }
                } //end of for loop for var z

                // change the background of the counts to red and set values
                if (counts[r + 1] == undefined) {
                    sheet.getRange(r + 1, 4, 1, 1).setValue(counts[r + 1]).setBackground('green');
                } else {
                    sheet.getRange(r + 1, 4, 1, 1).setValue(counts[r + 1]).setBackground('red');
                }
        } // end of for loop for var r


        // show if there is any errors 
    } catch (e) {
        Logger.log(e.lineNumber + ' - ' + e);
    }
}
函数格式(m,d){
试一试{
var sheet=SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');//获取工作表
var output=SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet2');//输出工作表
output.clear()
//将需要项目类型的列
变量计数={};
var eValues=sheet.getRange(1,3,sheet.getLastRow(),1.getValues();
var columnF=sheet.getRange(1,1,sheet.getLastRow(),1).setBackgroundColor('white');//获取所有行和清晰的颜色
var columnG=sheet.getRange(1,2,sheet.getLastRow(),1).setBackgroundColor('white');//获取所有行和清晰的颜色
var columnD=sheet.getRange(1,4,sheet.getLastRow(),1).setBackgroundColor('white').clearContent();//获取所有行和清晰颜色
var columnCritical=sheet.getRange(1,7,sheet.getLastRow(),1).setBackgroundColor('white').clearContent();//获取所有行和清晰颜色
var fValues=columnF.getValues();//获取值
var gValues=columnG.getValues();
var日=24*3600*1000
//循环遍历数据集中的所有行
对于(var r=0;r<(fValues.length-1);r++){
var startDay1=parseInt(fValues[r][0].getTime()/day);
var endDay1=parseInt(gvalue[r][0].getTime()/day);
//循环浏览给定日期的所有行
对于(var z=0;z<(fValues.length-1);z++){
var startDay2=parseInt(fValues[(z)][0].getTime()/天;
var endDay2=parseInt(gValues[(z)][0].getTime()/day);
//如果日期相同,则转到下一个日期
如果(startDay1==startDay2&&endDay2==endDay1)继续;
//检查是否存在冲突
否则如果(开始日期1
欢迎使用SO。在大多数情况下,我们不会为您工作,除非您已经向我们提供了您迄今为止所做的工作。请提供。欢迎使用SO,请在发布之前阅读…您的
function formatting(m, d) {
    try {
        var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1'); // get the sheet
        var output = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet2'); // output sheet        
        output.clear()

        // Going to need the column for project type
        var counts = {};
        var eValues = sheet.getRange(1, 3, sheet.getLastRow(), 1).getValues();
        var columnF = sheet.getRange(1, 1, sheet.getLastRow(), 1).setBackgroundColor('white'); // get all the rows and clear colors
        var columnG = sheet.getRange(1, 2, sheet.getLastRow(), 1).setBackgroundColor('white'); // get all the rows and clear colors
        var columnD = sheet.getRange(1, 4, sheet.getLastRow(), 1).setBackgroundColor('white').clearContent(); // get all the rows and clear colors
        var columnCritical = sheet.getRange(1, 7, sheet.getLastRow(), 1).setBackgroundColor('white').clearContent(); // get all the rows and clear colors
        var fValues = columnF.getValues(); // get the values
        var gValues = columnG.getValues();
        var day = 24 * 3600 * 1000


        // loop through all the rows in the dataset


        for (var r = 0; r < (fValues.length - 1); r++) {

                var startDay1 = parseInt(fValues[r][0].getTime() / day);
                var endDay1 = parseInt(gValues[r][0].getTime() / day);

                // loop through all the rows for given date

                for (var z = 0; z < (fValues.length - 1); z++) {

                    var startDay2 = parseInt(fValues[(z)][0].getTime() / day);
                    var endDay2 = parseInt(gValues[(z)][0].getTime() / day);

                    // if the date is the same go to the next one
                    if (startDay1 == startDay2 && endDay2 == endDay1) continue;

                    // check for conflicts
                    else if (startDay1 < endDay2 && startDay2 < endDay1) {

                        //Here is our conflict!!!;



                        var projectn = r + 1
                        if (counts[projectn] !== undefined) { // strict(!) comparison
                            // add one to this projects count
                            counts[projectn] += 1;
                        } else {
                            // create the first count for this project
                            counts[projectn] = 1;
                        }
                    } else {
                    // if there is no conflict
                    }
                } //end of for loop for var z

                // change the background of the counts to red and set values
                if (counts[r + 1] == undefined) {
                    sheet.getRange(r + 1, 4, 1, 1).setValue(counts[r + 1]).setBackground('green');
                } else {
                    sheet.getRange(r + 1, 4, 1, 1).setValue(counts[r + 1]).setBackground('red');
                }
        } // end of for loop for var r


        // show if there is any errors 
    } catch (e) {
        Logger.log(e.lineNumber + ' - ' + e);
    }
}