简体   繁体   English

AngularJS数字过滤器无法与UI网格正常工作

[英]Angularjs number filter not working properly with ui grid

I am using angularjs number filter in angular-ui-grid . 我在angular-ui-grid使用angularjs数字过滤器。 In a grid, the filter works fine. 在网格中,过滤器工作正常。 But when I export the grid to csv and open into excel, it does not work properly. 但是,当我将网格导出到csv并打开到excel中时,它无法正常工作。

I've added the filter in exporterFieldCallback as well. 我也已在exporterFieldCallback添加了过滤器。

In a grid: cellFilter: 'number:6', type: 'number' and in exporterFieldCallback : 在网格: cellFilter: 'number:6', type: 'number'并在exporterFieldCallback

if(col.name == 'columnName'){                   
                    return $filter('number')(input,6);
                } 

The numbers are displayed with 6 decimal places on a grid. 这些数字在网格上以小数点后6位显示。 But while I export it to csv and open into excel, the zeros are truncated. 但是,当我将其导出到csv并打开到excel中时,零将被截断。

Please find this plunker of angularjs number filter where numbers are displayed with specified fractionSize which is also works fine in grid. 请找到这个棱角分明的angularjs数字过滤器 ,其中显示的数字具有指定的fractionSize,在网格中也可以正常工作。 But does not work same while export the grid. 但是在输出网格时不一样。

If value in a grid is 3.000000 then in excel it shows 3 only. 如果网格中的值是3.000000则在excel中它仅显示3 If value in a grid is 1.415400 then in excel it shows 1.4154 only. 如果网格中的值为1.415400则在excel中仅显示1.4154

Why zeros are truncated while angular-ui-grid is exported to csv and open it in excel ? 为什么将angular-ui-grid导出到csv并在excel中将其打开时零被截断? How do I display values in excel as same as it appears on a grid ? 如何在Excel中显示与网格中相同的值?

This is probably an Excel issue, rather than an AngularJS one. 这可能是一个Excel问题,而不是AngularJS问题。

When you open a CSV file in Excel, it looks for numbers and normalises them, removing leading and trailing zeros. 当您在Excel中打开CSV文件时,它将查找数字并对其进行规范化,从而删除前导零和尾随零。 You can (hopefully) see that your CSV file is correct by opening it in a text editor instead and checking that it has leading and trailing zeros. 您可以(希望)通过在文本编辑器中打开CSV文件并检查其开头和结尾的零来查看CSV文件是否正确。

Depending on how often you'll need to be importing data into Excel, there are a couple of different options, but as you just want values to 6 decimal places, the simplest is probably to import the data and then reformat it within Excel using the Increase Decimal option: 根据需要将数据导入Excel的频率,有几个不同的选项,但是由于您只想将值保留到小数点后6位,最简单的方法可能是导入数据,然后使用增加十进制选项: 在Excel中增加十进制按钮

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM