CSV 文件:Excel 隐藏零

发布于 2024-10-29 18:32:52 字数 200 浏览 2 评论 0原文

如果我将 csv 文件加载到 Excel 中,值 123.320000 将变为 123.32。

我需要按原样查看所有内容。有什么方法可以阻止Excel隐藏尾随零吗?

阅读其他帖子,我发现这样做可以工作“=”“123.3200000”,但这意味着每次我想查看它时都在文件上运行正则表达式..因为它采用 xxxx|###|xxx 格式并且我无法控制生成部分。

if I load a csv file into excel, value 123.320000 will become 123.32.

i need to view all contents as they are. any way to stop excel from hiding trailing zeros?

reading other posts, i found that doing something like this could work "=""123.3200000" but that would mean running regex on the file every time i want to view it.. since it comes in xxxx|###|xxx format and i have no control over the generation part.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风柔一江水 2024-11-05 18:32:52

您究竟是如何加载 CSV 文件的?

如果将其导入为“文本”格式,则 Excel 将保留所有格式,包括前导/尾随零。

在 Excel 2010 中,您从“数据”选项卡导入并选择“从文本”,找到 CSV 文件,然后在出现提示时选择将数据格式设置为“文本”

How exactly are you loading the CSV file?

If you import it as "Text" format then Excel will retain all formatting, including leading/trailing zeros.

In Excel 2010 you import from the "Data" tab and choose "From Text", find your CSV file then when prompted choose to format the data as "Text"

还给你自由 2024-11-05 18:32:52

我假设一旦导入的值位于工作表中,您希望将它们视为数字而不是文本,即您希望能够求和、相乘等。将值加载为文本将阻止您执行此操作-- 直到您将值转换回数字,在这种情况下您将丢失尾随零,这使您回到最初的难题。

请记住, 123.32 和 123.3200000 之间没有区别,您想要的只是更改显示格式,以便明确显示值的完整精度。您可以在 VBA 中执行此操作,如下所示:

strMyValue = "123.3200000"

strFormat = "#."
' Append a 0 to the format string for each figure after the decimal point.
For i = 1 To Len(strMyValue) - InStr(strMyValue, ".")
    strFormat = strFormat & "0"
Next i

With Range("A1")
    .Value = CDbl(strMyValue)
    .NumberFormat = strFormat
    'Value now shown with same precision as in strMyValue.
End With

I'm assuming that once the imported values are in the sheet, you want to treat them as numbers and not as text, i.e. you want to be able to sum, multiply, etc. Loading the values as text will prevent you from doing this -- until you convert the values back to numbers, in which case you will lose the trailing zeros, which brings you back to your initial conundrum.

Keeping in mind that there is no difference between the values 123.32 and 123.3200000, what you want is just to change the display format such that the full precision of your value is shown explicitly. You could do this in VBA like so:

strMyValue = "123.3200000"

strFormat = "#."
' Append a 0 to the format string for each figure after the decimal point.
For i = 1 To Len(strMyValue) - InStr(strMyValue, ".")
    strFormat = strFormat & "0"
Next i

With Range("A1")
    .Value = CDbl(strMyValue)
    .NumberFormat = strFormat
    'Value now shown with same precision as in strMyValue.
End With
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文