Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Tue Jun 24, 2008 12:56 pm

I got the problem to show a 13 digit number correctly in a sheet.

Excel automatically format it into the sientific notation (1,0+E12), but i need the number to be shown complete.

What to do to format the sheet that way, that numbers are not changed to the scientific notation.?

BTW:

How can i generally set the format for a Cell or CellRange to string, even if i enter numbers?

Because sometimes you can have a numberstring e.g. for a zip code starting with a '0'. Without the correct format Excel automatically change this to a number and kills the '0'.

pb
 
Posts: 14
Joined: Fri Jun 20, 2008 11:05 am

Wed Jun 25, 2008 2:12 pm

Until there is a different approach i'm adding a single ' before the number, this forces Excel to handle a number as string.

Code: Select all
wb.Worksheets[sheet].Columns[x].Rows[y].Value2 = "'" + wb.Worksheets[sheet].Columns[x].Rows[y].Value2.ToString();


Not very clean, but for the moment it works.

pb
 
Posts: 14
Joined: Fri Jun 20, 2008 11:05 am

Fri Jun 27, 2008 4:24 pm

Hello,

You can try to using following source code,

Code: Select all
  wb.Worksheets[sheet].Columns[x].Rows[y].NumberFormat = "@";
User avatar

Flash
 
Posts: 56
Joined: Thu Jun 29, 2006 2:34 pm

Mon Jun 30, 2008 7:28 am

I tried, but it doesn't work with NumberFormat = "@", it changes to the 1E+12 format. Maybe a problem from Excel.

pb
 
Posts: 14
Joined: Fri Jun 20, 2008 11:05 am

Wed Jul 02, 2008 1:53 pm

I'm now using NumberFormat = '0'. That way Excel shows the number as it is and no longer shortens it. (At least it do this on my system).

pb
 
Posts: 14
Joined: Fri Jun 20, 2008 11:05 am

Return to Spire.XLS