Export Datatable as string

Hello,

I load data from a CSV file and then export a datatable as a string. I noticed a “conversion error” where one of my csv column’s data contains 001 (as text), but aspose exports it as a numeric 1.

Has anyone else discovered a conversion error such as this and found a workaround?


Hi,

Thank you for considering Aspose.

We have found the issue regarding CSV file export data after an initial test. We will fix it and get back to you soon.

Thank you & Best Regards,

Thanks for your prompt reply. I appreciate you working through this issue. We’ll be patiently awaiting your response.

:slight_smile:

Hi,

Thank you for considering Aspose.

After exploring your issue in detail, we came to know that this is process is same as performed by MS Excel. If you open a CSV file in MS Excel it will also change your 0001 value to 1.

But you can user Workbook.ConvertNumericData = false to not convert your 0001 to 1 in CSV export. Please see the following Sample Code which will help you get your desired result.
Sample Code:-

Workbook workbook = new Workbook();

workbook.ConvertNumericData = false;

workbook.Open(@"F:\Excels\test.csv", FileFormatType.CSV);

DataTable dt = workbook.Worksheets[0].Cells.ExportDataTable(0, 0, 1, 4);

workbook.Save(@"F:\Excels\test1.xls", FileFormatType.Default);

Thank you & Best Regards,

Thanks for the tip. It worked perfectly!