Search code examples
google-docs

Are there any methods to modifying properties of all tables at a time for google docs?


I have written a article in my google docs.

I have included small tables, big tables and huge tables in different places in the files.

Now I need to modify some properties of all tables at a time.

But that seems not possible?

Are there any methods to modifying properties of all tables at a time for google docs?

PS. more details to illustrate my issue:

1. Here is a doc file with one table. enter image description here

2. Right click on the table and choose Table properties enter image description here

3. Now here comes more tables in a doc file enter image description here

How can I deal with all the tables together? (All modifications are the same)


Solution

  • Method 1

    When creating the tables, you can simply set all the properties on the first one and then for the next ones you can copy and paste the first one since the format will be kept.

    Method 2

    If you want to modify more tables at the same time, you can make use of Apps Script.

    Apps Script is a powerful development platform which can be used to build web apps and automate tasks. What makes it special is the fact that it is easy to use and to create applications that integrate with G Suite.

    Therefore, your task can be achieved by using this script.

    Snippet

    function setTableProperties() {
      var doc = DocumentApp.openById("DOCUMENT_ID");
      var tables = doc.getBody().getTables();
    
      tables.forEach((table) => {
        //Any instruction run with the variable table will be executed for all tables.
      });
    }
    
    

    Explanation

    The above script gathers all the tables from the wanted document and then using a for loop accesses each table from the document.

    In order to set the properties of the tables as wanted, you just have to use the appropriate method/s.

    The getAttributes method can be used as well in order to see exactly which properties does a table posses.

    Reference