简体   繁体   English

C# 互操作 Excel:可以像 Value2 一样设置 NumberFormat 吗?

[英]C# interop Excel: is possible to set NumberFormat like Value2?

I am trying to set NumberFormat in Excel with C# for quite big Range.我正在尝试使用 C# 在 Excel 中设置 NumberFormat 以获得相当大的范围。 Its big table and make it cell by cell consume too much time.它的大表并逐个单元格地制作它会消耗太多时间。

I tried it similar like setting Value2 for range:我尝试了类似设置 Value2 的范围:

 rng = ws.get_Range("H" + 2, "S" + 2);
 rng.NumberFormat = numberFormat;

Where numberFormat is array of objects with formatting strings (like "0.00", "0.0000", ...) Looks like this will not work because it looks to me, that NumberFormat is just one property for whole Range.其中 numberFormat 是具有格式化字符串的对象数组(如“0.00”、“0.0000”……)看起来这不起作用,因为在我看来,NumberFormat 只是整个 Range 的一个属性。

Do you have any idea how to make it fast, not cell by cell approach?你知道如何让它快速,而不是逐个细胞的方法吗? Thank you!谢谢!

I forgot to know you guys I resolved this by solution that was already placed here (shame on me)我忘了认识你们我通过已经放置在这里的解决方案解决了这个问题(我感到羞耻)

How to specify format for individual cells with Excel.Range.set_Value()如何使用 Excel.Range.set_Value() 为单个单元格指定格式

I just slightly modified solution of Drew Shafer (thanx man).我只是稍微修改了 Drew Shafer (thanx man) 的解决方案。 based on my research it is best possible solution for excel via interop.根据我的研究,excel 通过互操作是最好的解决方案。

Besides of the limitation of Excel, His solution is really elegant.除了 Excel 的限制之外,他的解决方案非常优雅。

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

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