Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

excel cell formatting

Tags:

c#

excel

How can I change the cell format to be text in Excel programatically?

like image 986
user158182 Avatar asked Dec 20 '25 00:12

user158182


2 Answers

You can use:

Range("A1").NumberFormat = "@"

for text

Range("A1").NumberFormat = "dd/mm/yyyy hh:mm:ss" 

for a date.

Range("A1").NumberFormat = "#,###"

for money, etc.

like image 72
butterchicken Avatar answered Dec 21 '25 12:12

butterchicken


The way that I answer this and other excel queries it to record a macro in Excel, perform the action that I want to see how to do, and then look at the macro to see what it recorded.

Doing that, this questions answer is:

Selection.NumberFormat = "@"

like image 37
Joon Avatar answered Dec 21 '25 14:12

Joon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!