简体   繁体   English

ExcelPackage不使用C#以编程方式保存

[英]ExcelPackage not Saving programmatically using C#

I'm trying to edit an existing excel file with .xlsx extension using C#,but it is not saving the new value.My code is as follows.Can anybody help me? 我正在尝试使用C#编辑扩展名为.xlsx的现有excel文件,但未保存新值。我的代码如下。有人可以帮助我吗?

 string path = @"D:\Demo\test.xlsx"    ;  
    FileInfo file = new FileInfo(Path.GetFileName(path));
          using (ExcelPackage xlPackage = new ExcelPackage(file))
           {
                 ExcelWorkbook workBook = xlPackage.Workbook;
                 ExcelWorksheet ws = workBook.Worksheets[1];
                 ws.Cells[8, 6].Value = 25;
                 xlPackage.Save();
           }

Put the @ symbol before your path string to prevent automatic stripping or manually escape your \\ characters 在路径字符串前放置@符号,以防止自动剥离或手动转义\\字符

string path = @"D:\test\test.xslx";

Or 要么

string path = "D:\\test\\test.xslx";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM