function doAction() {
var result = ReadBaseData("22-05-2019");
//If found data for this date...
if (result != null ) {
var doc = CreateNewDoc(" iskovoe " + result[0][0]);
FillTemplate(doc, result);
}
}
//inDoc - its a empty template, inData - data for filling template
function FillTemplate(inDoc, inData) {
//Getting count of files in folder
var NUM = DocsList.getFolderById(1a3uCa9wRyOzio-C7FVacOykuLoxCqTs3).getFiles().length;
//Replace masks (Don't work [NUM] or $NUM or something else)
inDoc.replaceText("",
https://docs.google.com/spreadsheets/d//edit#gid=0...
inDoc.replaceText("",
https://docs.google.com/spreadsheets/d//edit#gid=0...
inDoc.replaceText("",
https://docs.google.com/spreadsheets/d//edit#gid=0...
inDoc.replaceText("",
https://docs.google.com/spreadsheets/d//edit#gid=0...
inDoc.replaceText("",
https://docs.google.com/spreadsheets/d//edit#gid=0...
//get first table in document
var table = curDoc.getTables()[0];
for (i=0; i< inData.length; i++) {
var row = table.appendTableRow();
row.appendTableCell(inData[i][1]);
row.appendTableCell(inData[i][2]);
}
curDoc.saveAndClose();
}
function CreateNewDoc(docName) {
//Making copy of blank file
var blankDoc = DocsList.getFileById(19vYiThaKdgQ6eeiRg5nPewzP_Eab7nkLUwyt49jCC1Q).makeCopy(iskovoe);
blankDoc.addToFolder(DocsList.getFolderById(1a3uCa9wRyOzio-C7FVacOykuLoxCqTs3));
//return working doc and table base
return curDoc = DocumentApp.openById(blankDoc.getId());
}
//get range and sort only for day from parameter
function ReadBaseData(inDate) {
var ssDoc = SpreadsheetApp.openById(1ZCNO6Iae2RwDdKAlQX6TF5mpp4xHHB4v1mXK233uJls).getActiveSheet();
//get filled range
var data = ssDoc.getDataRange().getValues();
//create new array with data to inDate,
//for start from 1 because first row is text column headers
var filteredData = new Array( new Array() );
for (i=1; i< data.length; i++) {
data[i][0] = convertDate(data[i][0]);
if (data[i][0] == inDate && data[i][3] == 1) {
filteredData[i-1] = data[i];
}
}
return filteredData;
}