I believe your goal as follows.
- You want to modify the text style in the texts in the cells of the table.
- You want to achieve this using Google Apps Script.
For this, how about this answer?
In this case, the following flow is used.
- Retrieve the text object from each cell using
editAsText().
- For the retrieved text object, modify the text style using
setBackgroundColor, setForegroundColor, setBold, setFontFamily and so on.
Sample script:
In this sample script, a table with 2 x 2 cells is appended to the document body. And, the text styles of cells "A1" and "B2" are modified.
function myFunction() {
var body = DocumentApp.getActiveDocument().getBody();
var cells = [
['This is my text', 'Row 1, Cell 2'],
['Row 2, Cell 1', 'Some more text']
];
var table = body.appendTable(cells);
// Modify the text style of the cell "A1".
table.getCell(0, 0).editAsText()
.setBackgroundColor(0, 7, "#FFFF00")
.setForegroundColor(5, 9, "#FF0000")
.setBackgroundColor(8, 14, "#00BFFF")
.setBold(8, 14, true);
// Modify the text style of the cell "B2".
table.getCell(1, 1).editAsText()
.setFontFamily(5, 13, "IMPACT")
.setBackgroundColor(5, 13, "#00BFFF")
.setBold(5, 13, true);
}
- For example, when you want to modify the background color of text, please use
setBackgroundColor(startOffset, endOffsetInclusive, color). Ref When the text style of This is is modified, please use setBackgroundColor(0, 7, "#FFFF00").
Result:
When above sample script is run, the following result can be obtained.

References: