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

Free Support Forum - aspose.com

When converting csv to pdf no validation that the csv is valid

Hi.

i have a non valid csv file which i am trying to convert to pdf. i’m expecting that an exception will be thrown instead of success in converting to pdf file

i’m using aspose.cells 7.7.2.0 for .net3.5

here is an exemple code
Aspose.Cells.LoadOptions loadOptions = new Aspose.Cells.LoadOptions(Aspose.Cells.LoadFormat.CSV);
Aspose.Cells.Workbook ExcelConvertor = new Aspose.Cells.Workbook(“c:\csv1.csv”, loadOptions);
ExcelConvertor.Save(“c:\csv.pdf”, Aspose.Cells.SaveFormat.Pdf);

i’m attaching the source file and the output pdf.

thanks

Hi,


Well, you may first try to detect the file format if it is valid, Aspose.Cells would throw an exception accordingly, so you may handle it. Please see the sample code for your reference:
e.g
Sample code:

//Detect File format
FileFormatInfo info = FileFormatUtil.DetectFileFormat(“e:\test2\csv1.csv”); //Error thrown
//Gets the detected load format
Console.WriteLine("The spreadsheet format is: " + FileFormatUtil.LoadFormatToExtension(info.LoadFormat));


Thank you.

thanks for the sample code. just one little issue. if the file is empty (size =0), the return type is “unknown”

Hi,


Could you provide a sample file ( with zero size) here, we will check it soon.

Thank you.

Hi,

Thanks for your posting and using Aspose.Cells.

Aspose.Cells detects the file format by reading the fields inside the format of the file. CSV or other text formats do not have any such fields that could be used to distinguish the file formats. Therefore, Aspose.Cells detects such file formats as unknown format.

ok. thank you for the answer