ce icon indicating copy to clipboard operation
ce copied to clipboard

Updating data for formula's leading to Uncaught TypeError

Open NinjaChristopher opened this issue 7 years ago • 9 comments

image

The image above shows the table I am currently using where the yellow columns contain formula's. Updating the values in the white columns should therefore update the yellow column values. This works, up to a certain point. When I try to update some of the white cells I get the error:

Uncaught TypeError: Cannot read property '0' of undefined jexcel.js:1558 at updateFormulaChain (jexcel.js:1558) at Object.obj.setValue (jexcel.js:1569) at Object.obj.closeEditor (jexcel.js:1446) at HTMLInputElement.editor.onblur (jexcel.js:1379) at HTMLDocument.jexcel.keyDownControls (jexcel.js:5736)

I wasn't able to figure out what was causing the error, I was hoping you could tell me whether it is something wrong on my end (although I think I did everything according to your documentation) or whether it is something that has to be fixed in the source code?

EDIT: The '0' changes depending on the cell I try to update. So e.g. sometimes it gives the error Uncaught TypeError: Cannot read property '5' of undefined

NinjaChristopher avatar Jul 03 '19 08:07 NinjaChristopher

Can you create a jsfiddle with your table, please?

pphod avatar Jul 03 '19 08:07 pphod

https://jsfiddle.net/NinjaChristopher/ywjbn5s3/18/

NinjaChristopher avatar Jul 03 '19 08:07 NinjaChristopher

It was due the readOnly directive. I have changed one thing and this will work fine. It will be in the master repository in 30 minutes.

pphod avatar Jul 03 '19 19:07 pphod

@paulhodel Really appreciate you looking into it!

Unfortunately I am still encountering the issue, as you will be able to see in the JS fiddle. Is it already in the master repository? If so, maybe there is something else going on as well.

NinjaChristopher avatar Jul 04 '19 12:07 NinjaChristopher

@paulhodel Could you please reopen this issue and take another look at what may be causing this. I saw you made some changes, but unfortunately those did not resolve the problem as you can see in the JSFiddle. The same error appears.

// Update formula chain var updateFormulaChain = function(x, y) { var cellId = jexcel.getColumnNameFromId([x, y]); if (obj.formula[cellId] && obj.formula[cellId].length > 0) { for (var i = 0; i < obj.formula[cellId].length; i++) { var cell = jexcel.getIdFromColumnName(obj.formula[cellId][i], true); // Update cell var value = ''+obj.options.data[cell[1]][cell[0]]; <-- Uncaught TypeError: Cannot read property '0' of undefined if (value.substr(0,1) == '=') { records.push(obj.updateCell(cell[0], cell[1], value, true)); } else { // No longer a formula, remove from the chain Object.keys(obj.formula)[i] = null; } updateFormulaChain(cell[0], cell[1]); } } } updateFormulaChain(x, y);

image

Not sure whether this helps, but this is the line where I keep getting the uncaught type error.

Really appreciate all the time and effort you're putting into this!

EDIT: Added screenshot

NinjaChristopher avatar Jul 08 '19 07:07 NinjaChristopher

It has been fixed now.

pphod avatar Jul 09 '19 09:07 pphod

Not sure whether this helps, but this is the line where I keep getting the uncaught type error.

i am getting the same error

NomanChali avatar Oct 07 '19 07:10 NomanChali

i got the cause of issue this is what i have done to fix the issue locally if by chance anyone wants to refer

var cell = jexcel.getIdFromColumnName(obj.formula[cellId][i], true);
if(obj.options.data[cell[1]]){ // added if condition to check obj.options.data[cell[1]]
	// Update cell
	var value = ''+obj.options.data[cell[1]][cell[0]];
	if (value.substr(0,1) == '=') {
		records.push(obj.updateCell(cell[0], cell[1], value, true));
	} else {
		// No longer a formula, remove from the chain
		Object.keys(obj.formula)[i] = null;
	}
}

NomanChali avatar Oct 07 '19 08:10 NomanChali

In my case, remaining formula was the problem.

So I cleared formula by sheet0.formual = [] when chnaging sheet data.

0Chan-smc avatar Mar 27 '24 04:03 0Chan-smc