Answer the question
In order to leave comments, you need to log in
What is the problem with the data import script from google spreadsheet to google doc?
With a creak, I adapted the script for importing data from Google Spreadsheets to Google Doc, but nothing works (
Please help me figure it out)
Answer the question
In order to leave comments, you need to log in
My linter almost had its cuckoo blown off. He even thought it wasn't JS. Your code is not valid for the Google Apps Script interpreter. Here is the formatted but untested code
/* eslint-disable require-jsdoc */
/* eslint-disable no-undef */
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(
'x',
'https://docs.google.com/spreadsheets/d//edit#gid=0...'
);
inDoc.replaceText(
'x',
'https://docs.google.com/spreadsheets/d//edit#gid=0...'
);
inDoc.replaceText(
'x',
'https://docs.google.com/spreadsheets/d//edit#gid=0...'
);
inDoc.replaceText(
'x',
'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() {
// 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([]);
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;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question