Hi Aspose Team,
I am using Aspose.Cells of version 17.1.0 with a license file. I have written REST end point which returns a excel file. For that I am loading workbook using template and loading data into it and returning it as a attachment. following is the code
var binPath = System.Web.Hosting.HostingEnvironment.MapPath("~/bin");
var stream = new FileStream(binPath + "//MyTemplate.xlsx", FileMode.Open, FileAccess.Read);
var loadOptions = new LoadOptions(LoadFormat.Xlsx);
var workbook = new Workbook(stream, loadOptions);
stream.Close();
var cells = workbook.Worksheets[0].Cells;
cells.ImportCustomObjects(data.Collection, data.Fields, false, 11, 0, data.Collection.Count,
true, "mm/dd/yyyy", true);
var memStream = new MemoryStream();
workbook.Save(memStream, SaveFormat.Xlsx);
memStream.Position = 0;
response.Content = new StreamContent(memStream);
response.Content.Headers.ContentDisposition =
new ContentDispositionHeaderValue("attachment") { FileName = data.FileName + (data.ViewType == ViewTypeEnum.PDF ? ".pdf" : ".xlsx") };
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
response.Content.Headers.ContentLength = memStream.Length;
response.StatusCode = HttpStatusCode.OK;
return response;
And the strange part is this is working fine locally but when I deploy it to QA environment excel gets corrupted. I tried to load data locally which is there in QA environment but it still works fine locally.
I have seen your other post where people reported same issue and tried following things
- workbook.Save(memStream, new OoxmlSaveOptions(SaveFormat.Xlsx));
- memStream.Seek(0, SeekOrigin.Begin); & memStream.Close();
But no luck.
Please advise, what could be the reason.