小编Rav*_*ana的帖子

使用epplus C#更新现有工作簿

我正在尝试将新工作表添加到现有工作簿中,代码运行正常,没有任何错误.但是更改没有更新到excel文件.这是我的代码

string path = "C:\\TestFileSave\\ABC.xlsx";
FileInfo filePath = new FileInfo(path);
if (File.Exists(path)) 
{
    using(ExcelPackage p = new ExcelPackage()) 
    {
        using(stream = new FileStream(path, FileMode.Open, FileAccess.ReadWrite)) 
        {
            p.Load(stream);
            ExcelWorksheet ws = p.Workbook.Worksheets.Add(wsName + wsNumber.ToString());
            ws.Cells[1, 1].Value = wsName;
            ws.Cells[1, 1].Style.Fill.PatternType = ExcelFillStyle.Solid;
            ws.Cells[1, 1].Style.Fill.BackgroundColor.SetColor(Color.FromArgb(184, 204, 228));
            ws.Cells[1, 1].Style.Font.Bold = true;
            p.Save();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

c# excel epplus-4

3
推荐指数
2
解决办法
2万
查看次数

标签 统计

c# ×1

epplus-4 ×1

excel ×1