Open dongfo opened 2 years ago
@dongfo MiniExcel.SaveAs(yourstream, yourreader);
It works for me . down load excel file like this.
using var db = new SqlConnection("....");
using var cmd = new SqlCommand("select * from table", db);
using var reader = await cmd.ExecuteReaderAsync(CommandBehavior.SequentialAccess);
var excelStream = new MemoryStream();
await MiniExcel.SaveAsAsync(excelStream, reader);
excelStream.Seek(0, SeekOrigin.Begin);
return Fie(excelStream,"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","export.xlsx");
and more ,when I try to zip this file and It's okay to create and download zip file.But the zip file can't open.
using var db = new SqlConnection("....");
using var cmd = new SqlCommand("select * from table", db);
using var reader = await cmd.ExecuteReaderAsync(CommandBehavior.SequentialAccess);
var excelStream = new MemoryStream();
await MiniExcel.SaveAsAsync(excelStream, reader);
excelStream.Seek(0, SeekOrigin.Begin);
var outStream = new MemoryStream();
using var archive = new ZipArchive(outStream, ZipArchiveMode.Create, true);
var csvFile = archive.CreateEntry($"export_{DateTime.Now:yyyyMMdd}.xlsx");
using var entryStream = csvFile.Open();
await excelStream.CopyToAsync(entryStream);
outStream.Seek(0, SeekOrigin.Begin);
return Fie(excelStream,"application/zip","export.zip");
waht is Fie?
Excel Type
Upload Excel File
Please attach your issue file by dragging or droppng, selecting or pasting them.
MiniExcel Version
MiniExcel 1.26.4
Description
as docs descriped saveAs to MemoryStream like this
to void load all data into memory ,I chose IDataReader
I want to combine them, Create excel and direct to memorystream for download.