Datatable export to excel amount error
Datatable export to excel amount error
$(document).ready(function () {
$.fn.dataTable.moment(lang == "en" ? 'DD/MM/YYYY' : 'DD.MM.YYYY');
categories_table = $('.datatable').DataTable({
order: [[1, 'desc']],
language: datatable_lang,
dom: 'Bfrtip',
buttons: [
{
extend: 'collection',
autoClose: 'true',
text: '<i class="download icon">',
tag: 'span',
buttons: ['csv', 'print', 'excel']
}
]
});
});
this way i call excel and others but data is wrong in excel. 90,00 in my table but 9,000 in excel. There is no problem in excel, I just need to add something in my code but I couldn't find it. My column is C. Sorry for my English
Answers
I assume you are using a decimal comma. There are two ways to resolve this.
a) you make your values not numeric by adding a % sign for example.
b) you are replacing the decimal commas with decimal points prior to passing them to Excel and format your columns to the right numeric format.
Excel doesn't understand decimal commas and periods as thousand separators. 90,00 is interpreted as a broken number because the comma can only be a thousand separator in America - which doesn't make sense if only two digits follow.
If you passed "1.900.000,76 EUR" Excel would not recognize this as a number but simply as text. Probably even if you drop the "EUR" from the string.
if your users don't need to do Excel calculations the easiest way to resolve the issue is solution a). Otherwise you would need to do something like this for example.
I identify Excel column letters that contain numbers with two decimal places and numbers with four decimal places. The latter are percentages. Those numbers can come in German or American format depending on the user language. The code strips off the thousand separators and replaces an eventual decimal comma with a period.
So "1.900.000,76 EUR" becomes 1900000.76 when being sent to Excel.
That is what Excel understands. Depending on the client version of the user's Excel (German or American). The number is rendered to the user as 1.900.000,76 or 1,900,000.76 - if you get the cell styling right! Not an easy task.
That is done with "customize" like in here. As you can see this isn't trivial. So better stick to solution a) ...
It didnt help.I try but datatable is get error.
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin