I have a JavaScript that works with tables in an Apple Numbers spreadsheet when run from Apples script editor. I needed to add file reading functionality to the script so I moved to Visual Studio Code and Node.js. The file reading now works but this line: let Numbers = Application("Numbers"); now kicks out an error "Application is not defined". Is there a package I need to install via npm or some other syntax I need to utilize to make this script work?
Chris
Below is the beginning of my code:
let Numbers = Application("Numbers");
let allHistory = Numbers.documents[0].sheets[1].tables["All History"];
let principalData = Numbers.documents[0].sheets[2].tables["Principal"];
const readline = require('readline');
const fs = require('fs');
let tempArray = [];
const principalDateArray = [];
const principalValueArray = [];
let rl = readline.createInterface({
input: fs.createReadStream('../CSV/largecap.csv')
});
rl.on('line', function(line) {
tempArray = line.split(',');
principalDateArray.push(tempArray[0]);
principalValueArray.push(tempArray[1]);
});
let arrayLength = principalDateArray.rows.Length;
for(let i = 0; i < arrayLength; i++){
principalData.rows[i].cells[2].value = principalDateArray[i];
principalData.rows[i].cells[3].value = principalValueArray[i];
}