简体   繁体   中英

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

I am trying to set NumberFormat in Excel with C# for quite big Range. Its big table and make it cell by cell consume too much time.

I tried it similar like setting Value2 for range:

 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.

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()

I just slightly modified solution of Drew Shafer (thanx man). based on my research it is best possible solution for excel via interop.

Besides of the limitation of Excel, His solution is really elegant.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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