用于解答有关Google Apps脚本的问题,这是Google基于JavaScript的云脚本语言,用于自动执行Google产品和第三方服务中的任务。
在从一个页面导航到另一页到另一页的Google Web应用程序中,将用户的输入存储在HTML页面上
保存这些复选框状态在HTML页面上
如果在另一个脚本文件中,breakpoint不起作用-Google脚本
我将我的Google脚本分为几个脚本文件。现在,我想使用一个脚本文件中的断点,该脚本文件是从第一个文件中调用的另一个脚本文件中调用的。这样的休息...
function Paycheck() { const ss = SpreadsheetApp.getActiveSpreadsheet(); const MB = ss.getSheetByName("Monthly Budget"); const Utilities = ss.getSheetByName("Utilities"); const data = MB.getDataRange().getValues(); const out = [data[4][12], data[4][13], data[4][14], data[4][15], data[4][16], data[4][17], data[4][18]]; Utilities.getRange(Utilities.getLastRow()+1, 1, 1, out.length).setValues([out]);
Step1.html GoogleSheet App脚本: function doPost(e) { try { const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1'); const data = JSON.parse(e.postData.contents); const values = [ data['candidateName'], data['contactNumber'], data['dob'], data['email'], data['education'], JSON.stringify(data['assets']), // Convert assets to JSON data['currentVisaCountry'], data['newVisaCountry'], data['visaRejectionCountries'], data['degree'], data['profession'], data['monthlyIncome'] ]; sheet.appendRow(values); // ✅ Return a response with proper CORS headers return ContentService.createTextOutput(JSON.stringify({ result: 'success' })) .setMimeType(ContentService.MimeType.JSON); } catch (error) { return ContentService.createTextOutput(JSON.stringify({ result: 'error', message: error.message })) .setMimeType(ContentService.MimeType.JSON); } } // ✅ Handle CORS Preflight Requests (OPTIONS) function doGet(e) { return ContentService.createTextOutput("") .setMimeType(ContentService.MimeType.TEXT) } postman在处理和提交数据中没有显示错误。 在浏览器中互动时面对的eRror在浏览器中面对:https://ashrithmanagementservicelimited.github.io/visascore/step1.html 在开发模式下: `Access to fetch at 'https://script.google.com/macros/s/AKfycbzbAyTfLqI3rJJJd2aYy6XdYZD60wViYYkwxzwSSyuc-i7zrW79t4J0gjdHF2olYdy0/exec' from origin 'https://ashrithmanagementservicelimited.github.io' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.Understand this errorAI step1.html:167 POST https://script.google.com/macros/s/AKfycbzbAyTfLqI3rJJJd2aYy6XdYZD60wViYYkwxzwSSyuc-i7zrW79t4J0gjdHF2olYdy0/exec net::ERR_FAILED` 其他Google Sheet App脚本: function doPost(e) { try { const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1'); const data = JSON.parse(e.postData.contents); const values = [ data['candidateName'], data['contactNumber'], data['dob'], data['email'], data['education'], JSON.stringify(data['assets']), // Convert assets to JSON data['currentVisaCountry'], data['newVisaCountry'], data['visaRejectionCountries'], data['degree'], data['profession'], data['monthlyIncome'] ]; sheet.appendRow(values); // ✅ Return a response with proper CORS headers return ContentService.createTextOutput(JSON.stringify({ result: 'success' })) .setMimeType(ContentService.MimeType.JSON) .setHeader("Access-Control-Allow-Origin", "*") .setHeader("Access-Control-Allow-Methods", "POST, GET") .setHeader("Access-Control-Allow-Headers", "Content-Type: application/json") } catch (error) { return ContentService.createTextOutput(JSON.stringify({ result: 'error', message: error.message })) .setMimeType(ContentService.MimeType.JSON) .setHeader("Access-Control-Allow-Origin", "*") .setHeader("Access-Control-Allow-Methods", "POST, GET") .setHeader("Access-Control-Allow-Headers", "Content-Type: application/json") } } // ✅ Handle CORS Preflight Requests (OPTIONS) function doGet(e) { return ContentService.createTextOutput("") .setMimeType(ContentService.MimeType.JSON) .setHeader("Access-Control-Allow-Origin", "*") .setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS") .setHeader("Access-Control-Allow-Headers", "Content-Type: application/json") } 执行脚本时的eRROR:TypeError: ContentService.createTextOutput(...).setMimeType(...).setHeader is not a function doPost @ Code.gs:34 其他脚本: return HtmlService.createHtmlOutput(JSON.stringify({ result: 'error', message: error.message })) .setMimeType(ContentService.MimeType.JSON) .setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL); } same浏览器错误显示如上所述,但Postman显示没有错误并保存数据 在您的脚本中,为了删除您的当前问题,下面的修改如何? 从:fetch('https://script.google.com/macros/s/AKfycbxOF8FLSlEd1sVmineXKQtph2Ix1RokQcJ3VuCYR3veLyi7xo98h3eW0zTvQN_fFnNK/exec', { method: 'POST', mode: 'cors', // Ensure CORS mode is enabled body: JSON.stringify(data), headers: { 'Content-Type': 'application/json' } }) TO: fetch('https://script.google.com/macros/s/AKfycbxOF8FLSlEd1sVmineXKQtph2Ix1RokQcJ3VuCYR3veLyi7xo98h3eW0zTvQN_fFnNK/exec', { method: 'POST', body: JSON.stringify(data), }) 注: 如果发生相同的结果,请在您的Web应用程序中反映最新的脚本并再次测试。 参考: 示例脚本以通过各种语言请求Web应用程序
Using Google App Script to update spreadsheet from gmail, javascript not running
<body onload="load()"> <!-- The Modal --> <div id="modalDiv" class="modal"> <!-- Modal content --> <div class="modal-content"> <div id="question"> <p>Are you sure the review of <span style="color:rgb(0,120,211);"><?= getDocument_()['name'] ?></span> has finished and its content is up to date?</p> <button id="yes">Yes</button> <button id="no">No</button> </div> </div> </div> <script> console.log("JavaScript is running!"); const modal = document.getElementById("modalDiv"); console.log("Modal Element:", modal); const yesBtn = document.getElementById("yes"); console.log("Yes Button:", yesBtn); const noBtn = document.getElementById("no"); console.log("No Button:", noBtn); const question = document.getElementById("question"); const content = document.getElementsByClassName("modal-content")[0]; const load = function () { console.log("Modal loaded."); modal.style.display = "block"; } yesBtn.addEventListener('click', () => { alert("Yes button clicked!"); console.log("Yes button clicked."); question.style.display = "none"; const yesResponse = document.createElement('p'); yesResponse.innerHTML = 'Thanks for completing the review/update of the document. We have updated the status of your document <span style="color:rgb(0,120,211);"><?= getDocument_()['name'] ?></span> to Ready and reset your next review date. You will no longer receive notifications for this review period. Have a great day!'; content.appendChild(yesResponse); try { const documentData = <?= JSON.stringify(getDocument_()) ?>; console.log("Sending document data to setDocumentAsReady:", documentData); if (!documentData.name || !documentData.url) { console.error("Error: Document data is missing!", documentData); return; } google.script.run .withSuccessHandler(() => console.log("setDocumentAsReady() executed successfully.")) .withFailureHandler(error => console.error("Error calling setDocumentAsReady:", error)) .setDocumentAsReady(documentData); } catch (err) { console.error("JavaScript Error:", err); } // google.script.run.setDocumentAsReady(<?= JSON.stringify(getDocument_()) ?>); }); noBtn.addEventListener('click', () => { console.log("No button clicked."); question.style.display = "none"; const noResponse = document.createElement('p'); noResponse.innerHTML = 'Ok. Please come back again when the review of <span style="color:rgb(0,120,211);"><?= getDocument_()['name'] ?></span> finishes and its content is up to date'; content.appendChild(noResponse); }); </script> </body>`
Google表格附加流是: 用户上传图像,附加组件将图像保存到用户驱动器中的文件夹中 附加组件可以访问图像,因为日志显示“徽标文件可访问:imageFileName.png ....
该API密钥无权使用此服务或API。位置API错误:ApitargetBlockedMaperror https://developers.google.com/maps/documentation/javascript/Error-messages#api-target-map--map--
adjust oneDit()函数将结果收集到一个选项卡上(而不是单独的选项卡)
调整应用程序脚本oneDit()函数以将结果收集到“调度程序”选项卡(而不是单独的“每日”选项卡)是此请求的下一步 单击此处(revi ...
我们以Web应用程序发布了一个Google脚本,因此发布了该网络应用程序的结果。 效果很好。当然,出版后,脚本进行了一些更改。 问题是,我们'...
adjust oneDit()appsscript以将结果收集到一个选项卡上(而不是单独的选项卡)
调整应用程序脚本oneDit()函数以将结果收集到“调度程序”选项卡(而不是单独的“每日”选项卡)是此请求的下一步 单击此处(revi ...
我有一个从床单文档中带有嵌入式图表的幻灯片。 我正在更新表格的数据,然后将刷新发送到表格,但它不起作用。 当我打开幻灯片文档时...