2015-08-11 21:23:56 +00:00
|
|
|
var argv = require('minimist')(process.argv.slice(2));
|
2016-05-25 03:26:43 +00:00
|
|
|
var assert = require('assert')
|
|
|
|
var XLSX = require('../');
|
2015-08-11 21:23:56 +00:00
|
|
|
var fs = require('fs')
|
|
|
|
var INFILE = './test_files/pivot_table_test.xlsm';
|
|
|
|
var TESTFILE = './test_files/pivot_table_test.xlsm.';
|
|
|
|
//var INFILE = './test_files/formula_stress_test.xlsb';
|
|
|
|
//var TESTFILE = './test_files/formula_stress_test.xls.';
|
2016-05-25 03:26:43 +00:00
|
|
|
var INFILE = './test_files/apachepoi_Tables.xlsx';
|
|
|
|
var TESTFILE = './test_files/apachepoi_Tables.xlsx.';
|
2015-08-11 21:23:56 +00:00
|
|
|
var INFILE = './test_files/apachepoi_45540_classic_Footer.xlsx';
|
|
|
|
var TESTFILE = './test_files/apachepoi_45540_classic_Footer.xlsx.';
|
2016-05-25 03:26:43 +00:00
|
|
|
var SHEET = argv.p || 0;
|
2015-08-11 21:23:56 +00:00
|
|
|
|
2016-05-25 03:26:43 +00:00
|
|
|
function stripbom(x) {
|
|
|
|
return x.replace(/^\ufeff/, "");
|
|
|
|
}
|
|
|
|
function fixcsv(x) {
|
|
|
|
return stripbom(x).replace(/\t/g, ",").replace(/#{255}/g, "").replace(/"/g, "").replace(/[\n\r]+/g, "\n").replace(/\n*$/, "");
|
|
|
|
}
|
2015-08-11 21:23:56 +00:00
|
|
|
|
2016-05-25 03:26:43 +00:00
|
|
|
describe("CSV writer", function () {
|
|
|
|
it("Generates CSV", function () {
|
|
|
|
wb = XLSX.readFile(INFILE, {cellNF: true});
|
2015-08-11 21:23:56 +00:00
|
|
|
|
2016-05-25 03:26:43 +00:00
|
|
|
//XLSX.writeFile(wb, '/tmp/test-csv.xlsx');
|
|
|
|
//var wb = XLSX.readFile('/tmp/test-csv.xlsx', {cellNF: true});
|
2015-08-11 21:23:56 +00:00
|
|
|
|
2016-05-25 03:26:43 +00:00
|
|
|
wb = XLSX.read(XLSX.write(wb, {type: "buffer", bookType: 'xlsx'}), {cellNF: true})
|
2015-08-11 21:23:56 +00:00
|
|
|
|
|
|
|
|
2016-05-25 03:26:43 +00:00
|
|
|
var csv = fixcsv(XLSX.utils.make_csv(wb.Sheets[wb.SheetNames[SHEET]]))
|
|
|
|
var exp = fixcsv(fs.readFileSync(TESTFILE + SHEET + '.csv', 'utf8'))
|
2015-08-11 21:23:56 +00:00
|
|
|
|
2016-05-25 03:26:43 +00:00
|
|
|
assert.equal(csv, exp)
|
|
|
|
})
|
|
|
|
})
|