Opening Excel Document using EPPlus

前端 未结 2 1524
时光说笑
时光说笑 2021-02-07 03:16

I am trying to open an Excel document using EPPlus reference/package. I can\'t get the Excel application to open. What code am I missing?

protected void BtnTest_         


        
2条回答
  •  面向向阳花
    2021-02-07 03:47

    Try this in ASP NET Core to avoid win32 exception:

    private void CreateWorkbook(string fileName)
    {
        using (var p = new ExcelPackage())
        {
            p.Workbook.Properties.Author = "Barry Guvenkaya";
            p.Workbook.Properties.Title = "MyTitle";
            p.Workbook.Worksheets.Add("MySheet");
            var bin = p.GetAsByteArray();
            File.WriteAllBytes(fileName, bin);
    
            // Below code opens the excel doc
            var proc = new Process();
            proc.StartInfo = new ProcessStartInfo(fileName)
            {
                UseShellExecute = true
            };
            proc.Start();
        }
    }
    

提交回复
热议问题