Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用epplus创建临时excel文件?_C#_Excel_Epplus - Fatal编程技术网

C# 使用epplus创建临时excel文件?

C# 使用epplus创建临时excel文件?,c#,excel,epplus,C#,Excel,Epplus,在使用epplus将所有我想要的内容添加到新创建的excel文件后,如何仅打开它?我不想先保存文件然后再打开它,这可能吗?我希望它只是打开,让用户决定是否要保存它 到目前为止,我找到并尝试的唯一代码是生成一个文件名,保存excel文件,然后打开它 Byte[] bin = p.GetAsByteArray(); string file = Guid.NewGuid().ToString() + ".xlsx"; File.WriteAllBytes(file, bin); ProcessStar

在使用epplus将所有我想要的内容添加到新创建的excel文件后,如何仅打开它?我不想先保存文件然后再打开它,这可能吗?我希望它只是打开,让用户决定是否要保存它

到目前为止,我找到并尝试的唯一代码是生成一个文件名,保存excel文件,然后打开它

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

不可能您无法使用epplus创建临时excel文件。不可能您无法使用epplus创建临时excel文件。epplus正在重命名的zip文件中生成xml,因此没有机制将其传输到excel而不将其保存在某处。但是你可以一直保存到users temp文件夹,这是大多数程序在某些时候为了在彼此之间传输文件所必须做的。可以使用
System.IO.Path.GetTempPath()
执行类似操作:


(摘自:)

EPPlus正在重命名的zip文件中生成xml,因此没有机制将其传输到Excel而不将其保存在某处。但是你可以一直保存到users temp文件夹,这是大多数程序在某些时候为了在彼此之间传输文件所必须做的。可以使用
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);
}