我想阻止 ModalDialog 格式化我的字串
我有多個看起來類似于的文本片段
const p = "\"_id\": " "\"\"" ",\n "
"\"name\": " "zzInheritanceBaseElements" ",\n "
"\"style\": " "@settings {\n include: person, loop;\n}\n\n/* Persons */\nelement[\"element type\"=\"person\"] {\n icon: user;\n icon-color: #c29999;\n padding: 0;\n color: #D57C2D;\n}\n\nelement[\"element type\"=\"Person\"] {\n icon: user;\n icon-color: #c29999;\n}\n\nelement:focus {\n shadow-size: 1.9;\n shadow-color: #e1eab6;\n shadow-opacity: 1;\n}\n\nelement[image] {\n icon: false;\n size: 130;\n}\n\nelement[!image] {\n size: 130;\n}\n\n"
"},"
當我在模態中打開它們時,我得到
"_id": "",
"name": zzInheritanceBaseElements,
"style": @settings {
include: person, loop;
}
/* Persons */
element["element type"="person"] {
icon: user;
icon-color: #c29999;
padding: 0;
color: #D57C2D;
}
element["element type"="Person"] {
icon: user;
icon-color: #c29999;
}
element:focus {
shadow-size: 1.9;
shadow-color: #e1eab6;
shadow-opacity: 1;
}
element[image] {
icon: false;
size: 130;
}
element[!image] {
size: 130;
}
},
我正在嘗試通過將多個字串連接在一起然后從 ModalDailog 下載它來創建一個字串
<script>
const formatYmd = date => date.toISOString().slice(0, 10);
formatYmd(new Date());
const filename = "Kumu" "_" formatYmd(new Date()) ".json"; // If you want to change the filename, please modify this.
const a = document.createElement("a");
document.body.appendChild(a);
a.download = filename;
a.href = <?= temp ?>;
a.click();
google.script.host.close();
</script>
我需要得到的字串在original format
如何防止 ModalDialog 格式化我的字串
謝謝
uj5u.com熱心網友回復:
我相信你的目標如下。
您想
p使用 Google Apps 腳本和對話框將變數下載為文本檔案。您希望按如下方式保留變數的文本。
"\"_id\": \"\",\n \"name\": zzInheritanceBaseElements,\n \"style\": @settings {\n include: person, loop;\n}\n\n/* Persons */\nelement[\"element type\"=\"person\"] {\n icon: user;\n icon-color: #c29999;\n padding: 0;\n color: #D57C2D;\n}\n\nelement[\"element type\"=\"Person\"] {\n icon: user;\n icon-color: #c29999;\n}\n\nelement:focus {\n shadow-size: 1.9;\n shadow-color: #e1eab6;\n shadow-opacity: 1;\n}\n\nelement[image] {\n icon: false;\n size: 130;\n}\n\nelement[!image] {\n size: 130;\n}\n\n},"
在這種情況下,下面的示例腳本怎么樣?
Google Apps 腳本方面:
function openDialog() {
const p = "\"_id\": " "\"\"" ",\n "
"\"name\": " "zzInheritanceBaseElements" ",\n "
"\"style\": " "@settings {\n include: person, loop;\n}\n\n/* Persons */\nelement[\"element type\"=\"person\"] {\n icon: user;\n icon-color: #c29999;\n padding: 0;\n color: #D57C2D;\n}\n\nelement[\"element type\"=\"Person\"] {\n icon: user;\n icon-color: #c29999;\n}\n\nelement:focus {\n shadow-size: 1.9;\n shadow-color: #e1eab6;\n shadow-opacity: 1;\n}\n\nelement[image] {\n icon: false;\n size: 130;\n}\n\nelement[!image] {\n size: 130;\n}\n\n"
"},";
var template = HtmlService.createTemplateFromFile('index'); // Please modify this to your HTML filename.
template.temp = `data:${MimeType.TEXT_PLAIN};base64,${Utilities.base64Encode(JSON.stringify(p))}`;
SpreadsheetApp.getUi().showModalDialog(template.evaluate(), 'sample');
}
- 當為您的 Javascript 運行此腳本時,將下載包含上述文本資料的文本檔案。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/438807.html
標籤:javascript 谷歌表格 模态对话
上一篇:GAS中用于在Google表單中創建CheckboxgridItem回應的二維陣列的正確結構是什么
下一篇:無法清除單元格的內容
