This commit is contained in:
Namhyeon Go 2023-11-27 19:14:11 +09:00
parent ae04570d40
commit 44c6e22dc8
4 changed files with 62 additions and 15 deletions

BIN
data/example.xlsx Normal file

Binary file not shown.

View File

@ -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;

View File

@ -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;

View File

@ -1,7 +1,36 @@
// officeloader.js
// Namhyeon Go <abuse@catswords.net>
// 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;
exports.main = main;