-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Junhui Tong
committed
Jul 15, 2024
1 parent
38ee1d9
commit c6adc2d
Showing
2 changed files
with
2 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"name": "@timepp/ev", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"exports": "./launch.ts" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"/index.html": "<html>\r\n <head>\r\n <title>Excel Navigate Helper</title>\r\n <link href=\"https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css\" rel=\"stylesheet\" integrity=\"sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH\" crossorigin=\"anonymous\">\r\r\n <script type=\"module\"> (function(){const s=document.createElement(\"link\").relList;if(s&&s.supports&&s.supports(\"modulepreload\"))return;for(const t of document.querySelectorAll('link[rel=\"modulepreload\"]'))c(t);new MutationObserver(t=>{for(const e of t)if(e.type===\"childList\")for(const a of e.addedNodes)a.tagName===\"LINK\"&&a.rel===\"modulepreload\"&&c(a)}).observe(document,{childList:!0,subtree:!0});function o(t){const e={};return t.integrity&&(e.integrity=t.integrity),t.referrerPolicy&&(e.referrerPolicy=t.referrerPolicy),t.crossOrigin===\"use-credentials\"?e.credentials=\"include\":t.crossOrigin===\"anonymous\"?e.credentials=\"omit\":e.credentials=\"same-origin\",e}function c(t){if(t.ep)return;t.ep=!0;const e=o(t);fetch(t.href,e)}})();const g={launchExcel:async function(){return await u(\"launchExcel\",arguments)},getActiveExcelRow:async function(){return await u(\"getActiveExcelRow\",arguments)},closeBackend:async function(){return await u(\"closeBackend\",arguments)}};async function u(n,...s){const o=window.location.protocol,c=window.location.hostname,e=new URLSearchParams(window.location.search).get(\"apiPort\")||\"22311\";return await(await fetch(`${o}//${c}:${e}/api?cmd=${n}&args=${encodeURIComponent(JSON.stringify(s))}`)).json()}let p=null,m=null,h={},f=!0;function w(n,s){h={},s.split(`\n`).forEach(o=>{const c=o.split(\":\");c.length>=2&&(h[c[0].trim()]=c.slice(1).join(\":\").trim())})}async function b(){try{await g.closeBackend()}catch{}window.close()}async function E(){try{return await g.getActiveExcelRow()}catch(n){throw console.error(\"backend exit\",n),window.close(),\"unreachable\"}}async function y(n,s=!1){const o=await E();if(!s&&m&&JSON.stringify(m)===JSON.stringify(o))return;m=o,p&&p.remove();const c=document.createElement(\"table\");c.classList.add(\"table\",\"table-bordered\"),n.appendChild(c);const t=document.createElement(\"tbody\");c.appendChild(t),t.style.whiteSpace=\"pre-wrap\";for(let e=0;e<o.data.length;e++){if(o.headings[e].trim()===\"\"&&o.data[e].trim()===\"\")continue;const a=document.createElement(\"tr\");t.appendChild(a);const l=document.createElement(\"td\");l.style.fontWeight=\"bold\",a.appendChild(l),l.textContent=o.headings[e]||\"\",f||(l.style.display=\"none\");const i=document.createElement(\"td\");a.appendChild(i);const x=h[o.headings[e]];i.style.cssText=x||\"\";const r=o.data[e];if(r.startsWith(\"http\")){const d=document.createElement(\"a\");d.href=r,d.textContent=r,i.appendChild(d)}else i.textContent=o.data[e]}p=c}async function C(){const n=document.createElement(\"div\");document.body.appendChild(n);const s=document.createElement(\"div\");s.classList.add(\"alert\",\"alert-info\"),s.innerText=`This app keep sync with Excel and show the data in current(active) row so that you can see all columns without scrolling if there are too many columns.\nIt assume there is a heading row in Excel and use the heading as the first column in the table. `,n.appendChild(s);const o=document.createElement(\"button\");o.classList.add(\"btn\",\"btn-primary\"),o.style.marginRight=\"10px\",o.textContent=\"Launch Excel to open file\",o.onclick=async()=>{await g.launchExcel()},n.append(o);const c=document.createElement(\"button\");c.classList.add(\"btn\",\"btn-secondary\"),c.style.marginRight=\"10px\",c.textContent=\"Edit Style\",n.append(c),c.onclick=()=>{const l=document.getElementById(\"styleText\");l&&(l.style.display=l.style.display===\"none\"?\"block\":\"none\")};const t=document.createElement(\"button\");t.classList.add(\"btn\",\"btn-secondary\"),t.style.marginRight=\"10px\",t.textContent=\"Toggle Heading\",n.append(t),t.onclick=()=>{f=!f,y(n,!0)};const e=document.createElement(\"button\");e.classList.add(\"btn\",\"btn-danger\"),e.textContent=\"Close\",e.onclick=async()=>{await b()},n.append(e);const a=document.createElement(\"textarea\");a.classList.add(\"form-control\"),a.id=\"styleText\",a.style.width=\"100%\",a.style.height=\"200px\",a.style.display=\"none\",a.style.marginTop=\"10px\",a.style.fontFamily=\"monospace\",a.value=localStorage.getItem(\"styleText\")||\"\",n.appendChild(a),a.onkeydown=()=>{const l=a.value;w(n,l),y(n,!0),localStorage.setItem(\"styleText\",l)},w(n,a.value),n.appendChild(document.createElement(\"p\")),setInterval(y,1e3,n)}document.addEventListener(\"DOMContentLoaded\",function(){C()},!1);\n </script>\n </head>\r\n <body style=\"padding:10px;\">\r\n </body>\r\n</html>\r\n", | ||
"/index.html": "<html>\r\n <head>\r\n <title>Excel Navigate Helper</title>\r\n <link href=\"https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css\" rel=\"stylesheet\" integrity=\"sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH\" crossorigin=\"anonymous\">\r\r\n <script type=\"module\"> (function(){const s=document.createElement(\"link\").relList;if(s&&s.supports&&s.supports(\"modulepreload\"))return;for(const t of document.querySelectorAll('link[rel=\"modulepreload\"]'))c(t);new MutationObserver(t=>{for(const e of t)if(e.type===\"childList\")for(const a of e.addedNodes)a.tagName===\"LINK\"&&a.rel===\"modulepreload\"&&c(a)}).observe(document,{childList:!0,subtree:!0});function o(t){const e={};return t.integrity&&(e.integrity=t.integrity),t.referrerPolicy&&(e.referrerPolicy=t.referrerPolicy),t.crossOrigin===\"use-credentials\"?e.credentials=\"include\":t.crossOrigin===\"anonymous\"?e.credentials=\"omit\":e.credentials=\"same-origin\",e}function c(t){if(t.ep)return;t.ep=!0;const e=o(t);fetch(t.href,e)}})();const g={launchExcel:async function(){return await u(\"launchExcel\",arguments)},getActiveExcelRow:async function(){return await u(\"getActiveExcelRow\",arguments)},closeBackend:async function(){return await u(\"closeBackend\",arguments)}};async function u(n,...s){const o=window.location.protocol,c=window.location.hostname,e=new URLSearchParams(window.location.search).get(\"apiPort\")||\"22311\";return await(await fetch(`${o}//${c}:${e}/api?cmd=${n}&args=${encodeURIComponent(JSON.stringify(s))}`)).json()}let p=null,m=null,h={},f=!0;function w(n,s){h={},s.split(`\n`).forEach(o=>{const c=o.split(\":\");c.length>=2&&(h[c[0].trim()]=c.slice(1).join(\":\").trim())})}async function b(){try{await g.closeBackend()}catch{}window.close()}async function E(){try{return await g.getActiveExcelRow()}catch(n){throw console.error(\"backend exit\",n),window.close(),\"unreachable\"}}async function y(n,s=!1){const o=await E();if(!s&&m&&JSON.stringify(m)===JSON.stringify(o))return;m=o,p&&p.remove();const c=document.createElement(\"table\");c.classList.add(\"table\",\"table-bordered\"),n.appendChild(c);const t=document.createElement(\"tbody\");c.appendChild(t),t.style.whiteSpace=\"pre-wrap\";for(let e=0;e<o.data.length;e++){if(o.headings[e].trim()===\"\"&&o.data[e].trim()===\"\")continue;const a=document.createElement(\"tr\");t.appendChild(a);const l=document.createElement(\"td\");l.style.fontWeight=\"bold\",a.appendChild(l),l.textContent=o.headings[e]||\"\",f||(l.style.display=\"none\");const i=document.createElement(\"td\");a.appendChild(i);const x=h[o.headings[e]];i.style.cssText=x||\"\";const d=o.data[e];if(d.startsWith(\"http\")){const r=document.createElement(\"a\");r.href=d,r.target=\"_blank\",r.textContent=d,i.appendChild(r)}else i.textContent=o.data[e]}p=c}async function C(){const n=document.createElement(\"div\");document.body.appendChild(n);const s=document.createElement(\"div\");s.classList.add(\"alert\",\"alert-info\"),s.innerText=`This app keep sync with Excel and show the data in current(active) row so that you can see all columns without scrolling if there are too many columns.\nIt assume there is a heading row in Excel and use the heading as the first column in the table. `,n.appendChild(s);const o=document.createElement(\"button\");o.classList.add(\"btn\",\"btn-primary\"),o.style.marginRight=\"10px\",o.textContent=\"Launch Excel to open file\",o.onclick=async()=>{await g.launchExcel()},n.append(o);const c=document.createElement(\"button\");c.classList.add(\"btn\",\"btn-secondary\"),c.style.marginRight=\"10px\",c.textContent=\"Edit Style\",n.append(c),c.onclick=()=>{const l=document.getElementById(\"styleText\");l&&(l.style.display=l.style.display===\"none\"?\"block\":\"none\")};const t=document.createElement(\"button\");t.classList.add(\"btn\",\"btn-secondary\"),t.style.marginRight=\"10px\",t.textContent=\"Toggle Heading\",n.append(t),t.onclick=()=>{f=!f,y(n,!0)};const e=document.createElement(\"button\");e.classList.add(\"btn\",\"btn-danger\"),e.textContent=\"Close\",e.onclick=async()=>{await b()},n.append(e);const a=document.createElement(\"textarea\");a.classList.add(\"form-control\"),a.id=\"styleText\",a.style.width=\"100%\",a.style.height=\"200px\",a.style.display=\"none\",a.style.marginTop=\"10px\",a.style.fontFamily=\"monospace\",a.value=localStorage.getItem(\"styleText\")||\"\",n.appendChild(a),a.onkeydown=()=>{const l=a.value;w(n,l),y(n,!0),localStorage.setItem(\"styleText\",l)},w(n,a.value),n.appendChild(document.createElement(\"p\")),setInterval(y,1e3,n)}document.addEventListener(\"DOMContentLoaded\",function(){C()},!1);\n </script>\n </head>\r\n <body style=\"padding:10px;\">\r\n </body>\r\n</html>\r\n", | ||
"excel.js": "// deno-lint-ignore-file no-var no-inner-declarations\r\n\r\nfunction WriteTextFile (text, path, encoding) {\r\n var stream = new ActiveXObject('ADODB.Stream');\r\n stream.Type = 2;\r\n stream.Mode = 3;\r\n if (encoding) stream.Charset = encoding;\r\n stream.Open();\r\n stream.Position = 0;\r\n stream.WriteText(text);\r\n stream.SaveToFile(path, 2);\r\n stream.Close();\r\n}\r\n\r\nfunction saveActiveRow(excel, path) {\r\n var sheet = excel.ActiveSheet;\r\n if (sheet) {\r\n // get max column that have data\r\n var maxColumn = Math.min(sheet.UsedRange.Columns.Count, 100);\r\n // get active range\r\n var cell = excel.ActiveCell;\r\n if (cell) {\r\n var activeRow = cell.Row;\r\n var rowValues = []\r\n var headings = []\r\n for (var i = 1; i <= maxColumn; i++) {\r\n var value = sheet.Cells(activeRow, i).Value;\r\n rowValues.push(value);\r\n var heading = sheet.Cells(1, i).Value;\r\n headings.push(heading);\r\n }\r\n \r\n var headingsStr = headings.join('_@@HS@@_');\r\n var rowValuesStr = rowValues.join('_@@VS@@_');\r\n var content = [headingsStr, rowValuesStr].join('_@@RS@@_');\r\n // WScript.Echo(content);\r\n WriteTextFile(content, path, 'utf-8');\r\n }\r\n }\r\n}\r\n\r\nvar excel = new ActiveXObject('Excel.Application');\r\nexcel.Visible = true;\r\n\r\nvar path = WScript.Arguments(0);\r\n\r\nfor (;;) {\r\n var cmd = WScript.StdIn.ReadLine();\r\n if (cmd == \"exit\") {\r\n WScript.Echo(\"received exit\");\r\n break;\r\n }\r\n\r\n try {\r\n saveActiveRow(excel, path);\r\n } catch (e) {\r\n WScript.Echo(e.message);\r\n }\r\n}\r\n\r\nexcel.Quit();\r\n" | ||
} |