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. Image for the cookie policy date

Cell format change to text


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

3 Replies

AV Abirami Varadharajan Syncfusion Team 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 



SK sateesh kumar 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);




KK Konduru Keerthi Konduru Ravichandra Raju Syncfusion Team 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. 


Loader.
Up arrow icon