Comparing version 0.0.5 to 0.0.6
@@ -1,9 +0,24 @@ | ||
var binding; | ||
var os = require('os'), | ||
path = require('path'); | ||
try { | ||
binding = require(__dirname + '/../build/Debug/libxl'); | ||
} catch(e) { | ||
binding = require(__dirname + '/../build/Release/libxl'); | ||
var bindings = null; | ||
var paths = [ | ||
path.join(__dirname, os.platform() + '-' + os.arch(), 'libxl'), | ||
path.join(__dirname, os.platform(), 'libxl'), | ||
path.join(__dirname, '..', 'build', 'Debug', 'libxl'), | ||
path.join(__dirname, '..', 'build', 'Release', 'libxl') | ||
]; | ||
for (var i = 0; i < paths.length; i++) { | ||
try { | ||
bindings = require(paths[i]); | ||
break; | ||
} catch (e) {} | ||
} | ||
module.exports = binding; | ||
if (!bindings) { | ||
throw new Error('unable to load libxl.node'); | ||
} | ||
module.exports = bindings; |
@@ -5,3 +5,3 @@ { | ||
"license": "MIT", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "libxl bindings for node", | ||
@@ -8,0 +8,0 @@ "keywords": ["excel", "libxl", "spreadsheet"], |
@@ -1,4 +0,81 @@ | ||
Node.js bindings for libxl. API coverage is a work in progress; see demo.js, | ||
# What it is | ||
Node.js bindings for [libxl](http://www.libxl.com/). | ||
# How to use it | ||
## Installation | ||
Pull the library into your project with `npm install libxl` | ||
and require the module via | ||
var xl = require('libxl'); | ||
## API | ||
A new excel document is created via | ||
var xlsBook = new xl.Book(xl.BOOK_TYPE_XLS); | ||
or | ||
var xlsxBook = new xl.Book(xl.BOOK_TYPE_XLSX); | ||
(for xlsx documents). The document is written to disk via | ||
xlsBook.writeSync('file.xls'); | ||
(loading and async writing are not implemented atm). | ||
The API closely follows the | ||
[libxl documentation](http://www.libxl.com/documentation.html). | ||
For example, adding a new sheet and writing two cells works as | ||
var sheet = xlsBook.addSheet('Sheet 1'); | ||
sheet.writeStr(1, 0, 'A string'); | ||
sheet.writeNum(1, 1, 42); | ||
Functions whose C++ counterpart returns void or an error status | ||
have been implemented to return the respective instance, so it | ||
is possible to chain calls | ||
sheet | ||
.writeStr(1, 0, 'A string'); | ||
.writeNum(1, 1, 42); | ||
Errors are handled by throwing exceptions. | ||
API coverage is a work in progress; see demo.js, | ||
jasmine specs and the class initializers | ||
(Book::Initialize, Sheet::Initialize, Format::Initialize) | ||
to find out what is currently supported :). | ||
## Unlocking the API | ||
If you have purchased a licence key from XLware, you can | ||
build it into the bindings by modifying `api_key.h` and | ||
rebuilding the library via `node-gyp rebuild` (you'll have | ||
to install node-gyp for this) or `npm install` in the package | ||
directory. I might implement `book.setKey` at some point in the | ||
future, too. | ||
## Platform support | ||
The package currently supports Linux and Windows. Mac support | ||
should be trivial to add, feel free to make a pull request | ||
if you need it before I find time and a mac ;) | ||
# How to contribute | ||
I'll be happy to merge in all sensible pull requests. If you | ||
implement a new API method, please add a short test to the | ||
jasmine specs and a call to demo.js (if applicable). | ||
# Credits | ||
* Torben Fitschen wrote the install script which pulls the | ||
necessary libxl SDK before building. | ||
* Alexander Makarenko wrote | ||
[node-excel-libxl](https://github.com/7eggs/node-excel-libxl) | ||
Though node-libxl is rewritten from scratch, this | ||
package served as the starting point. |
@@ -200,2 +200,51 @@ var xl = require('../lib/libxl'); | ||
it('sheet.readError reads an error', function() { | ||
sheet.writeStr(row, 0, ''); | ||
expect(function() {sheet.readError();}).toThrow(); | ||
expect(function() {sheet.readError.call({}, row, 0);}).toThrow(); | ||
expect(sheet.readError(row, 0)).toBe(xl.ERRORTYPE_NOERROR); | ||
row++; | ||
}); | ||
it('sheet.colWidth reads colum width', function() { | ||
sheet.setCol(0, 0, 42); | ||
expect(function() {sheet.colWidth();}).toThrow(); | ||
expect(function() {sheet.colWidth.call({}, 0);}).toThrow(); | ||
expect(sheet.colWidth(0)).toEqual(42); | ||
}); | ||
it('sheet.rowHeight reads row Height', function() { | ||
sheet.setRow(1, 42); | ||
expect(function() {sheet.rowHeight();}).toThrow(); | ||
expect(function() {sheet.rowHeight.call({}, 1);}).toThrow(); | ||
expect(sheet.rowHeight(1)).toEqual(42); | ||
}); | ||
it('sheet.setCol configures columns', function() { | ||
expect(function() {sheet.setCol();}).toThrow(); | ||
expect(function() {sheet.setCol.call({}, 0, 0, 42);}).toThrow(); | ||
expect(function() {sheet.setCol(0, 0, 42, wrongFormat);}).toThrow(); | ||
expect(sheet.setCol(0, 0, 42)).toBe(sheet); | ||
expect(sheet.setCol(0, 0, 42, format, false)).toBe(sheet); | ||
}); | ||
it('sheet.setRow configures rows', function() { | ||
expect(function() {sheet.setRow();}).toThrow(); | ||
expect(function() {sheet.setRow.call({}, 1, 42);}).toThrow(); | ||
expect(function() {sheet.setRow(1, 42, wrongFormat);}).toThrow(); | ||
expect(sheet.setRow(1, 42)).toBe(sheet); | ||
expect(sheet.setRow(1, 42, format, false)).toBe(sheet); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
800882
40
361
82
2