Click here to Skip to main content
16,020,568 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have an excel which contain numeric and some numbers are displayed with one decimal where there actual value contain 2 decimals for ex it display 0.3 and when I select that cell its value is 0.25

My problem is I'm saving that excel file as xlUnicodeText:
xlSheet.SaveAs(FileName, Excel.XlFileFormat.xlUnicodeText)  

and the data in my text file are displaying it as 0.3.

How I can make it to take and save it in my text file as its true value 0.25 and not as it is displayed?
Posted
Comments
[no name] 9-Jul-14 7:57am    
Try changing the format in your Excel sheet.
TheWebDeveloper 9-Jul-14 8:05am    
The user don't want to do that they want it to be programmed
CHill60 9-Jul-14 8:15am    
Then *programmatically* change the format of the sheet before you save it to text.
TheWebDeveloper 10-Jul-14 1:54am    
Yes that is my question, how to do that?
Maciej Los 9-Jul-14 9:25am    
Are you sure there is a 0.25 instead of 0.3?

To programmatically remove the formatting that is causing the problem try something like this
C#
Excel.Range oRng = MySheet.UsedRange;   // or whatever range you need
oRng.NumberFormat = "General";
This also works
C#
oRng.NumberFormat = null;
 
Share this answer
 
 
Share this answer
 
Comments
CHill60 9-Jul-14 8:14am    
What's that got to with the format being saved to the text file?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900