Convert CSV to Xlsx ConvertNumericData

Hi ,

Using Aspose.Cells for .NET Version 18.1
When converting CSV to XLSX Cell content is converted to numerical data,

ConvertNumericData = false - Not Working

Here’s the code i use

TxtLoadOptions opts = new TxtLoadOptions();

        opts.Separator = (',');
        opts.ConvertNumericData = false;
    
        opts.HasFormula = false;

   
                Aspose.Cells.Workbook doc = new Aspose.Cells.Workbook(item,opts);

                doc.Save(args[0] + "\\" + Path.GetFileName(item) + ".xlsx", Aspose.Cells.SaveFormat.Xlsx);

I’ve attached source file,

Thanks2.csv.zip (230 Bytes)

@Austin_Powers,

Thanks for the template CSV file and sample code.

I have tested your scenario/case using your latest version/fix Aspose.Cells for .NET v18.1.2 (please try it), it works fine.

Aspose.Cells for .NET (Latest Version)

I am using the following sample code with your CSV file:
e.g
Sample code:

   TxtLoadOptions opts = new TxtLoadOptions();

    opts.Separator = (',');
    opts.ConvertNumericData = false;

    opts.HasFormula = false;


    Aspose.Cells.Workbook doc = new Aspose.Cells.Workbook("e:\\test2\\2.csv", opts);

            doc.Save("e:\\test2\\out1.xlsx", Aspose.Cells.SaveFormat.Xlsx);

I have also attached the output XLSX file in which the numeric data is converted to text, see the screenshot for your reference:

file1.zip (6.4 KB)

Thanks you for your testing,
But still when i open the original file there’s no “zeros adding” on each numerical cell
Here’s the original CSV open in excel:

image.png (5.0 KB)

And after converting either with 18.1 or 18.1.2 :
image.png (4.6 KB)

@Austin_Powers,

Please note, when you set TxtLoadOptions.ConvertNumericData to false, it will not convert numbers to numeric values. When you set the Boolean property to true, it will set numbers (values) to numeric data type.

Please also note that it is MS Excel behavior that removes any unnecessary leading zeros or ending zeros when you load the file into it. That’s why you see those redundant leading/ending zeros are not there with the values in the cells. Please open your CSV file into notepad and you will see those leading and ending zeros are attached with the numeric values.

If you do not want those leading/ending zeros attached to the numbers, please either do not use the Boolean attribute or set it to “true”.

Let us know if you still have any confusion or issue.