1

How can someone format the cell which contains a number to be text? I have my code which is:

xlsWorkSheet.Cells(x+2,x+2).style.numberformat.format="@"
xlsWorkSheet.Cells(x+2,x+2).Value = xmlrequstmsg.toString

but for some reason even the excel is produced with format Custom and as soon as I double click the cell only then it transforms to the appropriate format.

How can I fix this?

1 Answer 1

4

Its because you are calling ToString. The Value property of the cell object from Epplus is Object type so it will allow you to store any type you would like. If you call ToString it will store what xmlrequestmsg is as its string representation. If it is, say, an int it will save it as a string that looks like an int which excel will flag with the green triangle in the corner of the cell (assuming the user has not turned off the warning messages).

So store or cast as a proper numeric format and it should solve the problem. See if this thread helps: Using EPPlus how can I generate a spreadsheet where numbers are numbers not text.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.