我正在嘗試使用 DocumentApp API 創建 Google 檔案檔案。
我想制作一個表格并將行內影像插入到它的單元格中。像這樣:
table = body.appendTable([[''],[contact]]);
let img = table.getCell(0,0).appendImage(DriveApp.getFileById(imgFileId).getBlob());
它有效,但在插入的影像之前有一個段落(或 '\n' 或 '\r'?我不確定。)。
我希望單元格只包含影像。
有沒有辦法做到這一點?
謝謝。
uj5u.com熱心網友回復:
創建表格時,該單元格有一個子項作為默認值,如Cooper's comment 所述。那么,在你的情況下,為了達到你的目的,下面的修改怎么樣?
修改后的腳本:
從:
let img = table.getCell(0,0).appendImage(DriveApp.getFileById(imgFileId).getBlob());
到:
在此修改中,影像被附加到單元格并在第一段中洗掉。我認為這種修改可能有助于理解上述情況。
var cell = table.getCell(0, 0);
cell.appendImage(DriveApp.getFileById(imgFileId).getBlob());
cell.getChild(0).removeFromParent();
或者,您也可以使用以下修改。在此修改中,影像被插入到第 1 段中。
table.getCell(0, 0).getChild(0).asParagraph().insertInlineImage(0, DriveApp.getFileById(imgFileId).getBlob());
參考:
- 類 TableCell 的 getChild(childIndex)
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/399246.html
