Link to home
Start Free TrialLog in
Avatar of christinaemmm
christinaemmmFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Need to programmatically set Excel cell format to text

I am writing data into Excel from vb.net and need to set some cell formats to text, to ensure that leading zeroes are not lost. So far, I have tried adding a leading apostrophe to the string I write into the cell, setting the cell's numberformat to "Text" and setting it to "000000". None of these work.

There must be a magic solution??
ASKER CERTIFIED SOLUTION
Avatar of Carlos Ramirez
Carlos Ramirez
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
what do you mean by You tried an appostroph and 00000 formating and it didn't work what number you have at first and what did you get can you post some examples as what you indicate should work with a slight change
gowflow
Avatar of christinaemmm

ASKER

I suddenly wondered whether it was because I save the ss as a csv file; when I tested, I found that the control settings for some of the values were not being passed correctly. So mea culpa, having fixed my code, it does work, including saving the ss as a csv file.

slycoder, I didn't know about using @ - is there any practical difference between the options of this or inserting an apostrophe? I have now tried both and they both seem fine, but it would be good to know if there are any little 'gotcha's with either solution.
Thanks, slycoder!
There are no 'gotchas' that I know of with using either method.

the apostrophe is a "literal" mark and has been used since the days of VisiCalc

the @ formatting is what I got when I recorded a macro and changed the formatting of the cell to Text.