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

Free Support Forum - groupdocs.app

Excel File of Type Xlsx. Cannot convert. The file is corrupt or damaged

Hi Team,
I am getting the error “Cannot convert. The file is corrupt or damaged.” when I try to convert my excel file (Xlsx) into the images.

The same file works fine when I try to read the file from local and convert it into images.
Sample Code:
using (Converter converter = new Converter(GetFileStream))
var info = converter.GetDocumentInfo();
PdfConvertOptions options = new PdfConvertOptions();
converter.Convert(“converted.pdf”, options);
catch (Exception ex)
static Stream GetFileStream() => File.OpenRead(filepath);

Now, as per my business use case, I am reading the same file from SharePoint using SharePoint REST API and getting the file content in the form of “Stream”. Passing the Stream to Convert class. It fails with the error “Cannot convert. The file is corrupt or damaged.”

Sample Code:
var byteArray = response.Content.ReadAsByteArrayAsync().Result;
using (var ms = new MemoryStream(byteArray))
var streams = new Dictionary<object, MemoryStream>();
SpreadsheetLoadOptions loadOptions = new SpreadsheetLoadOptions();
loadOptions.HideComments = true;
loadOptions.ShowHiddenSheets = false;
loadOptions.OnePagePerSheet = true;
loadOptions.Format = SpreadsheetFileType.Xlsx;

using (var converter = new Converter(() => ms, () => loadOptions))
    var options = new ImageConvertOptions
        Format = ImageFileType.Png
    converter.Convert(page => new MemoryStream(), (page, convertedStream, fileAnme) =>
        var memoryStream = new MemoryStream();
        streams.Add(page, memoryStream);
    }, options);


Note: The same code (without SpreadsheetLoadOptions) works fine for pptx,docx files reading from SharePoint.

Please help me with the excel file issue.

This topic has been moved to the related forum: https://forum.groupdocs.com/t/excel-file-of-type-xlsx-cannot-convert-the-file-is-corrupt-or-damaged/12132