DateFinder is a GAS library for searching the date objects from the cell range on the sheet in the Spreadsheet and retrieving the searched range as the RangeList object using Google Apps Script (GAS).
There is the Class TextFinder for searching the text from cells of the Spreadsheet using the Google Apps Script. But in this case, the date object in the cell is used as the string. Namely, the values for searching are used as the same with the values retrieved by getDisplayValues()
. So for example, when there are the date objects in the cells with the various formats, the date cannot be searched by the Class TextFinder. So I created this library. When this library is used, the date objects in the cells can be retrieved by the date object and/or the range between 2 dates.
17ghJiHk43mDeFqYYQRc7YMfTRv9hMNk0dkJ2rudZmJUMaopR0gvS9B01
Methods | Description |
---|---|
search(object) | Search date objects and return RangeList object. |
In order to use this library, please install this library as follows.
-
Create a GAS project.
- You can use this library for the GAS project of both the standalone type and the container-bound script type.
-
- Library's project key is
17ghJiHk43mDeFqYYQRc7YMfTRv9hMNk0dkJ2rudZmJUMaopR0gvS9B01
.
- Library's project key is
This library use the scope of https://www.googleapis.com/auth/spreadsheets
.
In this method, the date objects in the cells are searched from the sheet of Spreadsheet.
var spreadsheetId = "###";
var sheetName = "Sheet1";
var sheet = SpreadsheetApp.openById(spreadsheetId).getSheetByName(sheetName);
var range = sheet.getRange("A1:C10");
var from = new Date();
from.setDate(from.getDate() - 1);
var to = new Date();
var object = { sheet: sheet, range: range, from: from, to: to };
var res = DateFinder.search(object);
res.getRanges().forEach(function(range) {
Logger.log("%s, %s", range.getA1Notation(), range.getValue());
});
-
In this sample script, the ranges and values of date from "now" to "now - 1" day are retrieved from the range of "A1:C10" on "Sheet1" in the Spreadsheet of "###".
-
DateFinder.search(object)
returns RangeList. -
If
var object = { sheet: sheet, range: range, from: from};
is used, all date values afterfrom
are retrieved. -
If
var object = { sheet: sheet, range: range, to: to};
is used, all date values beforeto
are retrieved. -
If
var object = { sheet: sheet, range: range, date: date};
is used, date values which are the same withdate
are retrieved. -
If
var object = { sheet: sheet, date: date};
is used, date values which are the same withdate
are retrieved from the data range onsheet
. -
If
var object = { range: range, date: date};
is used, date values which are the same withdate
are retrieved fromrange
on the active sheet of the active Spreadsheet.. -
If
var object = {date: date};
is used, date values which are the same withdate
are retrieved from the data range on the active sheet of the active Spreadsheet. -
When
from
,to
anddate
are required to be the date object. -
When all
from
,to
anddate
are not included in the object, an error occurs. -
When the results don't match with the search parameter,
null
is returned.
var spreadsheetId = "###";
var sheetName = "Sheet1";
var sheet = SpreadsheetApp.openById(spreadsheetId).getSheetByName(sheetName);
var obj = { sheet: sheet, date: new Date("2020/01/01") };
var res = DateFinder.search(obj);
res.setBackground("red");
- In this sample script, the ranges and values of
date
(In this case, it's2020/01/01 00:00:00
.) are retrieved from the data range on "Sheet1" in the Spreadsheet of "###". And the background color of searched range is changed to the red color.
If you have any questions and commissions for me, feel free to tell me.
-
v1.0.0 (January 30, 2020)
- Initial release.