Update msoffice.js

This commit is contained in:
Namhyeon Go 2023-12-11 17:53:40 +09:00 committed by GitHub
parent 79bc3fe593
commit 2b524dcb13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -109,14 +109,15 @@ FileTypes.Word = [
// EXAMPLE: new Office.Excel()
function Excel() {
this.Application = CreateObject("Excel.Application");
this.Version = this.Application.Version;
this.Application.Visible = true;
this.application = CreateObject("Excel.Application");
this.Version = this.application.Version;
this.application.Visible = true;
console.info("Microsoft Excel Version:", this.Version);
this.CurrentWorkbook = null;
this.CurrentWorksheet = null;
this.currentWorkbook = null;
this.currentWorksheet = null;
this.range = null;
this.open = function(filename) {
if (typeof filename !== "undefined") {
@ -126,14 +127,14 @@ function Excel() {
}
if (FILE.fileExists(filename)) {
console.warn("Found the file:", filename);
this.Application.Workbooks.Open(filename);
this.CurrentWorkbook = this.Application.ActiveWorkbook;
this.application.Workbooks.Open(filename);
this.currentWorkbook = this.application.ActiveWorkbook;
} else {
console.warn("File not exists!");
this.CurrentWorkbook = this.Application.Workbooks.Add();
this.currentWorkbook = this.application.Workbooks.Add();
}
} else {
this.CurrentWorkbook = this.Application.Workbooks.Add();
this.currentWorkbook = this.application.Workbooks.Add();
}
this.selectWorksheet(1);
@ -142,21 +143,21 @@ function Excel() {
this.close = function() {
try {
this.CurrentWorksheet = null;
this.CurrentWorkbook.Close();
this.CurrentWorkbook = null;
this.Application.Quit();
this.Application = null;
this.currentWorksheet = null;
this.currentWorkbook.Close();
this.currentWorkbook = null;
this.application.Quit();
this.application = null;
} catch (e) {
this.CurrentWorksheet = null;
this.CurrentWorkbook = null;
this.Application = null;
this.currentWorksheet = null;
this.currentWorkbook = null;
this.application = null;
}
};
this.saveAs = function(filename) {
try {
this.CurrentWorkbook.saveAs(filename);
this.currentWorkbook.saveAs(filename);
return FILE.fileExists(filename);
} catch (e) {
console.error("Could not save a file:", e.message);
@ -166,16 +167,25 @@ function Excel() {
this.selectWorksheet = function(idx) {
if (idx == 0) {
this.CurrentWorksheet = this.Application.ActiveSheet;
this.currentWorksheet = this.application.ActiveSheet;
} else {
this.CurrentWorksheet = this.CurrentWorkbook.Worksheets(idx);
this.currentWorksheet = this.currentWorkbook.Worksheets(idx);
}
return this;
};
this.setRange = function(range) {
this.range = range;
return this;
};
this.getCellByPosition = function(row, col) {
return new Excel.Cell(this.CurrentWorksheet.Cells(row, col));
if (this.range == null) {
return new Excel.Cell(this.currentWorksheet.Cells(row, col));
} else {
return new Excel.Cell(this.currentWorksheet.Range(this.range).Cells(row, col));
}
};
};
Excel.SupportedFileTypes = FileTypes.Excel;
@ -202,13 +212,13 @@ Excel.Cell = function(cell) {
// EXAMPLE: new Office.PowerPoint()
function PowerPoint() {
this.Application = CreateObject("PowerPoint.Application");
this.application = CreateObject("PowerPoint.Application");
}
PowerPoint.SupportedFileTypes = FileTypes.PowerPoint;
// EXAMPLE: new Office.Word()
function Word() {
this.Application = CreateObject("Word.Application");
this.application = CreateObject("Word.Application");
}
Word.SupportedFileTypes = FileTypes.Word;
@ -216,7 +226,7 @@ exports.Excel = Excel;
exports.PowerPoint = PowerPoint;
exports.Word = Word;
exports.VERSIONINFO = "Microsoft Office interface (msoffice.js) version 0.1.4";
exports.VERSIONINFO = "Microsoft Office interface (msoffice.js) version 0.1.5";
exports.AUTHOR = "abuse@catswords.net";
exports.global = global;
exports.require = global.require;