Change the calling convention excel.getCellByPosition() to excel.getCellByPosition(x, y).setValue()

This commit is contained in:
Namhyeon Go 2023-11-28 00:51:54 +09:00
parent 44c6e22dc8
commit b87aad537a
2 changed files with 27 additions and 13 deletions

View File

@ -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;
@ -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");
}
@ -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 = "abuse@catswords.net";
exports.global = global;
exports.require = global.require;

View File

@ -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++;
});