ce icon indicating copy to clipboard operation
ce copied to clipboard

getData will return the formulas applied to cells instead of the value in the table.

Open avidsouza opened this issue 7 years ago • 7 comments

var data = $('#my').jexcel('getData');

Please guide me how to getData from the table the actual cell values instead of the formulas.

avidsouza avatar Feb 05 '19 08:02 avidsouza

I think there is no built-in way to do it.

Only solution that I've found is from #225:

$('yourtable').find('#0-0').text(); // for Colum A1

lioneil avatar Jun 02 '19 14:06 lioneil

Yes, this is the only way to get the parsed values.

pphod avatar Jun 02 '19 14:06 pphod

Here's one way to retrieve:

let _cells = [];
let ddd = [];
let dd = $('yourtable').find('tr').map(function () {
  let tds = $('yourtable').find('td').map(function () {
    return $(this).text();
  });
  ddd.push(tds)
  return tds;
});
_cells.push(dd);

// Compare the two.
console.log(_cells, $('yourtable').jexcel('getData'));

That's ^ untested but you get the idea.

lioneil avatar Jun 02 '19 15:06 lioneil

This didn't work for me. I had to get the values by using the data-x and data-y attributes of the table cell.

Here's a function to return a cell reference (e.g. A1) as x, y co-ordinate:

var xy = cellref(mycell).split(",");
value = $('td[data-x="' + xy[0] + '"][data-y="' + xy[1] + '"]').html();

function cellref(thisCell) {
                var x = thisCell.replace(/[^A-Za-z]/g, "");
                x = x.charCodeAt(0) - 65;
                var y = thisCell.replace(/\D/g, "");
                y = y - 1;
                return x + "," + y;
            }

andyhclark avatar Aug 01 '19 13:08 andyhclark

You can use the initial option

copyCompatibility: true

This means the copy and export will take into consideration the results, not formulas. Only valid for v3.

pphod avatar Aug 01 '19 20:08 pphod

This didn't work for me. I had to get the values by using the data-x and data-y attributes of the table cell.

Here's a function to return a cell reference (e.g. A1) as x, y co-ordinate:

var xy = cellref(mycell).split(",");
value = $('td[data-x="' + xy[0] + '"][data-y="' + xy[1] + '"]').html();

function cellref(thisCell) {
                var x = thisCell.replace(/[^A-Za-z]/g, "");
                x = x.charCodeAt(0) - 65;
                var y = thisCell.replace(/\D/g, "");
                y = y - 1;
                return x + "," + y;
            }

This is very useful

Sergio2R avatar Feb 11 '20 13:02 Sergio2R

Using copyCompatibility: true you will get the values not formulas.

pphod avatar Feb 11 '20 23:02 pphod