我必须在节点js中读取xls文件我尝试了三种方式,但我面临如下问题。 请告诉我任何解决此类问题的方法。
//first time
var office = require('office');
office.parse('test.xls', function(err, data) {
console.log(data.sheets);
});
//second time
require('xls').parse('test.xls', function(err, data) {
// xls file parsed into data
console.log(data);
});*/
//third time
var fs = require('fs');
var htmlparser = require("htmlparser");
var office = require('office');
exports.onlyText = function(test) {
test.expect(3);
var handler = new htmlparser.DefaultHandler(function (error, dom) {
test.ok(!error, error);
var text = htmlparser.DomUtils.getElementsByTagName("P", dom)[0].children[0].raw;
test.strictEqual(text, '213', 'text data');
test.done();
});
office.parse(__dirname + '/test.xls', function(err, data) {
test.ok(!err, err);
var parser = new htmlparser.Parser(handler);
parser.parseComplete(data);
});
};
//error in console for all time is
//Uncaught Error: Cannot find module '../build/Release/node_expat.node' module.js:338
//Uncaught Error: Cannot find module '../build/Release/node_expat.node' module.js:338