Update officeloader.js

This commit is contained in:
Namhyeon Go 2023-12-19 05:56:16 +09:00
parent 5f487d9409
commit 92dedd182e

View File

@ -6,23 +6,24 @@ var Office = require("lib/msoffice");
var ChatGPT = require("lib/chatgpt");
function main(args) {
// EXAMPLE: cscript app.js officeloader data\example.xlsx
// EXAMPLE: cscript app.js officeloader <data\example.xlsx> <programfile>
if (args.length > 0) {
var filename = args[0];
open(filename);
var programfile = args[1];
open(filename, programfile);
} else {
test();
}
}
function open(filename) {
function open(filename, programfile) {
var filetypes = [
{"application": "excel", "filetypes": Office.Excel.SupportedFileTypes},
{"application": "powerpoint", "filetypes": Office.PowerPoint.SupportedFileTypes},
{"application": "word", "filetypes": Office.Word.SupportedFileTypes}
];
var resolved_filetype = filetypes.reduce(function(a, x) {
var resolved_application = filetypes.reduce(function(a, x) {
if (a == '') {
var application = x.application;
var extensions = x.filetypes.reduce(function(b, x) {
@ -36,23 +37,37 @@ function open(filename) {
return a;
}, '');
switch (resolved_filetype) {
var after_opened = function(officeInstance) {
if (typeof programfile !== "undefined") {
var target = require(programfile);
try {
target.onApplicationOpened(resolved_application, officeInstance);
} catch (e) {
console.error("after_opened:", e.message);
}
};
};
switch (resolved_application) {
case "excel": {
var excel = new Office.Excel(); // Create an Excel instance
excel.open(filename); // Open the Excel instance
after_opened(excel);
break;
}
case "powerpoint": {
var powerpoint = new Office.PowerPoint(); // Create a PowerPoint instance
powerpoint.open(filename); // Open the PowerPoint instance
after_opened(powerpoint);
break;
}
case "word": {
var word = new Office.Word(); // Create an Word instance
word.open(filename); // Open the Word instance
after_opened(word);
break;
}