我必须在节点 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