jQuery 导出到 excel 的 DataTable 正在导出错误的列值
jQuery DataTable export to excel is exporting wrong column values
我正在使用 jQuery 的数据表 1.10.19 和按钮 1.6.1。导出到 excel sheet 整数列时,值导出错误,不存在
一列Reference No是后台每行生成的唯一编号。以下是示例
实际列包含值,该值存在于 (HTML) table & 对于同一行,当导出时,另一个值在该列中。
我查了下,样式也不一样。即在一行中,值递增(如在第一行中)1,而在第二行中值递减 1。在最后一行中值递减 5。
注意:相同 table 具有相同的值,当导出为 PDF 时,数据会正确导出。
您应该意识到所有导出的值都以 0
结尾。其实都是四舍五入到15个非零位。
如果您将 Actual
列中的任何值直接输入到 Excel,您会看到它的最后一位被替换为 0
。
关于此主题的好文章之一 articles 提供:
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
看完Sergey Nudnov先生的回答后,我想到了以下解决方案
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;
}
}
}
]
注意:column === 2 是需要从整数转换为字符串的列的索引。只是 prefix/concatenate 带有 '\u200C'
的单元格值(长数字)
我正在使用 jQuery 的数据表 1.10.19 和按钮 1.6.1。导出到 excel sheet 整数列时,值导出错误,不存在
一列Reference No是后台每行生成的唯一编号。以下是示例
实际列包含值,该值存在于 (HTML) table & 对于同一行,当导出时,另一个值在该列中。
我查了下,样式也不一样。即在一行中,值递增(如在第一行中)1,而在第二行中值递减 1。在最后一行中值递减 5。
注意:相同 table 具有相同的值,当导出为 PDF 时,数据会正确导出。
您应该意识到所有导出的值都以 0
结尾。其实都是四舍五入到15个非零位。
如果您将 Actual
列中的任何值直接输入到 Excel,您会看到它的最后一位被替换为 0
。
关于此主题的好文章之一 articles 提供:
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
看完Sergey Nudnov先生的回答后,我想到了以下解决方案
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;
}
}
}
]
注意:column === 2 是需要从整数转换为字符串的列的索引。只是 prefix/concatenate 带有 '\u200C'
的单元格值(长数字)