English 中文(简体)
谷歌。 原文取代。 未生效的案文
原标题:Google.App.Script replace.Text not working

我对此非常新,但希望得到任何帮助。 我试图采用电子表格,并将案文改为使用替代案文的斜体。 一切似乎都是在工作,它会产生奇迹,将其保留在指定文件夹中,其标题是正确的,但实际的谷歌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.

问题回答

我缩小了该法典的规模,但基本上没有改变。 我确实从一开始就消灭了头盔,因此没有必要再对他们进行ski。 我发现,该法典没有任何问题。

function createNewGoogleDocs() {
  const googleDocTemplate = DriveApp.getFileById(gobj.globals.testdocid);//replace id
  const destinationFolder = DriveApp.getFolderById(gobj.globals.folder1id);//replace id
  const ss = SpreadsheetApp.getActive();
  const sheet = ss.getSheetByName( Sheet0 );//replace sheet
  const [,...vs] = sheet.getDataRange().getValues();//removed header

  vs.forEach((r, i) => {
    if(r[8])return;//not sure what this is for except maybe to show that it already has a url so a copy may have been made already
    const copy = googleDocTemplate.makeCopy(`CC_${r[0]}_${r[1]}`, destinationFolder);
    const doc = DocumentApp.openById(copy.getId());
    const body = doc.getBody();
    const dts = new Date(r[4]).toLocaleDateString();
    body.replaceText( {{COL1}} ,r[0]);
    body.replaceText( {{COL2}} ,r[1]);
    body.replaceText( {{COL3}} ,r[2]);
    body.replaceText( {{COL4}} ,r[3]);
    body.replaceText( {{COL5}} ,dts);
    body.replaceText( {{COL6}} ,r[5]);
    body.replaceText( {{COL7}} ,r[6]);
    body.replaceText( {{COL8}} ,r[7]);
    doc.saveAndClose();
    const url = doc.getUrl();
    sheet.getRange(i+2,9).setValue(url);//changed the offset because I removed the headers
  })
}




相关问题
Forcing a datatype in MS Access make table query

I have a query in MS Access which creates a table from two subqueries. For two of the columns being created, I m dividing one column from the first subquery into a column from the second subquery. ...

How to convert / cast long to String?

I just created sample BB app, which can allow to choose the date. DateField curDateFld = new DateField("Choose Date: ", System.currentTimeMillis(), DateField.DATE | DateField.FIELD_LEFT); After ...

Converting an Integer to Enum in PostgreSQL

I have created a custom data type enum like so: create type "bnfunctionstype" as enum ( normal , library , import , thunk , adjustor_thunk ); From an external data ...

Convert Session Object to IOrderedQueryable<T>

I need to convert a Session object to an IOrderedQueryable and came up blank. I ve thought of creating a wrapper, but its not working properly. Basically, I am pulling a Linq query and would like to ...

WPF binding with explicit conversion

My question may be a repeat of other conversion question but I feel mine is different. Here goes... [simplified example]. public class DataWrapper<T> { public T DataValue{ get; set; } ...

String in scientific notation C++ to double conversion

I ve got a database filled up with doubles like the following one: 1.60000000000000000000000000000000000e+01 Does anybody know how to convert a number like that to a double in C++? Is there a "...

热门标签