1
votes

After adding all I want to a newly created excel file with epplus, how do I open it only? I don't want to save the file first then open it, is this possible? I want it to just open and let the user decide if he wants to save it or not.

The only code i've found and tried so far generates a file name, saves the excel file, and then open it.

Byte[] bin = p.GetAsByteArray();
string file = Guid.NewGuid().ToString() + ".xlsx";
File.WriteAllBytes(file, bin);
ProcessStartInfo pi = new ProcessStartInfo(file);
Process.Start(pi);
2

2 Answers

4
votes

EPPlus is generating the xml in a renamed zip file so there is no mechanism to transfer it to Excel without saving it somewhere. But you can always save to the users temp folder - this is what most programs have to do at some point in order to transfer files between each other. Can do something like this using System.IO.Path.GetTempPath():

[TestMethod]
public void TempFolderTest()
{
    var path = Path.Combine(Path.GetTempPath(), "temp.xlsx");
    var tempfile = new FileInfo(path);
    if (tempfile.Exists)
        tempfile.Delete();

    //Save the file
    using (var pck = new ExcelPackage(tempfile))
    {
        var ws = pck.Workbook.Worksheets.Add("Demo");
        ws.Cells[1, 2].Value = "Excel Test";
        pck.Save();
    }

    //open the file
    Process.Start(tempfile.FullName);
}

(taken from: Open ExcelPackage Object with Excel application without saving it on local file path)

0
votes

it's not possible you can't Create a temporary excel file with epplus