Skip to content

Commit 5de62a9

Browse files
committed
version bump 0.12.5: ancillary utility update
- add BOM to `stream.to_csv` (fixes #1024 h/t @hr5959) - `utils.format_cell` type (h/t @victorj2307) - duktape niggles - demo cleanup
1 parent 73a5e50 commit 5de62a9

66 files changed

Lines changed: 681 additions & 355 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.spelling

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ ui-grid
106106
angular-cli
107107

108108
- demos/database/README.md
109+
Knex
109110
LowDB
110111
MariaDB
111112
MySQL

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ In the browser, just add a script tag:
162162
| `unpkg` | <https://unpkg.com/xlsx/> |
163163
| `jsDelivr` | <https://jsdelivr.com/package/npm/xlsx> |
164164
| `CDNjs` | <http://cdnjs.com/libraries/xlsx> |
165+
| `packd` | <https://bundle.run/xlsx?name=XLSX> |
165166

166167
`unpkg` makes the latest version available at:
167168

bits/01_version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
XLSX.version = '0.12.4';
1+
XLSX.version = '0.12.5';

bits/55_vml.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ function write_comments_vml(rId, comments) {
1414
];
1515
while(_shapeid < rId * 1000) _shapeid += 1000;
1616

17-
comments.map(function(x) { return decode_cell(x[0]); }).forEach(function(c) { o = o.concat([
17+
comments.forEach(function(x) { var c = decode_cell(x[0]);
18+
o = o.concat([
1819
'<v:shape' + wxt_helper({
1920
id:'_x0000_s' + (++_shapeid),
2021
type:"#_x0000_t202",

bits/57_cmntxml.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,11 @@ function write_comments_xml(data/*::, opts*/) {
3636

3737
var iauthor/*:Array<string>*/ = [];
3838
o.push("<authors>");
39-
data.map(function(x) { return x[1]; }).forEach(function(comment) {
40-
comment.map(function(x) { return escapexml(x.a); }).forEach(function(a) {
41-
if(iauthor.indexOf(a) > -1) return;
42-
iauthor.push(a);
43-
o.push("<author>" + a + "</author>");
44-
});
45-
});
39+
data.forEach(function(x) { x[1].forEach(function(w) { var a = escapexml(w.a);
40+
if(iauthor.indexOf(a) > -1) return;
41+
iauthor.push(a);
42+
o.push("<author>" + a + "</author>");
43+
}); });
4644
o.push("</authors>");
4745
o.push("<commentList>");
4846
data.forEach(function(d) {

bits/75_xlml.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ function xlml_clean_comment(comment/*:any*/) {
163163
function xlml_normalize(d)/*:string*/ {
164164
if(has_buf &&/*::typeof Buffer !== "undefined" && d != null && d instanceof Buffer &&*/ Buffer.isBuffer(d)) return d.toString('utf8');
165165
if(typeof d === 'string') return d;
166+
/* duktape */
167+
if(typeof Uint8Array !== 'undefined' && d instanceof Uint8Array) return utf8read(a2s(ab2a(d)));
166168
throw new Error("Bad input format: expected Buffer or string");
167169
}
168170

bits/97_node.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ if(has_buf && typeof require != 'undefined') (function() {
1515
var rowinfo/*:Array<RowInfo>*/ = o.skipHidden && sheet["!rows"] || [];
1616
for(var C = r.s.c; C <= r.e.c; ++C) if (!((colinfo[C]||{}).hidden)) cols[C] = encode_col(C);
1717
var R = r.s.r;
18+
var BOM = false;
1819
stream._read = function() {
20+
if(!BOM) { BOM = true; return stream.push("\uFEFF"); }
1921
if(R > r.e.r) return stream.push(null);
2022
while(R <= r.e.r) {
2123
++R;

demos/altjs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ duk*
44
*.class
55
*.jar
66
rhino
7+
shim.min.js
78
xlsx.*.js
89
payload.js

demos/altjs/Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@ all: duktape nashorn rhinojs swift
55
base:
66
if [ ! -e sheetjs.xlsx ]; then node ../../tests/write.js; fi
77
if [ ! -e xlsx.full.min.js ]; then cp ../../dist/xlsx.full.min.js .; fi
8+
if [ ! -e shim.min.js ]; then cp ../../dist/shim.min.js .; fi
89

9-
.PHONY: duktape
10-
duktape: base ## duktape demo
10+
.PHONY: duk
11+
duk: base
1112
bash ./duktape.sh
1213
gcc -std=c99 -Wall -osheetjs.duk sheetjs.duk.c duktape.c -lm
13-
./sheetjs.duk
14+
15+
.PHONY: duktape
16+
duktape: duk ## duktape demo
17+
for ext in xlsx xlsb biff8.xls xml.xls; do ./sheetjs.duk sheetjs.$$ext; done
1418

1519
.PHONY: nashorn
1620
nashorn: base ## nashorn demo

demos/altjs/SheetJSCore.swift

Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -2,95 +2,95 @@
22
import JavaScriptCore;
33

44
enum SJSError: Error {
5-
case badJSContext;
6-
case badJSWorkbook;
7-
case badJSWorksheet;
5+
case badJSContext;
6+
case badJSWorkbook;
7+
case badJSWorksheet;
88
};
99

1010
class SJSWorksheet {
11-
var context: JSContext!;
12-
var wb: JSValue!; var ws: JSValue!;
13-
var idx: Int32;
11+
var context: JSContext!;
12+
var wb: JSValue!; var ws: JSValue!;
13+
var idx: Int32;
1414

15-
func toCSV() throws -> String {
16-
let XLSX: JSValue! = context.objectForKeyedSubscript("XLSX");
17-
let utils: JSValue! = XLSX.objectForKeyedSubscript("utils");
18-
let sheet_to_csv: JSValue! = utils.objectForKeyedSubscript("sheet_to_csv");
19-
return sheet_to_csv.call(withArguments: [ws]).toString();
20-
}
15+
func toCSV() throws -> String {
16+
let XLSX: JSValue! = context.objectForKeyedSubscript("XLSX");
17+
let utils: JSValue! = XLSX.objectForKeyedSubscript("utils");
18+
let sheet_to_csv: JSValue! = utils.objectForKeyedSubscript("sheet_to_csv");
19+
return sheet_to_csv.call(withArguments: [ws]).toString();
20+
}
2121

22-
init(ctx: JSContext, workbook: JSValue, worksheet: JSValue, idx: Int32) throws {
23-
self.context = ctx; self.wb = workbook; self.ws = worksheet; self.idx = idx;
24-
}
22+
init(ctx: JSContext, workbook: JSValue, worksheet: JSValue, idx: Int32) throws {
23+
self.context = ctx; self.wb = workbook; self.ws = worksheet; self.idx = idx;
24+
}
2525
}
2626

2727
class SJSWorkbook {
28-
var context: JSContext!;
29-
var wb: JSValue!; var SheetNames: JSValue!; var Sheets: JSValue!;
28+
var context: JSContext!;
29+
var wb: JSValue!; var SheetNames: JSValue!; var Sheets: JSValue!;
3030

31-
func getSheetAtIndex(idx: Int32) throws -> SJSWorksheet {
32-
let SheetName: String = SheetNames.atIndex(Int(idx)).toString();
33-
let ws: JSValue! = Sheets.objectForKeyedSubscript(SheetName);
34-
return try SJSWorksheet(ctx: context, workbook: wb, worksheet: ws, idx: idx);
35-
}
31+
func getSheetAtIndex(idx: Int32) throws -> SJSWorksheet {
32+
let SheetName: String = SheetNames.atIndex(Int(idx)).toString();
33+
let ws: JSValue! = Sheets.objectForKeyedSubscript(SheetName);
34+
return try SJSWorksheet(ctx: context, workbook: wb, worksheet: ws, idx: idx);
35+
}
3636

37-
func writeBStr(bookType: String = "xlsx") throws -> String {
38-
let XLSX: JSValue! = context.objectForKeyedSubscript("XLSX");
39-
context.evaluateScript(String(format: "var writeopts = {type:'binary', bookType:'%@'}", bookType));
40-
let writeopts: JSValue! = context.objectForKeyedSubscript("writeopts");
41-
let writefunc: JSValue! = XLSX.objectForKeyedSubscript("write");
42-
return writefunc.call(withArguments: [wb, writeopts]).toString();
43-
}
37+
func writeBStr(bookType: String = "xlsx") throws -> String {
38+
let XLSX: JSValue! = context.objectForKeyedSubscript("XLSX");
39+
context.evaluateScript(String(format: "var writeopts = {type:'binary', bookType:'%@'}", bookType));
40+
let writeopts: JSValue! = context.objectForKeyedSubscript("writeopts");
41+
let writefunc: JSValue! = XLSX.objectForKeyedSubscript("write");
42+
return writefunc.call(withArguments: [wb, writeopts]).toString();
43+
}
4444

45-
init(ctx: JSContext, wb: JSValue) throws {
46-
self.context = ctx;
47-
self.wb = wb;
48-
self.SheetNames = wb.objectForKeyedSubscript("SheetNames");
49-
self.Sheets = wb.objectForKeyedSubscript("Sheets");
50-
}
45+
init(ctx: JSContext, wb: JSValue) throws {
46+
self.context = ctx;
47+
self.wb = wb;
48+
self.SheetNames = wb.objectForKeyedSubscript("SheetNames");
49+
self.Sheets = wb.objectForKeyedSubscript("Sheets");
50+
}
5151
}
5252

5353
class SheetJSCore {
54-
var context: JSContext!;
55-
var XLSX: JSValue!;
54+
var context: JSContext!;
55+
var XLSX: JSValue!;
5656

57-
func init_context() throws -> JSContext {
58-
var context: JSContext!
59-
do {
60-
context = JSContext();
61-
context.exceptionHandler = { ctx, X in if let e = X { print(e.toString()); }; };
62-
context.evaluateScript("var global = (function(){ return this; }).call(null);");
63-
context.evaluateScript("if(typeof wbs == 'undefined') wbs = [];");
64-
let src = try String(contentsOfFile: "xlsx.full.min.js");
65-
context.evaluateScript(src);
66-
if context != nil { return context!; }
67-
} catch { print(error.localizedDescription); }
68-
throw SJSError.badJSContext;
69-
}
57+
func init_context() throws -> JSContext {
58+
var context: JSContext!
59+
do {
60+
context = JSContext();
61+
context.exceptionHandler = { ctx, X in if let e = X { print(e.toString()); }; };
62+
context.evaluateScript("var global = (function(){ return this; }).call(null);");
63+
context.evaluateScript("if(typeof wbs == 'undefined') wbs = [];");
64+
let src = try String(contentsOfFile: "xlsx.full.min.js");
65+
context.evaluateScript(src);
66+
if context != nil { return context!; }
67+
} catch { print(error.localizedDescription); }
68+
throw SJSError.badJSContext;
69+
}
7070

71-
func version() throws -> String {
72-
if let version = XLSX.objectForKeyedSubscript("version") { return version.toString(); }
73-
throw SJSError.badJSContext;
74-
}
71+
func version() throws -> String {
72+
if let version = XLSX.objectForKeyedSubscript("version") { return version.toString(); }
73+
throw SJSError.badJSContext;
74+
}
7575

76-
func readFile(file: String) throws -> SJSWorkbook {
77-
let data: String! = try String(contentsOfFile: file, encoding: String.Encoding.isoLatin1);
78-
return try readBStr(data: data);
79-
}
76+
func readFile(file: String) throws -> SJSWorkbook {
77+
let data: String! = try String(contentsOfFile: file, encoding: String.Encoding.isoLatin1);
78+
return try readBStr(data: data);
79+
}
8080

81-
func readBStr(data: String) throws -> SJSWorkbook {
82-
context.setObject(data, forKeyedSubscript: "payload" as (NSCopying & NSObjectProtocol)!);
83-
context.evaluateScript("var wb = XLSX.read(payload, {type:'binary'});");
84-
let wb: JSValue! = context.objectForKeyedSubscript("wb");
85-
if wb == nil { throw SJSError.badJSWorkbook; }
86-
return try SJSWorkbook(ctx: context, wb: wb);
87-
}
81+
func readBStr(data: String) throws -> SJSWorkbook {
82+
context.setObject(data, forKeyedSubscript: "payload" as (NSCopying & NSObjectProtocol)!);
83+
context.evaluateScript("var wb = XLSX.read(payload, {type:'binary'});");
84+
let wb: JSValue! = context.objectForKeyedSubscript("wb");
85+
if wb == nil { throw SJSError.badJSWorkbook; }
86+
return try SJSWorkbook(ctx: context, wb: wb);
87+
}
8888

89-
init() throws {
90-
do {
91-
self.context = try init_context();
92-
self.XLSX = self.context.objectForKeyedSubscript("XLSX");
93-
if self.XLSX == nil { throw SJSError.badJSContext; }
94-
} catch { print(error.localizedDescription); }
95-
}
89+
init() throws {
90+
do {
91+
self.context = try init_context();
92+
self.XLSX = self.context.objectForKeyedSubscript("XLSX");
93+
if self.XLSX == nil { throw SJSError.badJSContext; }
94+
} catch { print(error.localizedDescription); }
95+
}
9696
}

0 commit comments

Comments
 (0)