I thought that from your provided image, it's the smart chips and it might be Class Date, and also, it seems that it is put into a cell of the column "B". Unfortunately, that cannot be directly retrieved using getText()
. I think that this is the reason for your issue.
But, 3 Classes for retrieving the smart chips has been added on August 23, 2021. You can retrieve the value using these Classes. If you want to retrieve the value, how about the following sample script?
Sample script:
When the table of your sample image is used, a simple sample script is as follows.
const cell = table.getCell(i, 1); // This is from your script.
const p = cell.getChild(0).asParagraph();
const c = p.getChild(0);
if (c.getType() == DocumentApp.ElementType.DATE) {
const value = c.asDate().getDisplayText();
console.log(value)
} else if (c.getType() == DocumentApp.ElementType.TEXT) {
const value = c.asText().getText();
console.log(value)
}
or, if your cells have multiple paragraphs, you can also the following sample script.
const cell = table.getCell(i, 1); // This is from your script.
for (let j = 0; j < cell.getNumChildren(); j++) {
const p = cell.getChild(j).asParagraph();
for (let k = 0; k < p.getNumChildren(); k++) {
const c = p.getChild(k);
if (c.getType() == DocumentApp.ElementType.DATE) {
const value = c.asDate().getDisplayText();
console.log(value)
} else if (c.getType() == DocumentApp.ElementType.TEXT) {
const value = c.asText().getText();
console.log(value)
}
}
}
- When
getDisplayText()
is changed to getTimestamp()
, the Date object can be retrieved instead of the string value.
References: