diff --git a/.gitmodules b/.gitmodules index 3b0336f..1b90759 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "tests/files"] path = tests/files - url = https://github.com/Niggler/js-xlsx-testfiles.git + url = https://github.com/Niggler/test_files.git diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..179fa1a --- /dev/null +++ b/.travis.yml @@ -0,0 +1,9 @@ +language: node_js +node_js: + - "0.10" + - "0.8" +before_install: + - "npm install -g mocha" +before_script: + - "make init" + - "cd tests/files; make; cd -" diff --git a/LICENSE b/LICENSE index 76f4470..ba1a010 100644 --- a/LICENSE +++ b/LICENSE @@ -1,16 +1,17 @@ Copyright (C) 2012-2013 Niggler -The MIT License (MIT) + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. Except where noted, this license applies to any and all software programs and associated documentation files created by the Original Author and distributed with the Software: 'jszip.js' is a modified version of JSZip, Copyright (c) Stuart Knightley, David Duponchel, Franz Buchinger, Ant'onio Afonso. JSZip is dual licensed and is used according to the terms of the MIT License. - -Any code shared between this project and the Apache-licensed XLS parser by the same author (all of which draws from the ECMA-376 specification) falls under this license. diff --git a/Makefile b/Makefile index f54d6d4..2e1bc2e 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,27 @@ DEPS=$(wildcard bits/*.js) - -xlsx.js: $(DEPS) +TARGET=xlsx.js +$(TARGET): $(DEPS) cat $^ > $@ .PHONY: clean clean: - rm xlsx.js + rm $(TARGET) -test: - npm test \ No newline at end of file +.PHONY: init +init: + git submodule init + git submodule update + git submodule foreach git pull origin master + + +.PHONY: test mocha +test mocha: + mocha -R spec + +.PHONY: jasmine +jasmine: + npm run-script test-jasmine + +.PHONY: lint +lint: $(TARGET) + jshint --show-non-errors $(TARGET) diff --git a/README.md b/README.md index 2b09646..b51bb4b 100644 --- a/README.md +++ b/README.md @@ -61,9 +61,15 @@ For more details: - `index.html` is the live demo - `bits/90_utils.js` contains the logic for generating CSV and JSON from sheets +## Test Files + +Test files are housed in [another repo](https://github.com/Niggler/test_files). + ## License -Please consult the attached LICENSE file for details. All rights not explicitly granted by the MIT license are reserved by the Original Author. +Please consult the attached LICENSE file for details. All rights not explicitly granted by the Apache 2.0 license are reserved by the Original Author. + +It is the opinion of the Original Author that this code conforms to the terms of the Microsoft Open Specifications Promise, falling under the same terms as OpenOffice (which is governed by the Apache License v2). Given the vagaries of the promise, the Original Author makes no legal claim that in fact end users are protected from future actions. It is highly recommended that, for commercial uses, you consult a lawyer before proceeding. ## XLS Support @@ -73,3 +79,7 @@ XLS is not supported in this module. Due to Licensing issues [that are discusse ISO/IEC 29500:2012(E) "Information technology — Document description and processing languages — Office Open XML File Formats" +OSP-covered specifications: + + - [MS-XLSX]: Excel (.xlsx) Extensions to the Office Open XML SpreadsheetML File Format + diff --git a/package.json b/package.json index c99a6d7..88a0a74 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xlsx", - "version": "0.2.8", + "version": "0.3.0", "author": "Niggler", "description": "(one day) a full-featured XLSX parser and writer. For now, primitive parser", "keywords": [ @@ -10,19 +10,24 @@ "xlsx2csv": "./bin/xlsx2csv.njs" }, "main": "./xlsx", + "dependencies": { + "codepage":"", + "commander":"" + }, + "devDependencies": { + "mocha":"", + "jasmine-node": "x" + }, "repository": { "type":"git", "url": "git://github.com/Niggler/js-xlsx.git" }, - "bugs": { - "url": "https://github.com/Niggler/js-xlsx/issues" - }, - "devDependencies": { - "jasmine-node": "x" - }, "scripts": { "pretest": "git submodule init && git submodule update", - "test": "jasmine-node --verbose tests/" + "test": "make mocha", + "test-jasmine": "jasmine-node --verbose tests/" }, + "bugs": { "url": "https://github.com/Niggler/js-xlsx/issues" }, + "license": "Apache-2.0", "engines": { "node": ">=0.6" } } diff --git a/test.js b/test.js new file mode 100644 index 0000000..0bc3458 --- /dev/null +++ b/test.js @@ -0,0 +1,39 @@ +/* vim: set ts=2: */ +var XLSX; +var fs = require('fs'), assert = require('assert'); +describe('source', function() { it('should load', function() { XLSX = require('./'); }); }); + +var files = (fs.existsSync('tests.lst') ? fs.readFileSync('tests.lst', 'utf-8').split("\n") : fs.readdirSync('test_files')).filter(function(x){return x.substr(-5)==".xlsx" || x.substr(-13)==".xlsx.pending"}); + +function parsetest(x, wb) { + describe(x + ' should have all bits', function() { + var sname = './test_files/' + x + '.sheetnames'; + it('should have all sheets', function() { + wb.SheetNames.forEach(function(y) { assert(wb.Sheets[y], 'bad sheet ' + y); }); + }); + it('should have the right sheet names', fs.existsSync(sname) ? function() { + var file = fs.readFileSync(sname, 'utf-8'); + var names = wb.SheetNames.join("\n") + "\n"; + assert.equal(file, names); + } : null); + }); + describe(x + ' should generate correct output', function() { + wb.SheetNames.forEach(function(ws, i) { + var name = ('./test_files/' + x + '.' + i + '.csv'); + it('#' + i + ' (' + ws + ')', fs.existsSync(name) ? function() { + var file = fs.readFileSync(name, 'utf-8'); + var csv = XLSX.utils.make_csv(wb.Sheets[ws]); + assert.equal(file.replace(/"/g,""), csv.replace(/"/g,""), "CSV badness"); + } : null); + }); + }); +} + +describe('should parse test files', function() { + files.forEach(function(x) { + it(x, x.substr(-8) == ".pending" ? null : function() { + var wb = XLSX.readFile('./test_files/' + x); + parsetest(x, wb); + }); + }); +}); diff --git a/test_files b/test_files new file mode 120000 index 0000000..47f9dd3 --- /dev/null +++ b/test_files @@ -0,0 +1 @@ +tests/files \ No newline at end of file diff --git a/tests.lst b/tests.lst new file mode 100644 index 0000000..7c5af4a --- /dev/null +++ b/tests.lst @@ -0,0 +1,120 @@ +45430.xlsx +45540_classic_Footer.xlsx.pending +45540_classic_Header.xlsx.pending +45540_form_Footer.xlsx +45540_form_Header.xlsx +45544.xlsx.pending +46535.xlsx +46536.xlsx +47090.xlsx +47504.xlsx +47668.xlsx +47737.xlsx +47804.xlsx +47813.xlsx +47862.xlsx +47889.xlsx +48495.xlsx +48539.xlsx +48703.xlsx +48779.xlsx +48923.xlsx +49156.xlsx +49273.xlsx +49325.xlsx +49609.xlsx +49783.xlsx +49872.xlsx +49928.xlsx.pending +49966.xlsx +50096.xlsx +50299.xlsx +50784-font_theme_colours.xlsx +50786-indexed_colours.xlsx +50795.xlsx +50846-border_colours.xlsx +50867_with_table.xlsx +51222.xlsx +51470.xlsx +51710.xlsx +51850.xlsx +51963.xlsx +52348.xlsx +52716.xlsx +53101.xlsx +53282.xlsx +53568.xlsx +53734.xlsx +53798.xlsx +53798_shiftNegative_TMPL.xlsx +54071.xlsx +54084 - Greek - beyond BMP.xlsx +54206.xlsx +54288-ref.xlsx +54288.xlsx +54436.xlsx +54524.xlsx +54607.xlsx +AverageTaxRates.xlsx +Booleans.xlsx +BrNotClosed.xlsx +CustomXMLMapping-singleattributenamespace.xlsx +CustomXMLMappings-complex-type.xlsx +CustomXMLMappings.xlsx +CustomXmlMappings-inverse-order.xlsx +DataValidations-49244.xlsx +DateFormatTests.xlsx +ElapsedFormatTests.xlsx +ForShifting.xlsx +FormatChoiceTests.xlsx +FormatConditionTests.xlsx +Formatting.xlsx.pending +FormulaEvalTestData_Copy.xlsx.pending +GeneralFormatTests.xlsx +InlineStrings.xlsx +NewlineInFormulas.xlsx +NumberFormatApproxTests.xlsx +NumberFormatTests.xlsx +RepeatingRowsCols.xlsx +SampleSS.xlsx +SimpleMultiCell.xlsx +SimpleWithComments.xlsx +Tables.xlsx +TextFormatTests.xlsx +TwoSheetsNoneHidden.xlsx +TwoSheetsOneHidden.xlsx +WithChart.xlsx +WithChartSheet.xlsx.pending +WithConditionalFormatting.xlsx +WithDrawing.xlsx +WithEmbeded.xlsx +WithMoreVariousData.xlsx +WithTable.xlsx +WithTextBox.xlsx +WithTextBox2.xlsx +WithThreeCharts.xlsx +WithTwoCharts.xlsx +WithVariousData.xlsx +atp.xlsx +chart_sheet.xlsx +comments.xlsx +formula_stress_test.xlsx.pending +interview.xlsx +issue.xlsx +mixed_sheets.xlsx +named_ranges_2011.xlsx +picture.xlsx +reordered_sheets.xlsx +sample-beta.xlsx +sample.xlsx +shared_formulas.xlsx +sheetProtection_allLocked.xlsx +sheetProtection_not_protected.xlsx +styles.xlsx +workbookProtection_not_protected.xlsx +workbookProtection_workbook_revision_protected.xlsx +workbookProtection_workbook_structure_protected.xlsx +workbookProtection_workbook_windows_protected.xlsx +workbookProtection_worksheet_protected.xlsx +xlsx-jdbc.xlsx +חישוב_נקודות_זיכוי.xlsx diff --git a/tests/files b/tests/files index 340b477..20470ba 160000 --- a/tests/files +++ b/tests/files @@ -1 +1 @@ -Subproject commit 340b4779c42e8b322de850679d6abbe787ee8afc +Subproject commit 20470bae65b2912a2d29dd3c1cc591fddbd002a0