packages/opal-node-msexcel/msexcel.js
function readRegion(ws, range, opts) {
        let contents = {};
        opts = (opts === undefined) ? {} : opts;
        // console.log('Xref:%s', ws['!ref']);
        let dORange = xlsx.utils.decode_range(ws['!ref']);
        let dRange = xlsx.utils.decode_range(range);

        // Support for cols only ranges like !A:A,!A:C
        dRange.s.r = (isNaN(dRange.s.r)) ? dORange.s.r : dRange.s.r;
        dRange.e.r = (isNaN(dRange.e.r)) ? dORange.e.r : dRange.e.r;

        // Single for row only ranges like !1:1, !1:3
        dRange.s.c = (dRange.s.c === -1) ? dORange.s.c : dRange.s.c;
        dRange.e.c = (dRange.e.c === -1) ? dORange.e.c : dRange.e.c;

        for (let R = dRange.s.r; R <= dRange.e.r; ++R) {
            for (let C = dRange.s.c; C <= dRange.e.c; ++C) {
                let cellref = xlsx.utils.encode_cell({c: C, r: R});
                contents[cellref] = ws[cellref] || {};
            }
        }
        // console.log(JSON.stringify(dRange));
        contents['!ref'] = xlsx.utils.encode_range(dRange);

        if (opts.asis) {
            return contents;
        }

        Object.assign(opts, {
            header: 1,
            raw: true,
            blankrows: true,
        });

        opts.header = opts.useLabel ? 'A' : opts.header;

        let contentsJson = xlsx.utils.sheet_to_json(contents, opts);

        if (opts.removeEmpty) {
            contentsJson = contentsJson.filter((row) => {
                // console.log(typeof row);
                return check.object(row) ?
                    check.nonEmptyObject(row) : check.nonEmptyArray(row);
            });
        }
        return contentsJson;
    }
function readRegion(ws, range, opts) {
        let contents = {};
        opts = (opts === undefined) ? {} : opts;
        // console.log('Xref:%s', ws['!ref']);
        let dORange = xlsx.utils.decode_range(ws['!ref']);
        let dRange = xlsx.utils.decode_range(range);

        // Support for cols only ranges like !A:A,!A:C
        dRange.s.r = (isNaN(dRange.s.r)) ? dORange.s.r : dRange.s.r;
        dRange.e.r = (isNaN(dRange.e.r)) ? dORange.e.r : dRange.e.r;

        // Single for row only ranges like !1:1, !1:3
        dRange.s.c = (dRange.s.c === -1) ? dORange.s.c : dRange.s.c;
        dRange.e.c = (dRange.e.c === -1) ? dORange.e.c : dRange.e.c;

        for (let R = dRange.s.r; R <= dRange.e.r; ++R) {
            for (let C = dRange.s.c; C <= dRange.e.c; ++C) {
                let cellref = xlsx.utils.encode_cell({c: C, r: R});
                contents[cellref] = ws[cellref] || {};
            }
        }
        // console.log(JSON.stringify(dRange));
        contents['!ref'] = xlsx.utils.encode_range(dRange);

        if (opts.asis) {
            return contents;
        }

        Object.assign(opts, {
            header: 1,
            raw: true,
            blankrows: true,
        });

        opts.header = opts.useLabel ? 'A' : opts.header;

        let contentsJson = xlsx.utils.sheet_to_json(contents, opts);

        if (opts.removeEmpty) {
            contentsJson = contentsJson.filter((row) => {
                // console.log(typeof row);
                return check.object(row) ?
                    check.nonEmptyObject(row) : check.nonEmptyArray(row);
            });
        }
        return contentsJson;
    }
function readRegion ( ws , range , opts ) { let contents = { } ; opts = ( opts === undefined ) ? { } : opts ; // console.log('Xref:%s', ws['!ref']); let dORange = xlsx . utils . decode_range ( ws [ '!ref' ] ) ; let dRange = xlsx . utils . decode_range ( range ) ; // Support for cols only ranges like !A:A,!A:C dRange . s . r = ( isNaN ( dRange . s . r ) ) ? dORange . s . r : dRange . s . r ; dRange . e . r = ( isNaN ( dRange . e . r ) ) ? dORange . e . r : dRange . e . r ; // Single for row only ranges like !1:1, !1:3 dRange . s . c = ( dRange . s . c === - 1 ) ? dORange . s . c : dRange . s . c ; dRange . e . c = ( dRange . e . c === - 1 ) ? dORange . e . c : dRange . e . c ; for ( let R = dRange . s . r ; R <= dRange . e . r ; ++ R ) { for ( let C = dRange . s . c ; C <= dRange . e . c ; ++ C ) { let cellref = xlsx . utils . encode_cell ( { c : C , r : R } ) ; contents [ cellref ] = ws [ cellref ] || { } ; } } // console.log(JSON.stringify(dRange)); contents [ '!ref' ] = xlsx . utils . encode_range ( dRange ) ; if ( opts . asis ) { return contents ; } Object . assign ( opts , { header : 1 , raw : true , blankrows : true , } ) ; opts . header = opts . useLabel ? 'A' : opts . header ; let contentsJson = xlsx . utils . sheet_to_json ( contents , opts ) ; if ( opts . removeEmpty ) { contentsJson = contentsJson . filter ( ( row ) => { // console.log(typeof row); return check . object ( row ) ? check . nonEmptyObject ( row ) : check . nonEmptyArray ( row ) ; } ) ; } return contentsJson ; }
reads a specified region from an opened workbook
@function
@param {object} ws - worksheet.
@param {object} range - rows to be fetched.
@param {{asis: bool,
useLabel: boolean,
header: string,
removeEmpty:boolean}} opts - options for processing the read request
@return {object} contentsJson - returns the fetched content as a JSON
reads a specified region from an opened workbook