1

I have a Base64 string of xls file. When I try to open base64 stream it throws the following exception

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

public Stream ConvertFileToStream(string fileBase64)
{
        var fileAsBytes = Convert.FromBase64String(fileBase64);
        Stream stream = new MemoryStream(fileAsBytes);
        return stream;
  }


public void Open(Stream fileSource)
{
        FileFormatUtil.DetectFileFormat(fileSource);
        _workbook = new Workbook(fileSource);
}
zapoo
  • 1,548
  • 3
  • 17
  • 32

1 Answers1

1

I changed the related part of the code and it worked. Now I'm able to work with base64 excel strings.

First, I used BinaryWriter to convert file to stream.

public Stream ConvertFileToStream(string fileBase64, NameValueCollection formData, string fileName)
{
        var fileAsBytes = Convert.FromBase64String(fileBase64);
        var  stream = new MemoryStream();
        BinaryWriter writer = new BinaryWriter(stream);
        writer.Write(fileAsBytes);

        return stream;
}

Then I changed my Open method to convert file to Workbook.

public void Open(Stream fileSource)
{
        fileSource.Position = 0;
        FileFormatUtil.DetectFileFormat(fileSource);
        _workbook = new Workbook(fileSource);
}
zapoo
  • 1,548
  • 3
  • 17
  • 32