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.3.9: HTML output cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
SheetJSDev committed Jul 10, 2014
1 parent 94fcc2a commit 79f7448
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 9 deletions.
6 changes: 6 additions & 0 deletions .jscs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"requireCommaBeforeLineBreak": true,
"disallowTrailingWhitespace": true,
"disallowTrailingComma": true
}

2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
TARGET=j.js
FMT=xls xml xlsx xlsm xlsb misc
.PHONY: init
init:
Expand Down Expand Up @@ -27,6 +28,7 @@ numbers:
.PHONY: lint
lint: $(TARGET)
jshint --show-non-errors $(TARGET)
jscs $(TARGET)

.PHONY: cov cov-spin
cov: misc/coverage.html
Expand Down
43 changes: 35 additions & 8 deletions j.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* j -- (C) 2013-2014 SheetJS -- http://sheetjs.com */
/* vim: set ts=2: */
/*jshint node:true */
/*jshint node:true, eqnull:true */
var XLSX = require('xl'+'sx');
var XLS = require('xl'+'sjs');
var fs = require('f'+'s');
Expand Down Expand Up @@ -55,13 +55,39 @@ function get_cols(sheet, XL) {
r = _XL.utils.decode_range(sheet["!ref"]);
for (R = r.s.r, C = r.s.c; C <= r.e.c; ++C) {
val = sheet[_XL.utils.encode_cell({c:C, r:R})];
if(!val) continue;
hdr[C] = typeof val.w !== 'undefined' ? val.w : _XL.utils.format_cell ? XL.utils.format_cell(val) : val.v;
if(val == null) continue;
hdr[C] = val.w !== undefined ? val.w : _XL.utils.format_cell ? XL.utils.format_cell(val) : val.v;
}
return hdr;
}

function to_html(w) {
var XL = w[0], wb = w[1];
var json = to_json(w);
var tbl = {};
wb.SheetNames.forEach(function(sheet) {
var ws = wb.Sheets[sheet];
if(ws["!ref"] == null) return;
var src = "<h3>" + sheet + "</h3>";
var range = XL.utils.decode_range(ws["!ref"]);
src += "<table>";
src += "<colgroup span=\"" + (range.e.c - range.s.c + 1) + "\"></colgroup>";
for(var R = range.s.r; R <= range.e.r; ++R) {
src += "<tr>";
for(var C = range.s.c; C <= range.e.c; ++C) {
var val = ws[XL.utils.encode_cell({c:C,r:R})];
var w = val == null ? "" : val.w !== undefined ? val.w : XL.utils.format_cell ? XL.utils.format_cell(val) : val.v;
src += "<td>" + w + "</td>";
}
src += "</tr>";
}
src += "</table>";
tbl[sheet] = src;
});
return tbl;
}

function to_html_cols(w) {
var XL = w[0], wb = w[1];
var json = to_json(w);
var tbl = {};
Expand All @@ -70,11 +96,11 @@ function to_html(w) {
var src = "<h3>" + sheet + "</h3>";
src += "<table>";
src += "<thead><tr>";
cols.forEach(function(c) { src += "<th>" + (typeof c !== "undefined" ? c : "") + "</th>"; });
cols.forEach(function(c) { src += "<th>" + (c !== undefined ? c : "") + "</th>"; });
src += "</tr></thead>";
(json[sheet]||[]).forEach(function(row) {
src += "<tr>";
cols.forEach(function(c) { src += "<td>" + (typeof row[c] !== "undefined" ? row[c] : "") + "</td>"; });
cols.forEach(function(c) { src += "<td>" + (row[c] !== undefined ? row[c] : "") + "</td>"; });
src += "</tr>";
});
src += "</table>";
Expand Down Expand Up @@ -125,10 +151,10 @@ function to_xml(w) {
function to_xlsx_factory(t) {
return function(w, o) {
o = o || {}; o.bookType = t;
if(typeof o.bookSST === 'undefined') o.bookSST = true;
if(typeof o.type === 'undefined') o.type = 'buffer';
if(o.bookSST === undefined) o.bookSST = true;
if(o.type === undefined) o.type = 'buffer';
return XLSX.write(w[1], o);
}
};
}

var to_xlsx = to_xlsx_factory('xlsx');
Expand All @@ -148,6 +174,7 @@ module.exports = {
to_xlsb: to_xlsb,
to_json: to_json,
to_html: to_html,
to_html_cols: to_html_cols,
to_formulae: to_formulae,
get_cols: get_cols
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "j",
"version": "0.3.8",
"version": "0.3.9",
"author": "sheetjs",
"description": "CLI tool for working with XLS/XLSX/XLSM/XLSB files",
"keywords": [ "excel", "xls", "xlsx", "xlsm", "xlsb", "office", "spreadsheet" ],
Expand Down
1 change: 1 addition & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ files.forEach(function(x) {
J.utils.to_json(wb, true);
J.utils.to_json(wb, false);
J.utils.to_dsv(wb,",", "\n");
J.utils.to_dsv(wb,";", "\n");
J.utils.to_html(wb);
J.utils.to_xml(wb);
});
Expand Down
9 changes: 9 additions & 0 deletions tests.lst
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ apachepoi_56274.xlsx
apachepoi_56278.xlsx
apachepoi_56315.xlsx
apachepoi_56325.xls
apachepoi_56420.xlsx
apachepoi_56450.xls
apachepoi_56482.xls
apachepoi_56514.xlsx
Expand Down Expand Up @@ -476,6 +477,7 @@ apachepoi_workbookProtection_workbook_structure_protected.xlsx
apachepoi_workbookProtection_workbook_windows_protected.xlsx
apachepoi_workbookProtection_worksheet_protected.xlsx
apachepoi_xlsx-jdbc.xlsx
apachepoi_xor-encryption-abc.xls.pending
apachepoi_yearfracExamples.xls
calendar_stress_test.xls.pending
calendar_stress_test.xlsb.pending
Expand Down Expand Up @@ -754,6 +756,10 @@ number_format.xlsb
number_format.xlsb.xml
number_format.xlsm
number_format.xlsm.xml
number_format_russian.xls
number_format_russian.xlsb
number_format_russian.xlsm
number_format_russian.xml
oo34xml_cell_pattern.xml
oo34xml_cellstyle.xml
oo34xml_conditionalformat.xml
Expand Down Expand Up @@ -905,6 +911,9 @@ spreadsheet-parsexlsx_bug-6-2.xlsx
spreadsheet-parsexlsx_bug-6.xlsx
spreadsheet-parsexlsx_bug-7.xlsx
spreadsheet-parsexlsx_bug-8.xlsx
spreadsheet-parsexlsx_bug-lock.xlsx
spreadsheet-parsexlsx_column-formats.xlsx
spreadsheet-parsexlsx_tab-color.xlsx
sushi.xls
sushi.xlsb
sushi.xlsx
Expand Down

0 comments on commit 79f7448

Please sign in to comment.