forked from sheetjs/sheetjs
SheetJS
ab2ecebac9
- basic support for parsing BIFF2-4 - basic support for writing BIFF2 - cleaned up some bad substr uses for IE6 compatibility - added flow type annotations for xlsx.flow.js - added numerous null guards (fixes #255 h/t @martinheidegger) - README cleanup (fixes #539 h/t @oliversalzburg) - pin jszip to local version (closes #408 h/t @limouri) bower issues: | id | author | comment | |-----:|:------------------|:------------------------------------------| | #254 | @kkirsche | fixes #254 by removing version from json | | #165 | @vincentcialdella | fixes #165 by changing default script | | #180 | @owencraig | fixes #180 by using xlsx.core.min.js | format issues: | id | author | comment | |-----:|:------------------|:------------------------------------------| | #271 | @morstaine | fixes #271 by reworking related parse fns | | #504 | @JanSchuermannPH | fixes #504 detect FullPaths h/t @Mithgol | | #508 | @basma-emad | fixes #508 offending file used `x:` NS |
54 lines
1.9 KiB
JavaScript
54 lines
1.9 KiB
JavaScript
function getdatastr(data)/*:?string*/ {
|
|
if(!data) return null;
|
|
if(data.data) return debom_xml(data.data);
|
|
if(data.asNodeBuffer && has_buf) return debom_xml(data.asNodeBuffer().toString('binary'));
|
|
if(data.asBinary) return debom_xml(data.asBinary());
|
|
if(data._data && data._data.getContent) return debom_xml(cc2str(Array.prototype.slice.call(data._data.getContent(),0)));
|
|
return null;
|
|
}
|
|
|
|
function getdatabin(data) {
|
|
if(!data) return null;
|
|
if(data.data) return char_codes(data.data);
|
|
if(data.asNodeBuffer && has_buf) return data.asNodeBuffer();
|
|
if(data._data && data._data.getContent) return Array.prototype.slice.call(data._data.getContent());
|
|
return null;
|
|
}
|
|
|
|
function getdata(data) { return (data && data.name.substr(data.name.length-4) === ".bin") ? getdatabin(data) : getdatastr(data); }
|
|
|
|
function safegetzipfile(zip, file/*:string*/) {
|
|
var f = file; if(zip.files[f]) return zip.files[f];
|
|
f = file.toLowerCase(); if(zip.files[f]) return zip.files[f];
|
|
f = f.replace(/\//g,'\\'); if(zip.files[f]) return zip.files[f];
|
|
return null;
|
|
}
|
|
|
|
function getzipfile(zip, file/*:string*/) {
|
|
var o = safegetzipfile(zip, file);
|
|
if(o == null) throw new Error("Cannot find file " + file + " in zip");
|
|
return o;
|
|
}
|
|
|
|
function getzipdata(zip, file/*:string*/, safe/*:?boolean*/) {
|
|
if(!safe) return getdata(getzipfile(zip, file));
|
|
if(!file) return null;
|
|
try { return getzipdata(zip, file); } catch(e) { return null; }
|
|
}
|
|
|
|
function getzipstr(zip, file/*:string*/, safe/*:?boolean*/)/*:?string*/ {
|
|
if(!safe) return getdatastr(getzipfile(zip, file));
|
|
if(!file) return null;
|
|
try { return getzipstr(zip, file); } catch(e) { return null; }
|
|
}
|
|
|
|
var _fs, jszip;
|
|
/*:: declare var JSZip:any; */
|
|
if(typeof JSZip !== 'undefined') jszip = JSZip;
|
|
if (typeof exports !== 'undefined') {
|
|
if (typeof module !== 'undefined' && module.exports) {
|
|
if(typeof jszip === 'undefined') jszip = require('./js'+'zip');
|
|
_fs = require('f'+'s');
|
|
}
|
|
}
|