0

I'm using jQuery's DataTable 1.10.19 & Buttons 1.6.1. When exporting to the excel sheet integer column values are exported wrong, which doesn't exist

One column Reference No is unique number generated per row by back-end. Following is sample

enter image description here

Actual column contains value, which exist in (HTML) table & for same row, when exported, an other value is in the column.

I checked, pattern is also not same. i.e. in one row, value is incremented (as in 1st row) by 1 while in second row value is decremented by 1. In last row value is decremented by 5.

NOTE: Same table with same values, when exported to PDF, data is exported correctly.

1

2 Answers 2

1

You should realize that all exported values end with 0. Actually, all of them are rounded to 15 non-zero digits.

If you would type in any of values from the Actual column directly to Excel, you would see, that its last digit was replaced with 0.

One of good articles on this topic provides:

You will notice this standard (IEEE 754) in many ways in Excel, but the main is, that if you write an integer with more than 15 digits (which is quite feasible), excel will transform all integers starting with the 16th to zero.

So when you put 1234567890123456789 in a cell, you get 1234567890123450000. The same goes for 1234567890.123456789 that would give 1234567890.123450000! This is by itself quite a drawback, but it doesn’t end there, this limitation impacts all parts of Excel, including calculations.

Is there a way around this

The short answer is NO. The long answer is, you can store longer number as text (so begin writing in Excel with an apostrophe), and you will see more than 15 integers, but if you will want to convert them back to numbers and do calculations with them, you will again only work with 15 integers!

The only way to make Excel more precise, is by using an Add-In. There are many out there, here is an example: xlPrecision

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @Sergey I didn't know this before about 15 digits limit about excel. I solved the issue by converting cell value to text format instead of integer
0

After reading answer of Mr. Sergey Nudnov, I came up with following solution

    buttons: [
               {
                   "extend": 'excel', "text": ' Excel', "className": 'btn btn-flat btn-success fa fa-file-excel-o'
                  , exportOptions: {
                      columns: [':visible']
                        , format: {
                            body: function (data, row, column, node) {
                                var cellData;
                                cellData = data.indexOf("<") < 0 ? data : $(data).text();   // Some cells contains html elements. need to strip off
                                return column === 2 ? '\u200C' + cellData : cellData;
                            }
                        }
                  }
            ]

NOTE: column === 2 is the index of the column which need to be converted from integer to string. just prefix/concatenate cell value (long number) with '\u200C'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.