资源简介
离线上传Excel 文件 并在浏览器中解析文件, 减少与服务器之间得交互
代码片段和文件信息
/* xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */
#include
#include
#include
#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 “shim.min.js“);
if(res != 0) FAIL(“shim load“)
res = eval_file(ctx “xlsx.full.min.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 argv[1] “buf“);
if(res != 0) FAIL(“file load“)
printf(“Loaded file %s\n“ argv[1]);
/* parse workbook */
DOIT(“wb = XLSX.read(buf {type:‘buffer‘ cellNF:true});“);
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 */
#define WRITE_TYPE(BOOKTYPE) \
DOIT(“newbuf = (XLSX.write(wb {type:‘array‘ bookType:‘“ BOOKTYPE “‘}));“);\
res = save_file(ctx “sheetjsw.“ BOOKTYPE “newbuf“);\
if(res != 0) FAIL(“save sheetjsw.“ BOOKTYPE)
WRITE_TYPE(“xlsb“)
WRITE_TYPE(“xlsx“)
WRITE_TYPE(“xls“)
WRITE_TYPE(“csv“)
/* cleanup */
duk_destroy_heap(ctx);
return res;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-06-22 21:40 js-xlsx-master\
文件 518 2018-06-22 21:40 js-xlsx-master\.eslintrc
文件 501 2018-06-22 21:40 js-xlsx-master\.flowconfig
文件 116 2018-06-22 21:40 js-xlsx-master\.fossaignore
文件 315 2018-06-22 21:40 js-xlsx-master\.gitattributes
文件 464 2018-06-22 21:40 js-xlsx-master\.gitignore
文件 89 2018-06-22 21:40 js-xlsx-master\.gitmodules
文件 114 2018-06-22 21:40 js-xlsx-master\.jscs.json
文件 39 2018-06-22 21:40 js-xlsx-master\.jshintrc
文件 693 2018-06-22 21:40 js-xlsx-master\.npmignore
文件 1512 2018-06-22 21:40 js-xlsx-master\.spelling
文件 1278 2018-06-22 21:40 js-xlsx-master\.travis.yml
文件 2638 2018-06-22 21:40 js-xlsx-master\CHANGELOG.md
文件 2304 2018-06-22 21:40 js-xlsx-master\CONTRIBUTING.md
文件 11356 2018-06-22 21:40 js-xlsx-master\LICENSE
文件 7663 2018-06-22 21:40 js-xlsx-master\Makefile
文件 109512 2018-06-22 21:40 js-xlsx-master\README.md
目录 0 2018-06-22 21:40 js-xlsx-master\bin\
文件 9893 2018-06-22 21:40 js-xlsx-master\bin\xlsx.njs
目录 0 2018-06-22 21:40 js-xlsx-master\bits\
文件 5 2018-06-22 21:40 js-xlsx-master\bits\.npmignore
文件 246 2018-06-22 21:40 js-xlsx-master\bits\00_header.js
文件 25 2018-06-22 21:40 js-xlsx-master\bits\01_version.js
文件 3169 2018-06-22 21:40 js-xlsx-master\bits\02_codepage.js
文件 37 2018-06-22 21:40 js-xlsx-master\bits\03_consts.js
文件 1317 2018-06-22 21:40 js-xlsx-master\bits\04_ba
文件 1839 2018-06-22 21:40 js-xlsx-master\bits\05_buf.js
文件 457 2018-06-22 21:40 js-xlsx-master\bits\09_types.js
文件 36841 2018-06-22 21:40 js-xlsx-master\bits\10_ssf.js
文件 3268 2018-06-22 21:40 js-xlsx-master\bits\11_ssfutils.js
文件 25867 2018-06-22 21:40 js-xlsx-master\bits\18_cfb.js
............此处省略505个文件信息
相关资源
- _upload_201106_BHT-600中文字库.zip
- Unity Offline Render
- gnuplot 4.6.3 windows版
- UpLoadFile MVC完整Demo支持断点续传
- ExtJS4MutiUpload.rar
- A2Uploader.rar
- layui-springmvc-imgupload.zip
- gnuplot 4.6 中文手册 修订2
- iar offline activator by unis v1.3.zip
- gnuplot5.0.5 windows安装包 亲测可用
- stm32F103GRBL系统脱机移植带屏幕控制
- springboot、vue-simple-uploader文件上传、续
- upload_new.rar
- springMVC结合webUploader完美实现图片上传
- OfflineExplorerPortable.exe破解版
- Offline Explorer Enterprise(离线浏览)V
- centos7 离线docker安装包全套
- uploaded-v2.6-node-v12.18.1-win-x64
- gp522-win64-mingw.exe
- CentOS7.6-Offline-nvidia-docker2.tgz
- WebUploader支持Web移动端上传
- OfflineExplorerPortable仿网站工具最强大没
- csdn_curve_upload.zip
- vs2017offline证书文件.rar
- 禾匠-榜店商城小程序V4_4.2.37独立版开
- Excel表格读取工具
- zyupload插件+js版代码
- 配合elementuiupload组件支持分片上传功
- springboot+webuploader 实现大文件切片上传
- myeclipse-pro-2014-GA-offline-installer-window
评论
共有 条评论