We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Reading simple CSV

It appears that Aspose.Cells cannot read CSV files, from at least version 17.5 until 19.1 (released today).

The following code throws: Aspose.Cells.CellsException: This file’s format is not supported or you don’t specify a correct format.

try
{
	var data = System.Text.Encoding.ASCII.GetBytes("Header 1,Header 2\ndata 1,data 2\n");
	using (var ms = new System.IO.MemoryStream(data))
	using (var wb = new Aspose.Cells.Workbook(ms)) { }
}
catch (Exception ex)
{
	Console.WriteLine(ex.ToString());
}

@jay_bp,

Thanks for your query.

Please mention the load format of the memory stream while loading the CSV through memory stream. Give a try to the following sample code and provide your feedback.

try
{
    var data = Encoding.ASCII.GetBytes("Header 1,Header 2\ndata 1,data 2\n");
    LoadFormat loadFormat = LoadFormat.CSV;
    TxtLoadOptions loadOptions = new TxtLoadOptions(loadFormat)
    {
        Separator = ',',
    };
    using (var ms = new MemoryStream(data))
    using (var wb = new Workbook(ms, loadOptions))
    {

    }
}
catch (Exception ex)
{
    Console.WriteLine(ex.ToString());
}

That does work, thanks.

But, this raises the question about why the LoadFormat Enumeration has an Auto value. Why have a Workbook constructor that doesn’t take the LoadOptions if it can’t automatically detect the format of the data?

@jay_bp,

In your case the underlying stream is simply a text stream which does not follow any specific standard file format type(the file format is simply detected as Unknown" type) so you have to load it with the concerned loading options. All the standard file types contain specific headers which are used for identification by Excel and Aspose.Cells and sometimes file extensions are used for identification. The LoadFormat.Auto uses these headers and extensions to identify the file format. Same is the criteria used by Workbook constructor without the LoadFormat.

For verification, if you save your memory stream to some file and put some random extension(other than CSV) to it, Excel will also raise error while opening it.