Skip to content
This repository has been archived by the owner on Dec 5, 2017. It is now read-only.

Commit

Permalink
version bump 0.4.0: integration with js-harb
Browse files Browse the repository at this point in the history
  • Loading branch information
SheetJSDev committed Oct 2, 2014
1 parent b3ebab1 commit d95408b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# J

Simple data wrapper that attempts to wrap [xlsjs](http://npm.im/xlsjs) and [xlsx](http://npm.im/xlsx) to provide a uniform way to access data from Excel files.
Simple data wrapper that attempts to wrap SheetJS libraries to provide a uniform way to access data from Excel and other spreadsheet files:

- [xlsjs](http://npm.im/xlsjs)
- [xlsx](http://npm.im/xlsx)
- [harb](http://npm.im/harb)

Excel files are parsed based on the content (not by filename). For example, CSV files can be renamed to .XLS and excel will do the right thing.

Expand All @@ -14,14 +18,20 @@ Supported Formats:
| XLSM (2007+ w/macros) | JS-XLSX |
| XLSB (2007+ binary) | JS-XLSX |
| XML (2003/2004, basic) | JS-XLS |
| DIF (plaintext) | JS-HARB |
| UTF-16 Text | JS-HARB |
| CSV / TSV | JS-HARB |
| SocialCalc | JS-HARB |

Output formats:

- XML and HTML work with [Excel Web Query](http://office.microsoft.com/en-us/excel-help/get-and-analyze-data-from-the-web-in-excel-HA001054848.aspx)
- CSV (and other delimited formats such as TSV)
- DSV (general delimiters, including CSV and TSV)
- JSON
- Formulae list (e.g. `A1=NOW()`, `A2=A1+3`)
- XLSX / XLSM work with iOS Numbers and Excel
- Markdown tables (GFM style)
- SocialCalc output

## Installation

Expand Down
30 changes: 25 additions & 5 deletions j.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
/*jshint node:true, eqnull:true */
var XLSX = require('xl'+'sx');
var XLS = require('xl'+'sjs');
var HARB = require('ha'+'rb');
var UTILS = XLSX.utils;

var libs = [
["XLS", XLS],
["XLSX", XLSX]
["XLSX", XLSX],
["HARB", HARB]
];

var fs = require('f'+'s');
Expand All @@ -21,7 +23,7 @@ var readFileSync = function(filename, options) {
/* Zip container */
case 0x50: return [XLSX, XLSX.readFile(filename, options)];
/* Unknown */
default: return [undefined, f];
default: return [HARB, HARB.readFile(filename, options)];
}
};

Expand All @@ -34,12 +36,13 @@ var read = function(data, options) {
/* Zip container */
case 0x50: return [XLSX, XLSX.read(data, options)];
/* Unknown */
default: return [undefined, data];
default: return [HARB, HARB.read(data.toString(), options)];
}
};

function to_formulae(w) {
var XL = w[0], workbook = w[1];
if(!XL.utils.get_formulae) XL = XLSX;
var result = {};
workbook.SheetNames.forEach(function(sheetName) {
var f = XL.utils.get_formulae(workbook.Sheets[sheetName]);
Expand All @@ -50,6 +53,7 @@ function to_formulae(w) {

function to_json(w, raw) {
var XL = w[0], workbook = w[1];
if(!XL.utils.sheet_to_row_object_array) XL = XLSX;
var result = {};
workbook.SheetNames.forEach(function(sheetName) {
var roa = XL.utils.sheet_to_row_object_array(workbook.Sheets[sheetName], {raw:raw});
Expand All @@ -60,6 +64,7 @@ function to_json(w, raw) {

function to_dsv(w, FS, RS) {
var XL = w[0], workbook = w[1];
if(!XL.utils.make_csv) XL = XLSX;
var result = {};
workbook.SheetNames.forEach(function(sheetName) {
var csv = XL.utils.make_csv(workbook.Sheets[sheetName], {FS:FS||",",RS:RS||"\n"});
Expand All @@ -70,6 +75,7 @@ function to_dsv(w, FS, RS) {

function get_cols(sheet, XL) {
var val, r, hdr, R, C, _XL = XL || XLS;
if(!XL.utils.format_cell) XL = XLSX;
hdr = [];
if(!sheet["!ref"]) return hdr;
r = _XL.utils.decode_range(sheet["!ref"]);
Expand All @@ -83,6 +89,7 @@ function get_cols(sheet, XL) {

function to_md(w) {
var XL = w[0], wb = w[1];
if(!XL.utils.format_cell) XL = XLSX;
var tbl = {};
wb.SheetNames.forEach(function(sheet) {
var ws = wb.Sheets[sheet];
Expand Down Expand Up @@ -118,6 +125,7 @@ function to_md(w) {

function to_html(w) {
var XL = w[0], wb = w[1];
if(!XL.utils.format_cell) XL = XLSX;
var tbl = {};
wb.SheetNames.forEach(function(sheet) {
var ws = wb.Sheets[sheet];
Expand Down Expand Up @@ -238,7 +246,7 @@ var sheet_to_socialcalc = (function() {

var end = "--SocialCalcSpreadsheetControlSave--";

var scencode = function(s) { return s.replace(/\\/g, "\\b").replace(/:/g, "\\c").replace(/\n/g,"\\n"); }
var scencode = function(s) { return s.replace(/\\/g, "\\b").replace(/:/g, "\\c").replace(/\n/g,"\\n"); };

var scsave = function scsave(ws) {
if(!ws || !ws['!ref']) return "";
Expand All @@ -262,6 +270,18 @@ var sheet_to_socialcalc = (function() {
oo[2] = 'v';
oo.push(cell.v);
} break;
case 'b':
if(cell.f) {
oo[2] = 'vtf';
oo.push('nl');
oo.push(cell.v ? 1 : 0);
oo.push(scencode(cell.f));
} else {
oo[2] = 'vtc';
oo.push('nl');
oo.push(cell.v ? 1 : 0);
oo.push(cell.v ? 'TRUE' : 'FALSE');
} break;
}
o.push(oo.join(":"));
}
Expand All @@ -274,7 +294,7 @@ var sheet_to_socialcalc = (function() {

return function socialcalcify(ws, opts) {
return [header, sep, meta, sep, scsave(ws), end].join("\n");
return ["version:1.5", scsave(ws)].join("\n");
// return ["version:1.5", scsave(ws)].join("\n"); // clipboard form
};
})();

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "j",
"version": "0.3.15",
"version": "0.4.0",
"author": "sheetjs",
"description": "CLI tool for working with XLS/XLSX/XLSM/XLSB files",
"keywords": [ "excel", "xls", "xlsx", "xlsm", "xlsb", "office", "spreadsheet" ],
Expand All @@ -17,6 +17,7 @@
"dependencies": {
"xlsjs": "~0.7.1",
"xlsx": "~0.7.10",
"harb": "~0.0.2",
"concat-stream":"",
"commander":""
},
Expand Down

0 comments on commit d95408b

Please sign in to comment.