Excel 自定义数据格式

发布于 2024-09-26 12:50:13 字数 614 浏览 0 评论 0原文

我正在使用 NPOI 生成 XLS 电子表格。 NPOI 是一个 Excel 电子表格生成库/API,可在 codeplex 上使用,使您能够创建工作簿、格式、公式等等......我用它来创建具有多个工作表的工作簿,其中包含各种工作表的输出计算。

我为每个包含值的单元格使用了以下自定义数据格式,我已使用以下代码将其插入 NPOI:

var newFormat = MyNPOIWorkBook.CreateDataFormat();
var customFormat = newFormat.GetFormat("[=0]0;0.####");

然后将 customFormat 应用于创建单元格样式的方法中的单元格。

这工作得相当好 - 但当点/句点后的第四个小数位是 0 时,效果就不太好。在这种情况下,我不会得到 0。我的要求是实际显示 0!

因此,为了说明这一点。 0.33445566 在电子表格中显示为 0.3343(很好!) - 但 0.3340 显示为 0.334(不好) - 我想要 0.3340。我明白这有点微不足道,但我想精确地满足我的目标:)

任何人都可以提供帮助 - 通过建议解决方法,或以某种神奇的方式改变我的自定义格式?

谢谢 -SB

I'm using NPOI to generate XLS spreadsheets. NPOI is an Excel Spreadsheet generation library/API that is available on codeplex, enables you to create workbooks, formatting, formulae and so on and so forth....I use it to create workbooks with multiple sheets that contain the output of the various calculations.

I've used the following custom data format for each cell that contains a value, which I've plumbed into NPOI using code along the lines of:

var newFormat = MyNPOIWorkBook.CreateDataFormat();
var customFormat = newFormat.GetFormat("[=0]0;0.####");

the customFormat is then applied to a Cell within a method that creates the Cell Styles.

This works rather well - but not so well when the 4th decimal place after the point/period is a 0. When this is the case, I do not get the 0. My requirement is to have the 0 actually show!

So, to illustrate. 0.33445566 displays in the spreadsheet as 0.3343 (fine!) - but 0.3340 displays as 0.334 (not fine) - I want 0.3340. I appreciate that this is somewhat trivial, but I would like to satisfy my objective precisely :)

Can anybody help - either by suggesting a workaround, or altering my custom format in some magical fashion?

Thanks
-SB

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

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

发布评论

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

评论(1

要走就滚别墨迹 2024-10-03 12:50:13

[=0]0;0.###0 怎么样?

How about [=0]0;0.###0?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文