We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Cell format change to text

Thread ID:

Created:

Updated:

Platform:

Replies:

150275 Dec 30,2019 02:51 PM UTC Jan 23,2020 05:03 AM UTC Windows Phone 3
loading
Tags: XlsIO
sateesh kumar
Asked On December 30, 2019 03:15 PM UTC


Hi team,

Am successfully reading text file into data table. 
with using data table, i created excel file.

but my Text file and Data table is having values like

Column1
-------------------------
01
10
(12)

but my output excel getting as 

Column1
-------------------------
1
10
-12

here is my code

 IWorksheet worksheet = workbook.Worksheets.Create(1);
                        string filter = "Table='" + sheetName.Value + "'";
                        DataView dtView = new DataView(dt, filter, "Code", DataViewRowState.CurrentRows);
                        worksheet.ImportDataTable(dtView.ToTable(), true, 1, 1);
                        worksheet.UsedRange.AutofitColumns();

Am using Microsoft 365 ProPlus.
After excel creation, i observed , my cell number format is General. due to this (13)  converting as -13. but it should not do like.
for value 01 cases, can use worksheet.UsedRange.NumberFormat = "00#"; but in the same column it self my values in (13) also getting.

How can i achieve cell number format as Text.

Thanks for advance
J. Sateesh Kumar

Abirami Varadharajan [Syncfusion]
Replied On December 31, 2019 10:53 AM UTC

Hi Sai, 

Greetings from Syncfusion. 

We request you to make use of the overload of ImportDataTable by setting preserveTypes parameter to TRUE to preserve the values as text. Please refer to below code to achieve the same. 

Code Example: 
worksheet.ImportDataTable(dtView.ToTable(), true, 1, 1, true); 


Kindly try and let us know if this helps. 

Regards, 
Abirami 


sateesh kumar
Replied On January 22, 2020 12:12 PM UTC

Hi Abirami,

After using below code am getting expected result.
worksheet.ImportDataTable(dtView.ToTable(), true, 1, 1,-1,-1,true);



Konduru Keerthi Konduru Ravichandra Raju [Syncfusion]
Replied On January 23, 2020 05:03 AM UTC

Hi Sai, 

Thanks for the update. 

We are glad that the issue is resolved at your end. Kindly let us know if your need any further assistance. 

Regards, 
Keerthi. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon