开发者

Changing Excel cell format in C#

How can I change the 开发者_高级运维format of a cell in Excel using the Microsoft Excel 12.0 Library in C#? More specifically, I want to change a given cell to text format.

I have read .net c# changing excel cell format, but the cell still says general (although it does display as text).


It depends on the format you're actually trying to implement. There's not a silver bullet for changing to any format you want. If it's formatting numbers that you need, you could use something like this. I ran into a lot of suggestions to create a macro, you can do some pretty specific tasks that you define yourself.


No need to do that just change the NumberFormat.

// Set all cells from A1 to B2 to be text
ws.get_Range("A1", "B2")).NumberFormat = "@";

different formats can be looked up here

http://office.microsoft.com/en-us/excel-help/number-format-codes-HP005198679.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜