Base64 excel文件streamAspose.Cells.CellsException

我有一个xls文件的Base64string。 当我尝试打开base64stream时,会引发以下exception

Aspose.Cells.CellsException :这个文件的格式不被支持,或者你没有指定正确的格式。

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); } 

我改变了代码的相关部分,它的工作。 现在我可以使用base64 excelstring了。

首先,我使用BinaryWriter将文件转换为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; } 

然后我改变了我的Open方法将文件转换为Workbook。

 public void Open(Stream fileSource) { fileSource.Position = 0; FileFormatUtil.DetectFileFormat(fileSource); _workbook = new Workbook(fileSource); }