vba 从 excel 保存 csv 会丢失小数点精度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14462548/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 19:17:48  来源:igfitidea点击:

saving csv from excel loses decimal point precision

excelvbaexcel-vbaexcel-2010

提问by LostLin

If I create a simple .csv file containing something like this:

如果我创建一个包含如下内容的简单 .csv 文件:

01/22/2013,3.14159265358979323846264338

and proceed to open it up in excel, the cell will show a rounded number i.e. 3.141592654and the formula bar will show the whole value. However if I make some changes and save the csv file, or just save the original file as a different csv file, the file will only contain the rounded number 3.141592654, causing me to lose some decimal point precision.

并继续在excel中打开它,单元格将显示一个四舍五入的数字,即3.141592654公式栏将显示整个值。但是,如果我进行一些更改并保存 csv 文件,或者只是将原始文件另存为不同的 csv 文件,该文件将只包含四舍五入的数字3.141592654,导致我失去一些小数点精度。

I am writing these files out via a vba macro. I have tried :

我正在通过 vba 宏写出这些文件。我试过了 :

ActiveWindow.DisplayFormulas=True

before the save command, and it works except it changes my date into a numeric format and I have not figured out a way to apply this format to only a range of cells. Is there some simple way to keep my numeric precision?

在保存命令之前,它的工作原理只是将我的日期更改为数字格式,而且我还没有想出一种方法可以将这种格式仅应用于一系列单元格。有没有一些简单的方法可以保持我的数字精度?

采纳答案by Vinny Roe

If you know which cells are going to be affected, try something like

如果您知道哪些细胞会受到影响,请尝试类似

Range("MYNUMBERS").NumberFormat = "#0.000000000000000"

?

?