christinaemmm
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??
There must be a magic solution??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
ASKER
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.
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.
gowflow