Getting the following error for saving a workbook to a Response.
The type or namespace name ‘ContentDisposition’ does not exist in the namespace ‘Aspose.Cells’ (are you missing an assembly reference?)
workbook.Save(response, string.Format("{0}.xlsx", strName), Aspose.Cells.ContentDisposition.Attachment, new OoxmlSaveOptions(SaveFormat.Xlsx));
@FireWave ,
We have observed this issue and logged it in our database for further investigation. We will write back here once any update is available for sharing.
This issue is logged as:
CELLSNET-49746 - ContentDisposition.Attachment enumerator is missing in namespace .NET5
leoluo
November 5, 2021, 2:34am
3
Hi @FireWave
Due to .NET5 and .Netstandard20 do not contain the following object:
System.Web.HttpResponse
So the following method does not exist in Aspose.Cells .NET5 and .Netstandard20 version:
workbook.Save(response, string.Format("{0}.xlsx", strName), Aspose.Cells.ContentDisposition.Attachment, new OoxmlSaveOptions(SaveFormat.Xlsx));
Please confirm it, and you may call this method in .NET5 and .Netstandard20 version:
Workbook book = new Workbook(path + “test.xlsx”);
var stream = new MemoryStream();
book.Save(stream, SaveFormat.Xlsx);
You can then do operation to the stream.
Is there an equivalent for Microsoft.AspNetCore.Http.HttpResponse?
@FireWave ,
No, there is no equivalent API for Microsoft.AspNetCore.Http.HttpResponse. Anyways, we have recorded it against your ticket “CELLSNET-49746”. We will evaluate it and get back to you with more details soon.
leoluo
November 8, 2021, 7:11am
6
Hi @FireWave
Microsoft.AspNetCore.Http.HttpResponse only exist in asp.net Application.
Since we provide the netStandard library, we can not provide its overloaded methods.
After reading through your requirements, I’ve provided you with the following code snippet that shows how to transfer Steam to the object you need, hopefully for your benefit:
leoluo
November 8, 2021, 7:12am
7
Workbook book = new Workbook(path + “test.xlsx”);
var stream = new MemoryStream();
book.Save(stream, SaveFormat.Xlsx);
Microsoft.AspNetCore.Http.HttpResponse response = null;
FileFormatType fileFormatType = FileFormatType.Xlsx;
string fileName2 = “”;
string resultSpreadsheet = fileName2;
//Set content type
switch (fileFormatType)
{
case FileFormatType.Sxc:
case FileFormatType.Ods:
case FileFormatType.Ots:
response.ContentType = “application/ods”;
break;
case FileFormatType.Pdf:
response.ContentType = “application/pdf”;
break;
case FileFormatType.Csv:
response.ContentType = “application/csv”;
break;
case FileFormatType.TabDelimited:
response.ContentType = “application/txt”;
break;
case FileFormatType.Xlsx:
case FileFormatType.Xlsm:
case FileFormatType.Xltm:
case FileFormatType.Xltx:
response.ContentType = “application/xlsx”;
break;
//case FileFormatType.SpreadsheetML:
// response.ContentType = “text/xml”;
// break;
default:
response.ContentType = “application/vnd.ms-excel”;
break;
}
int index = resultSpreadsheet.LastIndexOf('\\');
if (index >= 0)
throw new CellsException(ExceptionType.InvalidData, "filename should not contain path");
response.Headers.Add("Content-Length", stream.Length.ToString());
//Add header
ContentDisposition saveType;
if (saveType == ContentDisposition.Attachment)
response.Headers.Add("content-disposition", "attachment; filename=\"" + resultSpreadsheet + "\"");
else
response.Headers.Add("content-disposition", "inline; filename=\"" + resultSpreadsheet + "\"");