我对此非常新,但希望得到任何帮助。 我试图采用电子表格,并将案文改为使用替代案文的斜体。 一切似乎都是在工作,它会产生奇迹,将其保留在指定文件夹中,其标题是正确的,但实际的谷歌Doc没有取代案文。 我有三倍的核对拼凑,但我看不出错误。 我不敢确定问题在哪里。
function onOpen() {
const ui = SpreadsheetApp.getUi();
const menu = ui.createMenu( AutoFill Docs );
menu.addItem( Create New Docs , createNewGoogleDocs );
menu.addToUi();
}
function createNewGoogleDocs() {
const googleDocTemplate = DriveApp.getFileById( 1UqtS6Uw4JU59IizIHZwncJjuSftKOsQH );
const destinationFolder = DriveApp.getFolderById( 1avJUSvwJoA31evoNzngcLJiZfympFCWe );
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName( Sheet1 );
const rows = sheet.getDataRange().getValues();
rows.forEach(function(row, index) {
if(index === 0)return;
if(row[29])return;
const copy = googleDocTemplate.makeCopy(`CC_${row[0]}_${row[1]}`, destinationFolder);
const doc = DocumentApp.openById(copy.getId());
const body = doc.getBody();
const friendlyDate = new Date(row[4]).toLocaleDateString();
body.replaceText( {{Full Name}} ,row[0]);
body.replaceText( {{Position}} ,row[1]);
body.replaceText( {{Yrs of Experience}} ,row[2]);
body.replaceText( {{Nationality}} ,row[3]);
body.replaceText( {{Date of Birth}} ,friendlyDate);
body.replaceText( {{Languages}} ,row[5]);
body.replaceText( {{Profile Summary}} ,row[6]);
body.replaceText( {{Qualifications}} ,row[7]);
body.replaceText( {{Skills}} ,row[8]);
body.replaceText( {{Emp1 Date}} ,row[9]);
body.replaceText( {{Emp1 Name}} ,row[10]);
body.replaceText( {{Emp1 Position}} ,row[11]);
body.replaceText( {{Emp1 Resp}} ,row[12]);
body.replaceText( {{Emp2 Date}} ,row[13]);
body.replaceText( {{Emp2 Name}} ,row[14]);
body.replaceText( {{Emp2 Position}} ,row[15]);
body.replaceText( {{Emp2 Resp}} ,row[16]);
body.replaceText( {{Emp3 Date}} ,row[17]);
body.replaceText( {{Emp3 Name}} ,row[18]);
body.replaceText( {{Emp3 Position}} ,row[19]);
body.replaceText( {{Emp3 Resp}} ,row[20]);
body.replaceText( {{Emp4 Date}} ,row[21]);
body.replaceText( {{Emp4 Name}} ,row[22]);
body.replaceText( {{Emp4 Position}} ,row[23]);
body.replaceText( {{Emp4 Resp}} ,row[24]);
body.replaceText( {{Emp5 Date}} ,row[25]);
body.replaceText( {{Emp5 Name}} ,row[26]);
body.replaceText( {{Emp5 Position}} ,row[27]);
body.replaceText( {{Emp5 Resp}} ,row[28]);
doc.saveAndClose();
const url = doc.getUrl();
sheet.getRange(index+1,29).setValue(url);
})
}
I am trying to take a spreadsheet and convert the text into a doc using replace text.