forked from SheetJS/sheetjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- frameworks: react, react-native, preact, next.js, weex, nuxt.js - deployments: nodejs server, duktape, chakra, electron, nw.js
- Loading branch information
1 parent
ad47cb4
commit f03e32f
Showing
58 changed files
with
1,731 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
jvm-npm.js | ||
sheetjs.* | ||
duk* | ||
*.class | ||
*.jar | ||
rhino | ||
xlsx.swift.js | ||
xlsx.*.js | ||
payload.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/* xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */ | ||
var wb = XLSX.read(payload, {type:'base64'}); | ||
console.log(XLSX.utils.sheet_to_csv(wb.Sheets[wb.SheetNames[0]])); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
DUKTAPE_VER=2.1.1 | ||
if [ ! -e duktape-$DUKTAPE_VER ]; then | ||
if [ ! -e duktape-$DUKTAPE_VER.tar ]; then | ||
if [ ! -e duktape-$DUKTAPE_VER.tar.xz ]; then | ||
curl -O http://duktape.org/duktape-$DUKTAPE_VER.tar.xz | ||
fi | ||
xz -d duktape-$DUKTAPE_VER.tar.xz | ||
fi | ||
tar -xf duktape-$DUKTAPE_VER.tar | ||
fi | ||
|
||
for f in duktape.{c,h} duk_config.h; do | ||
cp duktape-$DUKTAPE_VER/src/$f . | ||
done | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/* xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */ | ||
var global = (function(){ return this; }).call(null); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include "duktape.h" | ||
|
||
#define FAIL_LOAD { \ | ||
duk_push_undefined(ctx); \ | ||
perror("Error in load_file"); \ | ||
return 1; \ | ||
} | ||
|
||
static char *read_file(const char *filename, size_t *sz) { | ||
FILE *f = fopen(filename, "rb"); | ||
if(!f) return NULL; | ||
long fsize; { fseek(f, 0, SEEK_END); fsize = ftell(f); fseek(f, 0, SEEK_SET); } | ||
char *buf = (char *)malloc(fsize * sizeof(char)); | ||
*sz = fread((void *) buf, 1, fsize, f); | ||
fclose(f); | ||
return buf; | ||
} | ||
|
||
static duk_int_t eval_file(duk_context *ctx, const char *filename) { | ||
size_t len; char *buf = read_file(filename, &len); | ||
if(!buf) FAIL_LOAD | ||
|
||
duk_push_lstring(ctx, (const char *)buf, (duk_size_t)len); | ||
duk_int_t retval = duk_peval(ctx); | ||
duk_pop(ctx); | ||
return retval; | ||
} | ||
|
||
static duk_int_t load_file(duk_context *ctx, const char *filename, const char *var) { | ||
size_t len; char *buf = read_file(filename, &len); | ||
if(!buf) FAIL_LOAD | ||
|
||
duk_push_external_buffer(ctx); | ||
duk_config_buffer(ctx, -1, buf, len); | ||
duk_put_global_string(ctx, var); | ||
return 0; | ||
} | ||
|
||
static duk_int_t save_file(duk_context *ctx, const char *filename, const char *var) { | ||
duk_get_global_string(ctx, var); | ||
duk_size_t sz; | ||
char *buf = (char *)duk_get_buffer_data(ctx, -1, &sz); | ||
|
||
if(!buf) return 1; | ||
FILE *f = fopen(filename, "wb"); fwrite(buf, 1, sz, f); fclose(f); | ||
return 0; | ||
} | ||
|
||
#define FAIL(cmd) { \ | ||
printf("error in %s: %s\n", cmd, duk_safe_to_string(ctx, -1)); \ | ||
duk_destroy_heap(ctx); \ | ||
return res; \ | ||
} | ||
|
||
#define DOIT(cmd) duk_eval_string_noresult(ctx, cmd); | ||
int main(int argc, char *argv[]) { | ||
duk_int_t res = 0; | ||
|
||
/* initialize */ | ||
duk_context *ctx = duk_create_heap_default(); | ||
/* duktape does not expose a standard "global" by default */ | ||
DOIT("var global = (function(){ return this; }).call(null);"); | ||
|
||
/* load library */ | ||
res = eval_file(ctx, "xlsx.duktape.js"); | ||
if(res != 0) FAIL("library load") | ||
|
||
/* get version string */ | ||
duk_eval_string(ctx, "XLSX.version"); | ||
printf("SheetJS library version %s\n", duk_get_string(ctx, -1)); | ||
duk_pop(ctx); | ||
|
||
/* read file */ | ||
res = load_file(ctx, "sheetjs.xlsx", "buf"); | ||
if(res != 0) FAIL("load sheetjs.xlsx") | ||
|
||
/* parse workbook */ | ||
DOIT("wb = XLSX.read(buf, {type:'buffer'});"); | ||
DOIT("ws = wb.Sheets[wb.SheetNames[0]]"); | ||
|
||
/* print CSV */ | ||
duk_eval_string(ctx, "XLSX.utils.sheet_to_csv(ws)"); | ||
printf("%s\n", duk_get_string(ctx, -1)); | ||
duk_pop(ctx); | ||
|
||
/* change cell A1 to 3 */ | ||
DOIT("ws['A1'].v = 3; delete ws['A1'].w;"); | ||
|
||
/* write file */ | ||
DOIT("newbuf = XLSX.write(wb, {type:'buffer', bookType:'xlsx'})"); | ||
res = save_file(ctx, "sheetjsw.xlsx", "newbuf"); | ||
if(res != 0) FAIL("save sheetjsw.xlsx") | ||
|
||
/* cleanup */ | ||
duk_destroy_heap(ctx); | ||
return res; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.PHONY: init | ||
init: | ||
mkdir -p node_modules | ||
cd node_modules; if [ ! -e xlsx ]; then ln -s ../../../ xlsx ; fi; cd - | ||
|
||
.PHONY: run | ||
run: | ||
electron . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Electron | ||
|
||
This library is compatible with Electron and should just work out of the box. | ||
The demonstration uses Electron v1.7.5. The library is added via `require` from | ||
the render process. It can also be required from the main process, as shown in | ||
this demo to render a version string in the About dialog on OSX. | ||
|
||
The standard HTML5 `FileReader` techniques from the browser apply to Electron. | ||
This demo includes a drag-and-drop box as well as a file input box, mirroring | ||
the [SheetJS Data Preview Live Demo](http://oss.sheetjs.com/js-xlsx/) | ||
|
||
Since electron provides an `fs` implementation, `readFile` and `writeFile` can | ||
be used in conjunction with the standard dialogs. For example: | ||
|
||
```js | ||
var dialog = require('electron').remote.dialog; | ||
var o = (dialog.showOpenDialog({ properties: ['openFile'] })||[''])[0]; | ||
var workbook = X.readFile(o); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<!DOCTYPE html> | ||
<!-- xlsx.js (C) 2013-present SheetJS http://sheetjs.com --> | ||
<!-- vim: set ts=2: --> | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||
<title>SheetJS Electron Demo</title> | ||
<style> | ||
#drop{ | ||
border:2px dashed #bbb; | ||
-moz-border-radius:5px; | ||
-webkit-border-radius:5px; | ||
border-radius:5px; | ||
padding:25px; | ||
text-align:center; | ||
font:20pt bold,"Vollkorn";color:#bbb | ||
} | ||
a { text-decoration: none } | ||
</style> | ||
</head> | ||
<body> | ||
<pre> | ||
<b><a href="http://sheetjs.com">SheetJS Electron Demo</a></b> | ||
|
||
<a href="https://github.com/SheetJS/js-xlsx">Source Code Repo</a> | ||
<a href="https://github.com/SheetJS/js-xlsx/issues">Issues? Something look weird? Click here and report an issue</a> | ||
<br /> | ||
<button id="readf">Click here to select a file from your computer</button><br /> | ||
<div id="drop">Drop a spreadsheet file here to see sheet data</div> | ||
<input type="file" name="xlfile" id="xlf" /> ... or click here to select a file | ||
|
||
</pre> | ||
<div id="htmlout"></div> | ||
<br /> | ||
<script src="index.js"></script> | ||
</body> | ||
</html> |
Oops, something went wrong.