Add plain text replacement from spreadsheet contents
This commit is contained in:
parent
d5d0aae48b
commit
61ff5a5cc7
19
Code.ts
19
Code.ts
@ -44,16 +44,33 @@ function copyBody(
|
||||
}
|
||||
|
||||
function generateForCurrentRow() {
|
||||
const cell = SpreadsheetApp.getActive().getCurrentCell();
|
||||
const template = DocumentApp.openById(
|
||||
'1V0uMuM80BGpjpdt1AmuzlU97tDI_u-y2rOfdl4tkqmc'
|
||||
);
|
||||
const spreadsheet = SpreadsheetApp.getActive();
|
||||
const cell = spreadsheet.getCurrentCell();
|
||||
if (!cell) throw new Error('No Cell selected for operation on row');
|
||||
|
||||
const source_doc = DocumentApp.openById(
|
||||
'1tB9--ilbfDixuQAEMk0_D6KqNFToQzs-au6NiotCH5M'
|
||||
);
|
||||
const out_doc = template; // TODO: make a copy of template, and write to that
|
||||
|
||||
// do text replacement
|
||||
// TODO: could be more efficient
|
||||
const values = spreadsheet
|
||||
.getActiveSheet()
|
||||
.getDataRange()
|
||||
.getValues();
|
||||
const headers = values[0];
|
||||
const row = values[cell.getRow() - 1];
|
||||
|
||||
headers.forEach((header, index) => {
|
||||
out_doc.getBody().replaceText(`{{${header}}}`, String(row[index]));
|
||||
out_doc.getHeader().replaceText(`{{${header}}}`, String(row[index]));
|
||||
out_doc.getFooter().replaceText(`{{${header}}}`, String(row[index]));
|
||||
});
|
||||
|
||||
const insert_point = out_doc
|
||||
.getBody()
|
||||
.findText('{{body}}')
|
||||
|
Reference in New Issue
Block a user