From 44c6e22dc8b1118f00f73cc904ac36d8eb9feb87 Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Mon, 27 Nov 2023 19:14:11 +0900 Subject: [PATCH] MS Office #93 --- data/example.xlsx | Bin 0 -> 9567 bytes lib/msoffice.js | 25 ++++++++++++++++++++---- lib/system.js | 20 +++++++++---------- officetest.js => officeloader.js | 32 ++++++++++++++++++++++++++++++- 4 files changed, 62 insertions(+), 15 deletions(-) create mode 100644 data/example.xlsx rename officetest.js => officeloader.js (59%) diff --git a/data/example.xlsx b/data/example.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..ff4e3f9e5f59b99fbf2319b21dc7057ed9ca53d7 GIT binary patch literal 9567 zcmeHtg_x30)AVasbbd98RNrxaHAR#$)3@HsVARr*!9V(sDAq~rB)80)S1k+#4@WK ztV|S@d&jR6hv~U+b6Zr$XCs|dbMxEOcUM61415dTQk(&pJLsSfTxMfk~fzkb04roNf!0onmj)9yN;tyPK(KJp*^< zyEX*ew+B~r{C5vxH@rbVkO6?(TLgg0-(Xp(&Ovhw&ou=&>d@h^)ORqkg0Qpw-2V@b z|HT;m%cU1YDk`^fU_kd|t^>Qy#%3ab;_@zHGIdlhynJL~Se5UyXh~<9=*fUDNc<6` zy&Jr)d!}au-*0wNoi1_}gy7%_&{Vk;LgOy&oluw_JH$S-FIZ^9b{;z!J57+5b7OFB z2xrQ#{+J=(JxB9wt}EMQhFP+VA!Yq4+opXQ+RIBsV;Ss2BkNSc6j; z7CbVpR_rde4wiCRi)l!mVa)=4q7Znu~`e0S3&aMil;WiGiOr#4OA&Gw$?wBmNocs@}^(W^tK z6HUz`>o!ZaMLhIVt;CF+y@r!~zmpmb;Szvbq2iQ)N~6=Dt6e-=Fv?_ZU&B@muQ&nu zaz?eFR!Cdz5yE#4r@7)}RUT%a_z>;&&U>R(i6G%R%N)Za64)$oZi?X?X`h~m#Kjxe ziu~1BkZQLQ+c9eTQ0%eqEh3Hh>{|l}k^fQzgX*MN z{WT0x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msoffice.js index 3ab9a3be..2ec51e43 100644 --- a/lib/msoffice.js +++ b/lib/msoffice.js @@ -1,4 +1,5 @@ var STD = require("lib/std"); +var SYS = require("lib/system"); var FILE = require("lib/file"); // msoffice.js @@ -119,12 +120,24 @@ function Excel() { this.open = function(filename) { if (typeof filename !== "undefined") { - Application.Workbooks.Open(filename); - this.CurrentWorkbook = Application.ActiveWorkbook; + // check type of the path + if (filename.indexOf(":\\") < 0 && filename.indexOf(":/") < 0) { + filename = SYS.getCurrentWorkingDirectory() + "\\" + filename; // get absolute path + } + if (FILE.fileExists(filename)) { + console.warn("Found the file:", filename); + this.Application.Workbooks.Open(filename); + this.CurrentWorkbook = this.Application.ActiveWorkbook; + } else { + console.warn("File not exists!"); + this.CurrentWorkbook = this.Application.Workbooks.Add(); + } } else { this.CurrentWorkbook = this.Application.Workbooks.Add(); } this.selectWorksheet(1); + + return this; }; this.close = function() { @@ -157,6 +170,8 @@ function Excel() { } else { this.CurrentWorksheet = this.CurrentWorkbook.Worksheets(idx); } + + return this; }; this.getValueByPosition = function(row, col) { @@ -164,7 +179,9 @@ function Excel() { }; this.setValueByPosition = function(row, col, value) { - return this.CurrentWorksheet.Cells(row, col).Value = value; + this.CurrentWorksheet.Cells(row, col).Value = value; + + return this; }; }; Excel.SupportedFileTypes = FileTypes.Excel; @@ -185,7 +202,7 @@ exports.Excel = Excel; exports.PowerPoint = PowerPoint; exports.Word = Word; -exports.VERSIONINFO = "Microsoft Office interface (msoffice.js) version 0.1.2"; +exports.VERSIONINFO = "Microsoft Office interface (msoffice.js) version 0.1.3"; exports.AUTHOR = "abuse@catswords.net"; exports.global = global; exports.require = global.require; diff --git a/lib/system.js b/lib/system.js index 8b2b11be..45455d0b 100644 --- a/lib/system.js +++ b/lib/system.js @@ -24,15 +24,15 @@ exports.createProcess = function(cmd) { exports.getEnvString = function(envName) { return (function(s) { - switch(s) { - case "PROGRAMFILES": - return WSH.ExpandEnvironmentStrings("%HOMEDRIVE%\\Program Files"); - case "PROGRAMFILES(X86)": - return WSH.ExpandEnvironmentStrings("%HOMEDRIVE%\\Program Files (x86)"); - default: - return WSH.ExpandEnvironmentStrings('%' + s + '%'); - } - })(envName.toUpperCase()); + switch(s) { + case "PROGRAMFILES": + return WSH.ExpandEnvironmentStrings("%HOMEDRIVE%\\Program Files"); + case "PROGRAMFILES(X86)": + return WSH.ExpandEnvironmentStrings("%HOMEDRIVE%\\Program Files (x86)"); + default: + return WSH.ExpandEnvironmentStrings('%' + s + '%'); + } + })(envName.toUpperCase()); }; exports.get32BitFolder = function() { @@ -176,6 +176,6 @@ exports.ping = function(address) { return WMI.execQuery("Select ResponseTime From Win32_PingStatus where address='" + address + "'").fetch().get("ResponseTime"); }; -exports.VERSIONINFO = "System Module (system.js) version 0.1.1"; +exports.VERSIONINFO = "System Module (system.js) version 0.1.2"; exports.global = global; exports.require = global.require; diff --git a/officetest.js b/officeloader.js similarity index 59% rename from officetest.js rename to officeloader.js index 025d690c..dda0e48c 100644 --- a/officetest.js +++ b/officeloader.js @@ -1,7 +1,36 @@ +// officeloader.js +// Namhyeon Go +// https://github.com/gnh1201/welsonjs + +var SYS = require("lib/system"); var Office = require("lib/msoffice"); var ChatGPT = require("lib/chatgpt"); function main(args) { + // 기존 파일을 여는 경우 인자에 파일 경로 추가 + if (args.length > 0) { + var filename = args[0]; + open(filename); + } else { + test(); + } +} + +function open(filename) { + // 엑셀 인스턴스 생성 + var excel = new Office.Excel(); + + // 엑셀 열기 + excel.open(filename); + + // .... 여기서 작업하세요 .... + + // 엑셀 닫기 + //excel.close(); +} + +function test() { + // 엑셀 인스턴스 생성 var excel = new Office.Excel(); // 질문 목록 @@ -24,7 +53,8 @@ function main(args) { i++; }); + // 엑셀 닫기 //excel.close(); } -exports.main = main; \ No newline at end of file +exports.main = main;