У меня есть поток байтов со всеми данными, использующими Ep, и я хочу экспортировать файл в формате Excel с защитой паролем.Но он показывает ошибку в этой строке:
ws.Cells["A1"].LoadFromCollection(fileBytes.ToList());
Весь мой код:
public static void SendFileBytes(HttpResponse response, byte[] fileBytes, string fileName, string mimeType)
{
if (response != null && fileBytes != null && fileBytes.Length > 0 && !String.IsNullOrWhiteSpace(fileName) && !String.IsNullOrWhiteSpace(mimeType))
{
response.Clear();
response.Buffer = true;
response.ContentEncoding = System.Text.Encoding.UTF8;
response.ContentType = mimeType; // "application/pdf";
response.AddHeader("content-disposition", "attachment;filename=" + Uri.EscapeDataString(fileName));
response.Charset = "";
response.Cache.SetCacheability(HttpCacheability.NoCache);
using (ExcelPackage pack = new ExcelPackage())
{
ExcelWorksheet ws = pack.Workbook.Worksheets.Add("heelo");
ws.Cells["A1"].LoadFromCollection(fileBytes.ToList());
pack.Save("123");
var ms = new System.IO.MemoryStream();
pack.SaveAs(ms);
ms.WriteTo(HttpContext.Current.Response.OutputStream);
ms.Close();
}
response.Flush();
response.End();
}
}