Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9022305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:28:27+00:00 2026-06-16T05:28:27+00:00

I am trying to make automated reports by filling a form. The data is

  • 0

I am trying to make automated reports by filling a form. The data is read out by the script from the last spreadsheet line. Then the report is made as a Google Doc. Here some tags inside this document present where the items should be. %meterx% is for meters.

These can be images or text. For normal paragraphs, this is working fine with the first loop where the type = paragraph. But it skips tables. I need to replace the %meterx% in a table cell with the image, just like I do with the paragraph, but I am stuck at the code to look through the table.

I see some ways to replace text but this seems to be the only way to replace it with images.

  var totalElements = doc.getNumChildren();
  var el=[]
  for( var j = 0; j < totalElements; ++j ) {
  var element = doc.getChild(j);
  var type = element.getType();

   if (type =='PARAGRAPH'){
      el[j]=element.getText()

      if(el[j]=='%meter3%'){element.removeFromParent();
      var newimage = UrlFetchApp.fetch('http://chart.googleapis.com/chart?chf=bg,s,67676700&chs=280x150&cht=gm&chds=0,10&chd=t:'+row[4]+'&chdlp=b').getBlob();   
      doc.insertImage(j, newimage); 

   if (type =='TABLE'){
      var tablerows=element.getNumRows();
      Logger.log(tablerows);
      for ( var i = 0; i < tablerows; ++i ) {
        var tablerow = element.getRow(0)
        Logger.log(tablerow);   // <--- gives TableRow
      }  /// STUCK !! :)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T05:28:28+00:00Added an answer on June 16, 2026 at 5:28 am

    A TableRow contains child elements, of type TableCell, which also contain child elements. Those are type PARAGRAPH if they are blank or contain text.

    You can access the text within a TableCell with getText(), but it’s a good idea to confirm that the cell contains text first.

    The code below handles PARAGRAPH and TABLE element types, and for tables it explores the TABLECELL elements. I don’t know what you’re doing with your array el[], so I’ve left that out, and also commented out the image-replacement code – instead, I’m just logging the structure and content of the table for illustration. To complete your goal, you should replace the logging with the same match & replace behavior you have for PARAGRAPH.

    NOTE: I am using a couple of helper functions not detailed here, which should be self-explanatory, getFileByName_() and elementTypeToText_().

    function Q13869576() {
      var folder = "StackOverflow";
      var docname = "Q13869576.gdoc";
      var docId = getFileByName_(folder, docname).getId();
    
      var doc = DocumentApp.openById(docId);
      var docBody = doc.getActiveSection();
    
      var totalElements = doc.getNumChildren();
      var el=[]
      for( var j = 0; j < totalElements; ++j ) {
        var element = doc.getChild(j);
        var type = element.getType();
    
        switch (type) {
          case DocumentApp.ElementType.PARAGRAPH:
            el[j]=element.getText()
    
            if(el[j]=='%meter3%'){
              Logger.log( "Found tag in paragraph" );
    //          element.removeFromParent();
    //          var newimage = UrlFetchApp.fetch('http://chart.googleapis.com/chart?chf=bg,s,67676700&chs=280x150&cht=gm&chds=0,10&chd=t:'+row[4]+'&chdlp=b').getBlob();   
    //          doc.insertImage(j, newimage);
            }
            break;
    
          case DocumentApp.ElementType.TABLE:
            var tablerows=element.getNumRows();
            Logger.log(tablerows);
            for ( var row = 0; row < tablerows; ++row ) {
              var tablerow = element.getRow(row)
              for ( var cell=0; cell < tablerow.getNumCells(); ++cell) {
                Logger.log( "Table Row("+row+") Cell ("+cell+")");
                Logger.log(
                      elementTypeToText_(tablerow.getChild(cell).getType())
                      +" with child type "
                      +elementTypeToText_(tablerow.getChild(cell).getChild(0).getType()));
                var celltext = tablerow.getChild(cell).getText();
                Logger.log( "Text is ("+celltext+")" );
              }
            }
            break;
        }
      }
    }
    

    This is an excerpt of the logs from a sample doc, with a table containing a cell with the %meter3% tag:

    ...
    Table Row(1) Cell (2)
    TABLE_CELL with child type PARAGRAPH
    Text is (%meter3%)
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a case against automated checkins to version control. My group
I am trying to make a simple script to automate and log synchronization via
im trying to make a automated tool for poulating textboxes with usernames for a
I am trying to create an automated clicker program in C# to make some
I am trying to make an automated database entry generation with Django, whenever I
I'm trying to test out Visual Studio's automated testing capabilities for a web application
I am trying to make an automated test/load test on a Silverlight based webapp.
I'm trying to make a fully-automated game engine which needs to be working based
I'm laying the groundwork for an automated build process and am trying to make
I am trying to make an Automater workflow that uses AppleScript. The workflow gets

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.