Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format whole column with numeric values #1339

Open
sonjadeissenboeck opened this issue Nov 5, 2018 · 7 comments
Open

Format whole column with numeric values #1339

sonjadeissenboeck opened this issue Nov 5, 2018 · 7 comments

Comments

@sonjadeissenboeck
Copy link

@sonjadeissenboeck sonjadeissenboeck commented Nov 5, 2018

I tried to add a formatter to my table columns that applies a new format to numeric cells. I used this #885 issue as a guide to my solution but it didn't seem to work.

Here's what I have:

`var column = oEvent.getSource().getParent().getParent().getLabel().getText();
var C = XLSX.utils.decode_col(column);
var fmt = "#,##0";
var range = XLSX.utils.decode_range(worksheet['!ref']);
for(var i = range.s.r + 1; i <= range.e.r; ++i) {
	 var ref = XLSX.utils.encode_cell({r:i, c:C});
	if(!worksheet[ref]) continue;
	if(worksheet[ref].t != 'n') continue;
	worksheet[ref].z = fmt;
}`

When I debug this code, I see that worksheet[ref] is "undefined". Even though ref itself is not undefined (e.g. it's "NIAYPRLSVBUYWS15") and my worksheet is also filled with the correct data.

Am I doing something wrong?
Thanks in advacne!

Note I'd like to apply that format AFTER the table has been rendered!

@SheetJSDev
Copy link
Contributor

@SheetJSDev SheetJSDev commented Nov 6, 2018

Are you sure the cells are numeric? As a quick test, add the line

	if(!worksheet[ref]) continue;
+	console.log(worksheet[ref].t);
	if(worksheet[ref].t != 'n') continue;

... and verify you are seeing a string of n for numeric cells.

@sonjadeissenboeck
Copy link
Author

@sonjadeissenboeck sonjadeissenboeck commented Nov 6, 2018

If I add the console.log part, it simply says "cannot read property "t" of undefined".
And yes, it's a numeric cell!
image

@SheetJSDev
Copy link
Contributor

@SheetJSDev SheetJSDev commented Nov 6, 2018

If there is formatted text, utilities will use the cached values. Delete the formatted text as follows:

	if(worksheet[ref].t != 'n') continue;
+	delete worksheet[ref].w;
	worksheet[ref].z = fmt;
@sonjadeissenboeck
Copy link
Author

@sonjadeissenboeck sonjadeissenboeck commented Nov 6, 2018

That's not working either and if you ask me, I understand why. worksheet[ref] is not defined, so you also can't delete it. The error must be somewhere earlier in the code, where worksheet[ref] is defined?

@sonjadeissenboeck
Copy link
Author

@sonjadeissenboeck sonjadeissenboeck commented Nov 12, 2018

@SheetJSDev Still looking for a solution!

@sonjadeissenboeck
Copy link
Author

@sonjadeissenboeck sonjadeissenboeck commented Dec 10, 2018

Please, still looking for help @SheetJSDev

@JeremyLandi
Copy link

@JeremyLandi JeremyLandi commented Apr 25, 2019

@sonjadeissenboeck A little late, and I'm sure you already checked this, but I don't see where you are defining 'worksheet'. You need to add something like this

var worksheet = XLSX.utils.json_to_sheet(arrayOfObjects);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.