read-excel-file
Version:
Read `.xlsx` files in a web browser or in Node.js
32 lines (31 loc) • 1.38 kB
JavaScript
// Unzipper is multi-threaded and it spawns a separate worker for each individual file
// inside the archive that is large-enough to justify spawning a worker.
// Because it uses its own `Worker` implementation, it won't use `createWorkerFunction()`.
//
// XML parser is itself single-threaded but it could spawn a separate worker for each
// individual `.xml` file that is large-enough to justify spawning a worker.
// So it could use `createWorkerFunction()`.
//
import createWorkerFunction from 'worker-f/browser';
import parseXml from '../xml/parseXml.js';
import unpackXlsxFile from './unpackXlsxFileBrowser.js';
import parseSheet from './parseSheet.js';
/**
* Reads a single sheet from an `.xlsx` file.
* @param {(File|Blob|ArrayBuffer)} input
* @param {(number|string)} [sheet] — Sheet number or sheet name
* @param {object} [options]
* @return {Promise<SheetData>}
*/
export default function readSheet(input, sheet, options) {
// `sheet` argument is optional.
// It could be omitted while `options` argument is passed.
if (!options && sheet && typeof sheet !== 'number' && typeof sheet !== 'string') {
options = sheet;
sheet = undefined;
}
return unpackXlsxFile(input).then(function (contents) {
return parseSheet(createWorkerFunction, parseXml, contents, sheet, options);
});
}
//# sourceMappingURL=readSheetWebWorker.js.map