我試圖開發一個節點JS腳本,該腳本從電子表格中提取數據以便在腳本中使用。如何設置nodeJS以從電子表格中提取數據
我的腳本啓動這樣的:
var webdriverio = require('webdriverio');
var Excel = require('exceljs');
var testData = require('xlsx-extract');
//var Excel = require ('xlsx-style')
var options = {
desiredCapabilities: {
//browserName: 'phantomjs'
browserName: 'chrome'
}
};
var count = (1);
var testDate = new Date();
var Login = ('#button.mb24.secondary.wide')
var workbook = new Excel.Workbook();
workbook.xlsx.readFile('Myspreadsheet_v1.xlsx')
.then(function() {
getCell('A2').value
console.log('url is: ' + getCell('A2').value);
});
//var workbook = new Excel.Workbook();
//stream.pipe(workbook.xlsx.createInputStream('./Myspreadsheet_v1.xlsx'));
var worksheet = workbook.getWorksheet(1);
var sfurl = worksheet.getCell('A2').value;
var loginName = worksheet.getCell('B2').value;
var loginPassword = worksheet.getCell('C2').value;
不過,我得到一個錯誤,當我嘗試運行它:
xxxxxxx/xxxxxxx/xxxxx.js:32
var sfurl = worksheet.getCell('A2').value;
^
TypeError: Cannot read property 'getCell' of undefined
at Object.<anonymous> (xxxxxxx/xxxxxxx/xxxxx.js:32:22)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:509:3
我真的在爲我做錯了什麼,以及如何虧損要解決這個問題。 我有npn在停滯,我也安裝了node-xlxs和node-exceljs。 我在我的系統上安裝了nodeJS。
我使用這些鏈接來嘗試上手: https://www.npmjs.com/package/xlsx https://www.npmjs.com/package/exceljs
任何幫助將不勝感激。
謝謝。
你有沒有檢查過'workbook.getWorksheet(1);'返回? – Gab
你的意思是npm而不是npn? –