Trying to read an Excel file with EPPlus works on the server, but not through a browser

泪湿孤枕 提交于 2019-12-04 02:50:15

EPPlus can load a file into memory. You're just not doing it that way. I think if you do this, you're less likely to run into trouble reading it from the file system. You can turn uploaded files into a byte array without having it as a file first, but in my example I'm opening an existing file. If you provide the code for how you're uploading the file, I can update my example.

byte[] file = File.ReadAllBytes(@"C:\file.xlsx");
using (MemoryStream ms = new MemoryStream(file))
using (ExcelPackage package = new ExcelPackage(ms))
{
    if (package.Workbook.Worksheets.Count == 0)
        strError = "Your Excel file does not contain any work sheets";
    else
    {
        foreach (ExcelWorksheet worksheet in package.Workbook.Worksheets)
        {
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!