{"id":962,"date":"2012-08-15T12:46:24","date_gmt":"2012-08-15T04:46:24","guid":{"rendered":"http:\/\/www.shsh.ylc.edu.tw\/~taichis\/wp\/?p=962"},"modified":"2012-08-15T12:46:24","modified_gmt":"2012-08-15T04:46:24","slug":"%e4%bd%bf%e7%94%a8google-apps-script%e8%ae%80%e5%8f%96%e8%a9%a6%e7%ae%97%e8%a1%a8%e4%b8%ad%e7%9a%84%e8%b3%87%e6%96%99","status":"publish","type":"post","link":"https:\/\/www.shsh.ylc.edu.tw\/~taichis\/wp\/?p=962","title":{"rendered":"\u4f7f\u7528Google Apps Script\u8b80\u53d6\u8a66\u7b97\u8868\u4e2d\u7684\u8cc7\u6599"},"content":{"rendered":"<p>\u6700\u8fd1\u5728\u7814\u7a76 <a href=\"https:\/\/developers.google.com\/apps-script?hl=zh-TW\">Google Apps Script<\/a>\uff0c\u9019\u5be6\u5728\u662f\u5f88\u6709\u8da3\u7684\u65b0\u73a9\u5177\u3002<br \/>\n\u5982\u679c\u60f3\u8981\u900f\u904e Script \u53bb\u8b80\u53d6\u96f2\u7aef\u786c\u789f\u4e2d\u8a66\u7b97\u8868\u7684\u8cc7\u6599\uff0c\u4e26\u900f\u904eHTML\u7684\u7db2\u9801\u5370\u51fa\u5728\u700f\u89bd\u5668\u4e0a\uff0c\u5728 <a href=\"https:\/\/developers.google.com\/apps-script\/html_service?hl=zh-TW\">Google Apps Script<\/a> \u7684\u8aaa\u660e\u9801\u9762\u4e0a\uff0c\u6709\u95dc\u65bc HTML service \u7684\u8aaa\u660e\uff0c\u4e5f\u5728 Pulling Data into a Template \u9019\u500b section \u63d0\u4f9b\u4e86\u4e00\u500b\u7bc4\u4f8b\u3002\u4f46\u9019\u500b\u7bc4\u4f8b\u537b\u4e0d\u5920\u5b8c\u6574\uff0c\u521d\u5165\u9580\u7684\u4eba\uff08\u5c31\u662f\u6307\u6211\uff09\u6703\u641e\u5f97\u4e00\u5718\u9727\u6c34\uff0c\u53c8\u6c92\u8fa6\u6cd5\u6b63\u5e38\u57f7\u884c\u7a0b\u5f0f\u3002<\/p>\n<p>\u6211\u5c07\u5728\u9019\u7bc7\u6587\u7ae0\u4e2d\uff0c\u5c07\u8aaa\u660e\u6587\u4ef6\u4e2d\u7684\u7bc4\u4f8b\u7a0b\u5f0f\uff0c\u4e00\u6b65\u4e00\u6b65\u8aaa\u660e\u5efa\u7f6e\u65b9\u6cd5\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u9996\u5148\u5f9e\u96f2\u7aef\u786c\u789f\u4e2d\uff0c\u627e\u51fa\u60f3\u8981\u8b80\u53d6\u8cc7\u6599\u7684\u8a66\u7b97\u8868\uff0c\u5c07\u60f3\u8981\u8b80\u53d6\u7684\u7bc4\u570d\u9032\u884c\u547d\u540d\u3002<br \/>\n<code><br \/>\n\u4e0b\u62c9\u5f0f\u9078\u55ae\u300c\u8cc7\u6599\u300d\uff0c\u300c\u5df2\u547d\u540d\u548c\u53d7\u4fdd\u8b77\u7684\u7bc4\u570d\u300d\uff0c\u300c\u65b0\u589e\u7bc4\u570d\u300d\uff0c\u7d66\u500b\u540d\u7a31\uff0c\u4f8b\u5982 NamedRange1\u3002<br \/>\n<\/code><br \/>\n\u63a5\u4e0b\u4f86\u5fc5\u9808\u7372\u5f97\u8a72\u6587\u4ef6\u7684\u300ckey\u300d\uff0c\u53ef\u4ee5\u76f4\u63a5\u5f9e\u8a72\u6587\u4ef6\u7684\u7db2\u5740\uff08url\uff09\u7372\u5f97\uff0c\u4f8b\u5982\u7db2\u5740\u662f<\/p>\n<p>http:\/\/spreadsheets1.google.com\/ccc?key=tvGWKARIojJaOIGNX7C4qyg&#038;hl=en#gid=0 <\/p>\n<p>\u90a3\u9ebc key \u5c31\u662f tvGWKARIojJaOIGNX7C4qyg<\/p>\n<p>\u7e3d\u4e4b\uff0c\u6211\u5011\u8981\u5b58\u53d6\u8cc7\u6599\uff0c\u7e3d\u662f\u8981\u544a\u8a34\u7a0b\u5f0f\u8aaa\uff0c\u6211\u5011\u8981\u5b58\u53d6\u7684\u8cc7\u6599\u4f4d\u65bc\u4f55\u8655\u3002\u800c Google \u900f\u904e key \u53d6\u5f97\u6587\u4ef6\u4f4d\u7f6e\uff0c\u518d\u900f\u904e\u7bc4\u570d\u540d\u7a31\u53d6\u5f97\u8cc7\u6599\u7bc4\u570d\u3002<\/p>\n<p>\u63a5\u4e0b\u4f86\u5728\u96f2\u7aef\u786c\u789f\u4e2d\uff0c\u65b0\u589e\u4e00\u500b\u300c\u6307\u4ee4\u78bc\u300d\u6587\u4ef6\u3002<br \/>\n\u8a72\u6587\u4ef6\u4e2d\u5fc5\u9808\u6709\u5169\u500b\u6a94\u6848\uff0c\u4e00\u500b\u662f\u526f\u6a94\u540d .gs \u7684\u7a0b\u5f0f\u78bc\uff0c\u53e6\u4e00\u500b\u5247\u9700\u65b0\u589e\u4e00\u500b .html \u7684\u7db2\u9801\u7bc4\u672c\u3002<\/p>\n<p>.gs \u7684\u7a0b\u5f0f\u78bc\u7bc4\u4f8b\u5982\u4e0b\uff1a<\/p>\n<p><p>\n\t\t\t\t\t\t\t\t<pre class=\"Plum_Code_Box\"><code class=\"javascript\">function getData() {\r\n  return SpreadsheetApp.openById(&#039;tvGWKARIojJaOIGNX7C4qyg&#039;).getRangeByName(&#039;NamedRange1&#039;).getValues();\r\n}\r\n\r\nfunction doGet() {\r\n    return HtmlService.createTemplateFromFile(&#039;Publish&#039;).evaluate();\r\n}<\/code>\n\t\t\t\t\t\t\t\t\t<\/pre>\n\t\t\t\t\t\t\t<\/p><\/p>\n<p>.html \u7684\u7bc4\u4f8b\u5982\u4e0b\uff1a<\/p>\n<p><p>\n\t\t\t\t\t\t\t\t<pre class=\"Plum_Code_Box\"><code class=\"html\">&lt;html&gt;\r\n&lt;table&gt;\r\n  &lt; ? var data = getData();\r\n\r\n     for (var i = 0; i &lt; data.length; ++i) { ?&gt;\r\n    &lt;tr&gt;\r\n      &lt; ? for  (var j = 0; j &lt; data[i].length; ++j) { ?&gt;\r\n        &lt;td&gt;&lt; ?= data[i][j]?&gt;&lt;\/td&gt;\r\n      &lt; ? } ?&gt;\r\n    &lt;\/tr&gt;\r\n  &lt; ? } ?&gt;\r\n&lt;\/table&gt;\r\n&lt;\/html&gt;\r\n<\/code>\n\t\t\t\t\t\t\t\t\t<\/pre>\n\t\t\t\t\t\t\t<\/p><\/p>\n<p>\u7136\u5f8c\u53bb\u8a2d\u5b9a\u767c\u5e03\u7248\u672c<br \/>\n<code><br \/>\n\u300c\u6a94\u6848\u300d\u3001\u300c\u7ba1\u7406\u7248\u672c\u300d<br \/>\n<\/code><br \/>\n\u7136\u5f8c\u9032\u884c\u767c\u5e03<br \/>\n<code><br \/>\n\u300c\u767c\u5e03\u300d\u3001\u300c\u4f48\u7f72\u70ba\u7db2\u8def\u61c9\u7528\u7a0b\u5f0f\u300d<br \/>\n<\/code><\/p>\n<p>\u9019\u6a23\u5c31\u53ef\u4ee5\u4e86\uff01<\/p>\n<div class=\"fcbkbttn_buttons_block\" id=\"fcbkbttn_left\"><div class=\"fcbkbttn_like \"><fb:like href=\"https:\/\/www.shsh.ylc.edu.tw\/~taichis\/wp\/?p=962\" action=\"like\" colorscheme=\"light\" layout=\"standard\" show-faces='false' width=\"450px\" size=\"small\"><\/fb:like><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u5728\u7814\u7a76 Google Apps Script\uff0c\u9019\u5be6\u5728\u662f\u5f88\u6709\u8da3\u7684\u65b0\u73a9\u5177\u3002 \u5982\u679c &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/www.shsh.ylc.edu.tw\/~taichis\/wp\/?p=962\"> <span class=\"screen-reader-text\">\u4f7f\u7528Google Apps Script\u8b80\u53d6\u8a66\u7b97\u8868\u4e2d\u7684\u8cc7\u6599<\/span> \u95b1\u8b80\u66f4\u591a &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/www.shsh.ylc.edu.tw\/~taichis\/wp\/index.php?rest_route=\/wp\/v2\/posts\/962"}],"collection":[{"href":"https:\/\/www.shsh.ylc.edu.tw\/~taichis\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shsh.ylc.edu.tw\/~taichis\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shsh.ylc.edu.tw\/~taichis\/wp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shsh.ylc.edu.tw\/~taichis\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=962"}],"version-history":[{"count":7,"href":"https:\/\/www.shsh.ylc.edu.tw\/~taichis\/wp\/index.php?rest_route=\/wp\/v2\/posts\/962\/revisions"}],"predecessor-version":[{"id":969,"href":"https:\/\/www.shsh.ylc.edu.tw\/~taichis\/wp\/index.php?rest_route=\/wp\/v2\/posts\/962\/revisions\/969"}],"wp:attachment":[{"href":"https:\/\/www.shsh.ylc.edu.tw\/~taichis\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=962"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shsh.ylc.edu.tw\/~taichis\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=962"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shsh.ylc.edu.tw\/~taichis\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=962"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}