|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- <html>
- <meta charset="utf-8">
- <title>套用红头</title>
- </head>
-
- <body onload="getAllTemplelists()">
- <script type="text/javascript" src='js/main.js'></script>
- <div id="search">
- <span>关键词:</span>
- <input id="content" type="text" style="width:245px">
- <button type="button" onClick="search()">查询</button>
- <br />
- <br />
- </div>
- <select id="templates" size=5 style='width:360px'>
-
- </select>
- <br />
- <br />
- <button type="button" onClick="selectTemplate()">套红头</button>
- </body>
-
- </html>
-
- <script>
-
- function selectTemplate() {
- var wpsApp = wps.WpsApplication();
- var obj = document.getElementById("templates");
- var index = obj.selectedIndex;
- if (index == -1) {
- alert("请先选择红头文件后再进行套红头!");
- return;
- }
- var redId = obj.options[index].getAttribute("value");
- var activeDoc = wpsApp.ActiveDocument;
- var base = wps.PluginStorage.getItem("getRedHeadPath") || OA_DOOR.getRedHeadPath;
- if (base == undefined) {
- SetDocParamsValue(activeDoc, "insertFileUrl", getDemoTemplatePath());
- SetDocParamsValue(activeDoc, "bkInsertFile", "Content");
- InsertRedHeadDoc(activeDoc);
- window.opener = null;
- window.open('', '_self', '');
- window.close();
- return
- }
- var path = base + redId;
- SetDocParamsValue(activeDoc, "insertFileUrl", path);
- InsertRedHeadDoc(activeDoc);
-
- window.opener = null;
- window.open('', '_self', '');
-
- window.close();
- }
-
- function isWord(suffix) {
- var suffixArray = ["doc", "dot", "wps", "wpt", "docx", "docm", "dotm"];
- for (var f1 in suffixArray) {
- if (suffixArray[f1].indexOf(suffix) > -1) {
- return true;
- }
- }
- return false;
- }
-
- function getAllTemplelists() {
- var xmlhttp = new XMLHttpRequest();
- xmlhttp.onreadystatechange = function () {
-
- if (xmlhttp.readyState == 4 && (xmlhttp.status == 200 || xmlhttp.status == 0)) {
- var text = xmlhttp.responseText;
- var resultJson = JSON.parse(text)
- for (var i = 0; i < resultJson.length; i++) {
- var element = resultJson[i]
- var myOption = document.createElement("option");
- var suffix = element.tempName.split('.')[1];
- if (isWord(suffix)) {
- myOption.value = element.tempId;
- myOption.text = element.tempName;
- templates.add(myOption);
- }
- }
- }
- }
-
- var redHeadsPath = wps.PluginStorage.getItem("redHeadsPath") || OA_DOOR.redHeadsPath
- if (redHeadsPath == undefined) {
- var strData =
- '[{"tempId":23,"tempName":"广东省xx局.docx"},{"tempId":24,"tempName":"广东省xx局 - 副本.docx"},{"tempId":25,"tempName":"红头.docx"}]'
- resultJson = JSON.parse(strData);
- for (var i = 0; i < resultJson.length; i++) {
- var element = resultJson[i]
- var myOption = document.createElement("option");
- var suffix = element.tempName.split('.')[1];
- if (isWord(suffix)) {
- myOption.value = element.tempId;
- myOption.text = element.tempName;
- templates.add(myOption);
- }
- }
- document.getElementById("search").style.display = "none";
- return
- }
- xmlhttp.open("POST", redHeadsPath, true);
- xmlhttp.setRequestHeader("Content-type",
- "application/x-www-form-urlencoded;charset=UTF-16LE");
- xmlhttp.send();
- if (!wps.PluginStorage.getItem("searchRedHeadPath")) {
- document.getElementById("search").style.display = "none";
- }
- }
-
- function search() {
- var xmlhttp = new XMLHttpRequest();
- xmlhttp.onreadystatechange = function () {
-
- if (xmlhttp.readyState == 4 && (xmlhttp.status == 200 || xmlhttp.status == 0)) {
- var text = xmlhttp.responseText;
- var resultJson = JSON.parse(text)
- templates.options.length = 0;
- for (var i = 0; i < resultJson.length; i++) {
- var element = resultJson[i]
- var myOption = document.createElement("option");
- myOption.value = element.tempId;
- myOption.text = element.tempName;
- templates.add(myOption);
- }
- }
- }
-
- var searchPath = wps.PluginStorage.getItem("searchRedHeadPath") || OA_DOOR.redHeadsPath
-
- var totalPath = searchPath + "?content=" + document.getElementById("content").value;
-
- xmlhttp.open("get", totalPath, true);
- xmlhttp.setRequestHeader("Content-type",
- "application/x-www-form-urlencoded;charset=UTF-16LE");
- xmlhttp.send();
- }
-
- </script>
|