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
What would be an ideal way for me to update a cell value in Google Slides using an App Script?
CodePudding user response:
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);