1

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

Community
  • 1
  • 1
Andrew
  • 2,519
  • 6
  • 29
  • 46

2 Answers2

1

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

Lorin Davis
  • 229
  • 2
  • 4
1

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.

Community
  • 1
  • 1
Precious Roy
  • 1,086
  • 1
  • 9
  • 19