packages/opal-node-msexcel/msexcel.js
function readCols(ws, cols, opts) {
        // console.log('Reading cols ' + cols.length);
        // console.log(cols);
        let contents = {};
        if (typeof cols === 'string') {
            cols = cols.split(',');
        }
        opts = (opts === undefined) ? {} : opts;
        let dRange = xlsx.utils.decode_range(ws['!ref']);
        for (let i = 0; i < cols.length; ++i) {
            // console.log('Reading col:' + cols[i]);
            let dCol = xlsx.utils.decode_col(cols[i]);
            for (let R = dRange.s.r; R <= dRange.e.r; ++R) {
                // console.log('Reading cell:' + cols[i] + ', ' + R);
                let encCell = xlsx.utils.encode_cell({c: dCol, r: R});
                contents[encCell] = ws[encCell] || {};
                // console.log('Done cell:' + cols[i] + ', ' + R + ', ' + JSON.stringify(contents[encCell]));
            }
        }
        contents['!ref'] = ws['!ref'];

        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((col) => {
                // console.log(typeof col);
                return check.object(col) ? check.nonEmptyObject(col) : check.nonEmptyArray(col);
            });
        }
        return contentsJson;
    }
function readCols(ws, cols, opts) {
        // console.log('Reading cols ' + cols.length);
        // console.log(cols);
        let contents = {};
        if (typeof cols === 'string') {
            cols = cols.split(',');
        }
        opts = (opts === undefined) ? {} : opts;
        let dRange = xlsx.utils.decode_range(ws['!ref']);
        for (let i = 0; i < cols.length; ++i) {
            // console.log('Reading col:' + cols[i]);
            let dCol = xlsx.utils.decode_col(cols[i]);
            for (let R = dRange.s.r; R <= dRange.e.r; ++R) {
                // console.log('Reading cell:' + cols[i] + ', ' + R);
                let encCell = xlsx.utils.encode_cell({c: dCol, r: R});
                contents[encCell] = ws[encCell] || {};
                // console.log('Done cell:' + cols[i] + ', ' + R + ', ' + JSON.stringify(contents[encCell]));
            }
        }
        contents['!ref'] = ws['!ref'];

        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((col) => {
                // console.log(typeof col);
                return check.object(col) ? check.nonEmptyObject(col) : check.nonEmptyArray(col);
            });
        }
        return contentsJson;
    }
function readCols ( ws , cols , opts ) { // console.log('Reading cols ' + cols.length); // console.log(cols); let contents = { } ; if ( typeof cols === 'string' ) { cols = cols . split ( ',' ) ; } opts = ( opts === undefined ) ? { } : opts ; let dRange = xlsx . utils . decode_range ( ws [ '!ref' ] ) ; for ( let i = 0 ; i < cols . length ; ++ i ) { // console.log('Reading col:' + cols[i]); let dCol = xlsx . utils . decode_col ( cols [ i ] ) ; for ( let R = dRange . s . r ; R <= dRange . e . r ; ++ R ) { // console.log('Reading cell:' + cols[i] + ', ' + R); let encCell = xlsx . utils . encode_cell ( { c : dCol , r : R } ) ; contents [ encCell ] = ws [ encCell ] || { } ; // console.log('Done cell:' + cols[i] + ', ' + R + ', ' + JSON.stringify(contents[encCell])); } } contents [ '!ref' ] = ws [ '!ref' ] ; 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 ( ( col ) => { // console.log(typeof col); return check . object ( col ) ? check . nonEmptyObject ( col ) : check . nonEmptyArray ( col ) ; } ) ; } return contentsJson ; }
reads a specified cols from an opened workbook
@function
@param {object} ws - worksheet.
@param {object} cols - cols 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 cols from an opened workbook