Skip to content

Commit

Permalink
Change the calling convention excel.getCellByPosition() to `excel.g…
Browse files Browse the repository at this point in the history
…etCellByPosition(x, y).setValue()`
  • Loading branch information
gnh1201 committed Nov 27, 2023
1 parent 44c6e22 commit b87aad5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
38 changes: 26 additions & 12 deletions lib/msoffice.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ FileTypes.Word = [
{"extension": [".xps"], "type": "XPS Document"}
];

// Example: new Office.Excel()
// EXAMPLE: new Office.Excel()
function Excel() {
this.Application = CreateObject("Excel.Application");
this.Version = this.Application.Version;
Expand Down Expand Up @@ -174,25 +174,39 @@ function Excel() {
return this;
};

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

this.setValueByPosition = function(row, col, value) {
this.CurrentWorksheet.Cells(row, col).Value = value;

return this;
this.getCellByPosition = function(row, col) {
return new Excel.Cell(this.CurrentWorksheet.Cells(row, col));
};
};
Excel.SupportedFileTypes = FileTypes.Excel;
Excel.Cell = function(cell) {
this.cell = cell;
// EXAMPLE: excel.getCellByPosition(1, 3).setValue("Hello world!");
this.setValue = function(value) {
this.cell.Value = value;
};
this.getValue = function() {
return this.cell.Value;
};
// EXAMPLE: excel.getCellByPosition(1, 3).setFormula("=SUM(A1:A2)");
this.setFormula = function(formula) {
if (formula.indexOf('=') != 0) {
console.warn("Be careful because it may not be the correct formula.");
}
this.cell.Formula = formula;
}
this.getFormula = function() {
return this.call.Formula;
}
};

// Example: new Office.PowerPoint()
// EXAMPLE: new Office.PowerPoint()
function PowerPoint() {
this.Application = CreateObject("PowerPoint.Application");
}
PowerPoint.SupportedFileTypes = FileTypes.PowerPoint;

// Example: new Office.Word()
// EXAMPLE: new Office.Word()
function Word() {
this.Application = CreateObject("Word.Application");
}
Expand All @@ -202,7 +216,7 @@ exports.Excel = Excel;
exports.PowerPoint = PowerPoint;
exports.Word = Word;

exports.VERSIONINFO = "Microsoft Office interface (msoffice.js) version 0.1.3";
exports.VERSIONINFO = "Microsoft Office interface (msoffice.js) version 0.1.4";
exports.AUTHOR = "[email protected]";
exports.global = global;
exports.require = global.require;
2 changes: 1 addition & 1 deletion officeloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function test() {
questions.forEach(function(x) {
var answer = ChatGPT.chat(x);
console.log("받은 답변:", answer);
excel.setValueByPosition(i, 1, answer);
excel.getCellByPosition(i, 1).setValue(answer);
i++;
});

Expand Down

0 comments on commit b87aad5

Please sign in to comment.