From 2b524dcb130256e995fa867592eff685e0bd5d44 Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Mon, 11 Dec 2023 17:53:40 +0900 Subject: [PATCH] Update msoffice.js --- lib/msoffice.js | 60 ++++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/lib/msoffice.js b/lib/msoffice.js index b365fdc..633319d 100644 --- a/lib/msoffice.js +++ b/lib/msoffice.js @@ -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;