Detecting file format using Aspose Cells

Hi,

I need to detect file format of the spreadsheets. Some times users are sending with .xls extention but while processing them getting below exception

Aspose.Cells.CellsException: This file's format is not supported or you don't specify a correct format.

That means those are renamed from some other type like .xlsm, .xlsb etc

In Aspose.Word we have below method to get FileFormatInfo

FileFormatUtil.DetectFileFormat(inputFileName)

Is there similar method in Aspose.Cells? How I can detect the file format of excels without looking at extension?

Thanks,

SubbaM

Hi,

We have a class CellsHelper.DetectFileFormat() in Aspose.Cells for .NET version, which can identify the file format. e.g


string path = “…”;

FileFormatType fmtType= CellsHelper.DetectFileFormat(path);

Debug.Write(fmtType.ToString());

Thank you.

ok there is a file Aspose.Cells.FileFormatType fileFormat = Aspose.Cells.CellsHelper.DetectFileFormat(stream);

but how to manage to have a Aspose.Cells.LoadFormat? becasue I would like to use:
Aspose.Cells.SaveFormat saveFormat = Aspose.Cells.FileFormatUtil.LoadFormatToSaveFormat(…)


in Aspose.Words, there is Aspose.Words.FileFormatInfo and Aspose.LoadFormat = FileFormatInfo.LoadFormat in that case I can use the method LoadFormatToSaveFormat


I found it:

Aspose.Cells.LoadFormat loadFormat = Aspose.Cells.CellsHelper.DetectLoadFormat(stream);
Aspose.Cells.SaveFormat saveFormat = Aspose.Cells.FileFormatUtil.LoadFormatToSaveFormat(loadFormat);


but I don’t really understand the differrence between FileFormatType / LoadFormat?

my goal is:

I have a memorystream , I need to detect if the stream would be managed by Aspose.Slides / Aspose.Word or Aspose.Cells for that I use : DetectFileFormat

I made some transformation on the memoryStream and to save it again I use the SaveFormat option.

Abnd to have the SaveFormat option I detect the loadFormat .

Is it the good way to process?

Hi,


Well, XLSX and XLSM are almost the same formats and you don’t really need to specify the LoadFormat (while loading) or SaveFormat (while saving) in case of XLSX, XLSM formats.

Thank you.