Free Support Forum - aspose.com

"Text identifier" option when extracting CSV file

Hi everyone !

I need to import a CSV file. So to extract data, I’m using Aspose and I define my separator as “,” :

image.png (5.7 KB)

(“LoadWorkBook” methods just instanciates and returns a new workbook with the file at “alertPath” using options “loadOptions”)

My problem is that my CSV file contains sometimes in some cells the “,” character, and if so, the whole cell value is between double quotes ("). When extracting data with Aspose as I do in code above, the double quotes don’t “protect” the text, and I’ve go one new column per “,”…

In excel, when you go to Data -> Convert -> Delimited you’ve got an option called “Text identifier”, and that’s exactly what I need. Can I do that sort of thing in Aspose ?

I hope i’m clear ! Thanks
Julien

@Kraaneur,

Thanks for your query.

You may please send us the source CSV file, the output file generated by Aspose.Cells and another expected output file generated by Excel only. It will help us to observe the problem, compare the program output with the expected output file and provide our feedback.

Of course !

Source :
Id1,titre1,description1,program1
Id2,titre2,"description2,with a comma",program2
Id3,"titre3,with a coma",description3,program3
Id4,titre4,description4,"program4, program5, program6"

Expected result (simulation in Excel) :
image.png (2.7 KB)

Actual result with Aspose (simulation in Excel too) :
image.png (2.6 KB)

Is it enough ? :slight_smile:

@Kraaneur,

I have tried following sample code using latest version Aspose.Cells for .NET 18.10 but could not observe any issue as the output file resembles the expected output shared by you. Could you please test the scenario again and provide your feedback?

Workbook alertWorkbook = null;
try
{
    Aspose.Cells.LoadFormat loadFormat = Aspose.Cells.LoadFormat.CSV;
    Aspose.Cells.TxtLoadOptions loadOptions = new Aspose.Cells.TxtLoadOptions(loadFormat)
    {
        Separator = ',',
    };

    alertWorkbook = new Workbook(path + "sample.csv", loadOptions);
    alertWorkbook.Save(path + "Output.xlsx");
}
catch(Exception ex)
{
                
}

sample.zip (219 Bytes)
Output.zip (5.7 KB)

I updated my version of Aspose.Cells for .NET to 18.10, so we’ve the same last version.
I tried your code with your sample, but stil have the same “bad” result…
image.png (2.3 KB)

How is it possible…?

@Kraaneur,

Please download the complete project from the following link and provide your feedback after testing.

@ahsaniqbalsidiqui

Thank you very much for the time you took to answer me, all is working well with that code in your project as in mine.

Actually the problem isn’t here : the “sample.csv” file that I want to load comes from a SFTP server. Once I download it, all the double quotes has been removed… So it can’t work.

I’ll try to figure out why this is happening, but at the end it’s not an aspose problem at all.

Thanks again !

@Kraaneur,

Thank you for providing the feedback and feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.