How do I loop through all the cells in a table, selecting text in each cell based on Regex criteria, and format those cells?
EDIT: I can set row attributes using table.getRow(n).getCell(n)
but how do I format specific text in each cell?
I need to make the name appearing at the start of each cell bold:
Here's the sample doc.
I believe your goal is as follows.
Monserrat Banks
of Monserrat Banks: Fringilla dolor ultricies aliquam dolor.
to the bold type in a table on Google Document.In this case, how about the following sample script?
Please copy and paste the following script to the script editor of Google Document and run the script.
function myFunction() {
const table = DocumentApp.getActiveDocument().getBody().getTables()[0];
const rows = table.getNumRows();
for (let r = 0; r < rows; r++) {
const row = table.getRow(r);
const cols = row.getNumCells();
for (let c = 0; c < cols; c++) {
const cell = row.getCell(c);
const f = cell.findText(".*:");
if (!f) continue;
cell.editAsText().setBold(f.getStartOffset(), f.getEndOffsetInclusive() - 1, true);
}
}
}
When this script is run to your provided Google Document, the following result is obtained.