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.

Fri Sep 18, 2015 3:07 pm

Hi Team,

While writing a string to excel, it is getting converted to number. for example, string value "2015090433791826" is getting converted to "2.01509E+15" in the generated excel.

Attached is the generated excel

Can you please suggest a way I can write a string which looks like a NUMBER as a string only.

Really Appreciate your response on it.
Attachments
Sample.zip
Sample showing the error
(6.53 KiB) Downloaded 608 times

gargmanoj@gmail.com
 
Posts: 7
Joined: Tue May 15, 2012 2:52 pm

Mon Sep 21, 2015 2:20 am

Hello,

Thanks for your inquiry.
Please try the below code:
Code: Select all
 workbook.Worksheets[0].Range["A1"].Text = "2015090433791830";


Best wishes,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2774
Joined: Wed Jun 27, 2012 8:50 am

Mon Sep 21, 2015 7:44 am

Hi Amy,

I am loading data into the worksheet using a datatable using method sheet.InsertDataTable. How can I use the below line with this method.

I would really appreciate your help on this.

gargmanoj@gmail.com
 
Posts: 7
Joined: Tue May 15, 2012 2:52 pm

Mon Sep 21, 2015 8:05 am

Hello,

You only need to set its NumberFormat after inserting data.
Code: Select all
workbook.Worksheets[0].Range["A2"].NumberFormat = "0";


Best wishes,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2774
Joined: Wed Jun 27, 2012 8:50 am

Mon Sep 21, 2015 8:10 am

Hi Amy,

Thanks for your response. But adding the number format to "0" causes the rounding in the string for example

"2015090433791826" is getting converted to "2015090433791830"

gargmanoj@gmail.com
 
Posts: 7
Joined: Tue May 15, 2012 2:52 pm

Mon Sep 21, 2015 8:53 am

Hello,

Please use this method workbook.Worksheets[0].InsertDataTable(dt, true, 1, 1,true); to insert dataTable.

Best wishes,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2774
Joined: Wed Jun 27, 2012 8:50 am

Mon Sep 21, 2015 2:11 pm

Hi Amy,

Thanks a lot for your prompt responses.
This has fixed the earlier issue however the excel is showing a warning for all such cells that "number is stored as text". Is there a property by which I can suppress these warnings?

Thanks a lot once again.

Manoj

gargmanoj@gmail.com
 
Posts: 7
Joined: Tue May 15, 2012 2:52 pm

Tue Sep 22, 2015 1:24 am

Hello Manoj,

Please set cellRange's IgnoreErrorOptions property, like this code:
Code: Select all
workbook.Worksheets[0].Range["A2"].IgnoreErrorOptions = IgnoreErrorType.NumberAsText;


Best wishes,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2774
Joined: Wed Jun 27, 2012 8:50 am

Wed Sep 23, 2015 6:39 am

Hello Manoj,

Has your problem been resolved?
Thanks for your feedback.

Best wishes,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2774
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.XLS