Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to add table cell value in Google Slides using script?

I am trying to update the value of a table cell in Google Slides using Google App Script.

Here is the code.

function calculateResourceCapacity() {
  const FIXED_ROWS = 4;
  const COL_AVA_PD = 2;

  const presentation = SlidesApp.getActivePresentation();

  const monthPD = 24;
  const slide = presentation.getSelection().getCurrentPage();

  const elements = slide.getPageElements();
  for (let i = 0; i < elements.length; ++i) {
    try {
      const table = elements[i].asTable();

      const cResource = table.getColumn(0);
      const lastRowIdx = cResource.getNumCells() - FIXED_ROWS;

      for (let i = 1; i <= lastRowIdx; ++i) {
        // This line fails to execute in Google Slides
        const cell = table.getCell(i, COL_AVA_PD).editAsText().setText(monthPD);
      }

      break;
    } catch(e) { }
  }
}

Unlike Google Docs, the TableCell object does not have editAsText() method in Google Slides.
Documentation: https://developers.google.com/apps-script/reference/slides/table-cell

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

What would be an ideal way for me to update a cell value in Google Slides using an App Script?

>Solution :

In your script, how about the following modification?

From:

const cell = table.getCell(i, COL_AVA_PD).editAsText().setText(monthPD);

To:

const cell = table.getCell(i, COL_AVA_PD);
cell.getText().setText(monthPD);

References:

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading