I believe your goal is as follows.
- You want to retrieve the values of table cells.
- The values of table cells are the dropdown list of the smart chips.
Issue and workaround:
Unfortunately, in the current stage, it seems that there are no built-in methods of Google Apps Script for directly retrieving the values of the dropdown list of the smart chips. When getType()
is used, UNSUPPORTED
is returned as you have already mentioned in the comment. And also, even when Google Docs API is used, "content": "\n",
is returned. In this case, I would like to recommend reporting this to the Google issue tracker as a future request.
From the above situation, I would like to propose a workaround. In this workaround, the Google Document is converted to DOCX data. And, the DOCX data is converted to Google Document. By this conversion, the texts of the smart chips can be retrieved. When this flow is reflected in a script, it becomes as follows.
Sample script:
Please copy and paste the following script to the script editor of Google Document. And, please enable Drive API at Advanced Google services.
function myFunction() {
const doc = DocumentApp.getActiveDocument();
const id = doc.getId();
const url = "https://docs.google.com/feeds/download/documents/export/Export?exportFormat=docx&id=" + id;
const blob = UrlFetchApp.fetch(url, { headers: { authorization: "Bearer " + ScriptApp.getOAuthToken() } }).getBlob();
const tempFileId = Drive.Files.insert({ title: "temp", mimeType: MimeType.GOOGLE_DOCS }, blob).id;
const tempDoc = DocumentApp.openById(tempFileId);
const table = tempDoc.getBody().getTables()[0];
for (let r = 0; r < table.getNumRows(); r++) {
const row = table.getRow(r);
for (let c = 0; c < row.getNumCells(); c++) {
const cell = row.getCell(c);
console.log({ row: r, col: c, text: cell.getText() });
}
}
// DriveApp.getFileById(tempFileId).setTrashed(true); // If you want to delete the tempolary document, please use this.
// DriveApp.createFile(); // This is used for automatically detecting the scope by the script editor.
}
- When this script is run, the texts of the table, which has the dropdown list of the smart chips, can be retrieved.
Testing:
When this script is tested to the above Document, the following result is obtained.
{ row: 0, col: 0, text: 'sample1' }
{ row: 0, col: 1, text: 'sample2' }
{ row: 0, col: 2, text: 'sample3' }
{ row: 1, col: 0, text: 'sample3' }
{ row: 1, col: 1, text: 'sample2' }
{ row: 1, col: 2, text: 'sample1' }
Note:
- Of course, I think that by parsing DOCX data, you can also retrieve the values from the table. But, I thought that when Document service (DocumentApp) can be used, when it is used, the script will be simpler. So, I proposed to convert from DOCX to Document.
c.getType()
? – RoborantUNSUPPORTED
. – Efta