ce icon indicating copy to clipboard operation
ce copied to clipboard

JSON data(key/value pair) support in JExcel ?

Open thelightbringer opened this issue 7 years ago • 4 comments

Is there any future roadmap for supporting JSON data(key/value pair) in JExcel ? Btw kudos to developer for the library.

thelightbringer avatar Aug 07 '19 10:08 thelightbringer

I've been playing with this library and love it very much so far, I'm using V2 but needed JSON for MVC so I wrote this subroutine as an addon.

        getJSON: function (highlighted) {
            // Control vars
            var dataset = [];

            var id = $(this).prop('id');

            // Column and row length
            var x = $.fn.jexcel.defaults[id].columns.length;
            var y = $.fn.jexcel.defaults[id].data.length;

            // Go through the columns to get the data
            for (j = 0; j < y; j++) {

                var data = new Object();

                for (i = 0; i < x; i++) {
                    // Cell
                    cell = $(this).find('#' + i + '-' + j);

                    // Cell selected or fullset
                    if (!highlighted || $(cell).hasClass('highlight')) {
                        // Get value
                        colName = $.fn.jexcel.defaults[id].colHeaders[i];
                        colName = colName == undefined ? x : colName;
                        data[colName] = $(this).jexcel('getValue', $(cell));
                    }
                }
                dataset.push(data);
            }

            return JSON.stringify(dataset);
        },

AdemusPrime avatar Aug 14 '19 19:08 AdemusPrime

I have some issue. I want to get json with key and value. can anybody help?

glenoka avatar Sep 27 '19 04:09 glenoka

This is now supported. Example:

https://jsfiddle.net/paulhodel/jv7sth0z/

pphod avatar Oct 19 '19 11:10 pphod

Thanks :)

thelightbringer avatar Nov 21 '19 06:11 thelightbringer