我正在尝试创建一个脚本,以自动从Google表格中获取信息,并将每一行数据放入单独的格式化文档中。但是,当我运行脚本时,它要么将数据填充为“ DOB”(在出生日期),要么填充为其他值。我不是一个很好的程序员,我们将不胜感激。谢谢,
function createDocument() {
var headers =Sheets.Spreadsheets.Values.get('1oycOOxDIAhbAI6Yq54KF4GAnjfVcttywYXOpKDBLHag', ('A1', 'B1', 'C1', 'D1', 'H1', 'I1', 'N1', 'O1'));
var tactics = Sheets.Spreadsheets.Values.get('1oycOOxDIAhbAI6Yq54KF4GAnjfVcttywYXOpKDBLHag', ('A4:O14'));
var templateId = '1NJQHx4TWRQ3EQle5aLr-QV4uqD-tSR8TMP2-f6QjPmY';
for(var i = 0; i < tactics.values.length; i++){
var Patient_name = tactics.values[i][0];
var Date_Scheduled = tactics.values[i][0];
var Surgery_Posting = tactics.values[i][0];
var Start_Time = tactics.values[i][0];
var Hospital = tactics.values[i][0];
//Make a copy of the template file
var documentId = DriveApp.getFileById(templateId).makeCopy().getId();
//Rename the copied file
DriveApp.getFileById(documentId).setName(Patient_name + ' Surgery Posting');
//Get the document body as a variable
var body = DocumentApp.openById(documentId).getBody();
//Insert the Patient_name
body.replaceText('##Patient_name##', Patient_name)
//Insert the Date_Scheduled
body.replaceText('##Date_Scheduled##', Date_Scheduled)
//Insert the Surgery_Posting
body.replaceText('##Surgery_Posting##', Surgery_Posting)
//Insert the Start_Time
body.replaceText('##Start_Time##', Start_Time)
//Insert the Hospital
body.replaceText('##Hospital##', Hospital)
//Append tactics
parseTactics(headers.values[0], tactics.values[i], body);
}
}
function parseTactics(headers, tactics, body){
for(var i = 0; i < tactics.length; i++){
{tactics[i] != '' &&
body.appendListItem(headers[i] + ' | ' + tactics[i] + ' net').setGlyphType(DocumentApp.GlyphType.BULLET);
}
}
}
答案 0 :(得分:0)
迭代器之后的列位置未更改为下一列。
var Patient_name = tactics.values[i][0];
var Date_Scheduled = tactics.values[i][1]; //this last part the 0 to 1