I'm developing a report in Excel, from a WebPage. The page have some chart's and some data inside some tables. I have an excel file, that works as a model to write data inside the file. I created some chart´s inside the sheet, and write data inside some sheet, and i reference this data to use it on chart's. Everything works well, except by the fact that I cannot download the file.
I created a piece of code to do this, and I generated the file successfully. What I'm trying to do now, is download this file.
So i tried something:
So, I generate the file, and the file as been downloaded, but comes corrupted.
API
var mimeType = "application/vnd.ms-excel";
string file = Path.Combine(path, fileName);
var memory = new MemoryStream();
using (var stream = new FileStream(file, FileMode.Open))
{
stream.CopyTo(memory);
}
memory.Position = 0;
return File(memory, mimeType, "filename.xlsx");
Angular
return $http.post(url, data, config)
.then(function (response) {
//TODO: Implementar o download do arquivo
var file = new Blob([data], { type: 'application/vnd.ms-excel' });
saveAs(file, 'filename.xlsx');
}).catch(function (error) {
console.log("error");
});