Skip to content

Commit

Permalink
MS Office #93
Browse files Browse the repository at this point in the history
  • Loading branch information
gnh1201 committed Nov 27, 2023
1 parent ae04570 commit 44c6e22
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 15 deletions.
Binary file added data/example.xlsx
Binary file not shown.
25 changes: 21 additions & 4 deletions lib/msoffice.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var STD = require("lib/std");
var SYS = require("lib/system");
var FILE = require("lib/file");

// msoffice.js
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -157,14 +170,18 @@ function Excel() {
} else {
this.CurrentWorksheet = this.CurrentWorkbook.Worksheets(idx);
}

return this;
};

this.getValueByPosition = function(row, col) {
return this.CurrentWorksheet.Cells(row, col).Value;
};

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;
Expand All @@ -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 = "[email protected]";
exports.global = global;
exports.require = global.require;
20 changes: 10 additions & 10 deletions lib/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
32 changes: 31 additions & 1 deletion officetest.js → officeloader.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,36 @@
// officeloader.js
// Namhyeon Go <[email protected]>
// 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();

// 질문 목록
Expand All @@ -24,7 +53,8 @@ function main(args) {
i++;
});

// 엑셀 닫기
//excel.close();
}

exports.main = main;
exports.main = main;

0 comments on commit 44c6e22

Please sign in to comment.