Convertstringtonumericvalue issue

Hello,

I have been exporting values to excel and bumped into an issue where all the values exported were text values and I could not perform Sum to them or anything like that.

Here is how i was exporting the values:

cells.ImportDataTable(dt, True, 0, 0, endRow, dt.Columns.Count)

I found that you can use the convertStringtonumericvalue overload so I did as such:

cells.ImportDataTable(dt, True, 0, 0, endRow, dt.Columns.Count, False, “mm/dd/yyyy”, True)

which works great except it turns dates and anything that can be converted to a number into a number. I was able to reformat the dates and what not after the fact but the problem I am currently having is that in my export I often times have columns that are purchase order #s which are long numeric values (some only numeric and some alpha-numeric).

The convertstringtonumericvalue goes through these columns and turns the values it can into numeric values and in some cases I do not want this because for instance :

Purchase order # : 300000000218
when converted by this function turns into : 3E+11

Once it is a number I can set it back to text in the code but the text is now set to “3E+11” not the original “300000000218”.

So my question is this:

Is there any way to apply the numeric values to specific columns or better yet is there a way to convert the 3E+11 numeric value back to text with the “300000000218” value?

Thanks in advance!

Hi,

Thank you for considering Aspose.

If you want to change back the value from 3E+11 numeric value to “300000000218" in your Purchase Order Number Columns, You can Navigate through the column cells and change the values by using Cells.PutValue(string value,bool isConverted) method as follow:

for(int i=0; i<totalRows.length;i++)

{

Cells[i,1].PutValue(sheet.Cells[i,1].Value.ToString(),false);

}

As Cells.Value contains the original value of the cell (without numeric formatting) and isConverted = false will not apply any numeric format on the value, so your original text will be reverted back.

Thank you & Best Regards,