In Aspose (Words and Cells), the methods for FileFormatUtil.detectFileType can take an InputStream. The problem is when I pass in a ByteArrayInputStream representing the bytes of a Word or Excel file, it returns 255 (Unknown Format). Can it detect such files with a ByteArrayInputStream? Is there another solution?
For Aspose.Cells, it supports to detect file format type from ByteArrayInputStream for MS Excel or other file formats. I tested your scenario/case using the following sample code with a sample XLSX file, it works fine and as expected.
e.g.
Sample code:
File file = new File("f:\\files\\Book1.xlsx");
byte[] array = Files.readAllBytes(file.toPath());
ByteArrayInputStream stream = new ByteArrayInputStream(array);
// Detect file format from streams
FileFormatInfo info = FileFormatUtil.detectFileFormat(stream);
// Gets the detected load format
System.out.println("The spreadsheet format is: " + FileFormatUtil.loadFormatToExtension(info.getLoadFormat()));
Could you please share your sample Excel file (please zip the file prior attaching) to reproduce the issue. We will check your issue soon.
Moreover, regarding Aspose.Words, our fellow colleague from Aspose.Words will get back to you soon.
@jmmorgan Aspose.Words also supports detecting document format passed in a ByteArrayInputStream. But you should note that Aspose.Words is limited to detecting document formats supported by Aspose.Words for load. Please see LoadFormat enum. If you are sure the passed ByteArrayInputStream contains a document which should be detected by Aspose.Words and it is detected as Unknown Format, please attach the problematic document here for testing. We will check the and provide you more information.