![](/img/trans.png)
[英]Google Apps Script - Exporting events from Google Sheets to Google Calendar - how can I stop it from removing my spreadsheet formulas?
[英]Can I export my data to a Google Doc from Google Sheets using Apps Script?
我的問題可能有點難以解釋,但希望有人知道如何提供幫助! 我住的合作社使用這個谷歌表格來創建我們的購物清單,以便在一周內購物。
目前,用戶使用 List Filler 表中項目旁邊的復選框將它們發送到雜貨清單,在單獨的表上找到,其中只有選中的項目出現在 List Filler 中,以希望幫助購物者更清楚地查看需要購買什么。
我的問題是我目前的購物清單有點難以查看,並且對於那些必須通過手機滑動查看商品的人來說,購物變得困難。 我希望使用 DocumentApp 和 AppScripts 從購物清單中獲取數據並將其導入到谷歌文檔中,以便在我們必須購物時輕松打印。
我看過一些關於如何直接執行此操作的教程/文章,但他們的數據通常看起來與我的完全不同,而且我在嘗試翻譯時遇到了很多麻煩。
我不知道從哪里開始,所以任何幫助將不勝感激:謝謝:))
(工作表不在共享驅動器中)
以下是將電子表格表格復制到 Google 文檔的示例。
我使用占位符 {{table1}} 來顯示我想要桌子的位置。 請注意,此占位符后至少需要有 1 個段落才能刪除文本。
這是我的示例電子表格。
並且插入表格之前的文檔
在 Google Doc 腳本編輯器中,我有這個腳本。
function addTable() {
try {
let doc = DocumentApp.getActiveDocument();
let spread = SpreadsheetApp.openById("1xxxxxxxxxxxxxxxxxxxxxxxxxxA");
let sheet = spread.getSheetByName("Sheet1");
let values = sheet.getDataRange().getDisplayValues();
let body = doc.getBody();
let paras = body.getParagraphs();
let index = paras.findIndex( para => para.findText("{{table1}}"));
index = body.getChildIndex(paras[index]);
body.insertTable(index,values);
paras[index].removeFromParent();
}
catch(err) {
console.log(err);
}
}
運行腳本后的文檔
參考
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.