Google App Script | Headers and Footers | Replace text

Charles-Emmanuel Fousse Savoye

I'm trying to built a script that replace some Data in a Google Document. I'm just observing a problem. The script works well for all the body and the footers from the 2nd to the last page. My first page footer is set as different than the others but i couldn't find a way to modify its content.

Do you have any solutions ? By the way, I'm looking for a way to open the new document in my browser at the end of the script. Any solutions too ? There's a part of my script.

  var documentId = DriveApp.getFileById('1mh8yjFpy7NcjB8meXWvn1SKQofjSMcFdPqWBe4GoC14').makeCopy().getId();
  var body = DocumentApp.openById(documentId).getBody();
  var footer = DocumentApp.openById(documentId).getFooter();
  DriveApp.getFileById(documentId).setName('RM_' + RM + '_' + IDEtude + "_" + Prenom + "_" + Nom);
  
  footer.replaceText("{RM_REF}", RM);
  footer.replaceText("{PROJECT_REF}", IDEtude);

  body.replaceText("{RM_REF}", RM);
  body.replaceText("{PROJECT_REF}", IDEtude);
  body.replaceText("{NumeroBA}", numBA);
  body.replaceText('{PrenomNom}', Prenom + " " +Nom);
  body.replaceText('{adresse}', Adresse);
  body.replaceText('{code postal et ville}', CP);
  body.replaceText('{numero de telephone}', NumTel);
  body.replaceText('{CLIENT_COMPANY}', NomClient);
  body.replaceText('{DatedeFin}', DatedeFin);
  body.replaceText('{DatedeDebut}', DatedeDebut);
  body.replaceText('{FaitLe}',Date);
  body.replaceText('{Ville}',VilleCdP);

Thanks for your help !

Yuri Khristich

Try to add these three lines in your Code.gs after the line 37:

first_footer = footer.getParent().getChild(3);
first_footer.replaceText("{RM_REF}", RM);
first_footer.replaceText("{PROJECT_REF}", IDEtude);

...getParent().getChild(3) — is the hack to get access to a footer on a 'different first page' (probably it's your case)

enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to get multiple headers/footers in a document with Google Apps Script

From Dev

MigraDoc headers and footers

From Dev

True persistent footers/headers in jquerymobile

From Dev

removing headers and footers in android webview

From Dev

Perl Dancer Template headers, footers

From Dev

"ScreenUpdating = False" Not Working for Headers/Footers

From Dev

headers and footers in python-docx

From Dev

How do I replace text in a spreadsheet with Google Apps Script?

From Dev

Replace text within a cell in Google Spreadsheets using a script

From Dev

How replace text with regular expression in google apps script

From Dev

Validating response text in a Google Form with Regex in Google App Script

From Dev

How to replace text in Google Spreadsheet using App Scripts?

From Dev

IntelliJ Script to Replace Text

From Dev

Replace text with hostname script?

From Dev

Replace text with hostname script?

From Dev

How to add HTML headers and footers to a page?

From Dev

Setting margins, headers and footers for PDF without overlap

From Dev

Adding two headers and footers, one for screen and print

From Dev

OpenOffice API: How to turn off headers and footers

From Dev

Setting margins, headers and footers for PDF without overlap

From Dev

How to programmatically deny editing the headers and footers?

From Dev

Is there a way to add headers and footers to cells in a Word table?

From Dev

Angular 2 Feature Modules for Headers and Footers

From Dev

VBA Excel - Unlink headers & footers in Word

From Dev

SSRS Multiple Headers-Footers /Single List

From Dev

Get headers and footers of slides using PowerPoint Interop

From Dev

google app script regex 3 How to remove text bounded by parenthesis?

From Dev

splitting up text with a regular expression in google app script (documentApp) with findText

From Dev

find and replace text in a perl script

Related Related

  1. 1

    How to get multiple headers/footers in a document with Google Apps Script

  2. 2

    MigraDoc headers and footers

  3. 3

    True persistent footers/headers in jquerymobile

  4. 4

    removing headers and footers in android webview

  5. 5

    Perl Dancer Template headers, footers

  6. 6

    "ScreenUpdating = False" Not Working for Headers/Footers

  7. 7

    headers and footers in python-docx

  8. 8

    How do I replace text in a spreadsheet with Google Apps Script?

  9. 9

    Replace text within a cell in Google Spreadsheets using a script

  10. 10

    How replace text with regular expression in google apps script

  11. 11

    Validating response text in a Google Form with Regex in Google App Script

  12. 12

    How to replace text in Google Spreadsheet using App Scripts?

  13. 13

    IntelliJ Script to Replace Text

  14. 14

    Replace text with hostname script?

  15. 15

    Replace text with hostname script?

  16. 16

    How to add HTML headers and footers to a page?

  17. 17

    Setting margins, headers and footers for PDF without overlap

  18. 18

    Adding two headers and footers, one for screen and print

  19. 19

    OpenOffice API: How to turn off headers and footers

  20. 20

    Setting margins, headers and footers for PDF without overlap

  21. 21

    How to programmatically deny editing the headers and footers?

  22. 22

    Is there a way to add headers and footers to cells in a Word table?

  23. 23

    Angular 2 Feature Modules for Headers and Footers

  24. 24

    VBA Excel - Unlink headers & footers in Word

  25. 25

    SSRS Multiple Headers-Footers /Single List

  26. 26

    Get headers and footers of slides using PowerPoint Interop

  27. 27

    google app script regex 3 How to remove text bounded by parenthesis?

  28. 28

    splitting up text with a regular expression in google app script (documentApp) with findText

  29. 29

    find and replace text in a perl script

HotTag

Archive