获取Excel

默认Excel文档为

获取Excel_第1张图片

代码如下   需要下载  "EPPlus.Core"

            var file = Directory.GetCurrentDirectory() + "\\Demo.xlsx";
            using (var source = System.IO.File.OpenRead(file))
            using (var excel = new OfficeOpenXml.ExcelPackage(source))
            {
                excel.Workbook.Worksheets[1].Cells[3, 1].Value = 123;
                excel.Workbook.Worksheets[1].Cells[3, 2].Value = 张三;
                excel.Workbook.Worksheets[1].Cells[3, 3].Value = 29;
                var newfile = Directory.GetCurrentDirectory() + "\\new.xlsx";
                var newfileinfo = new FileInfo(newfile);
                excel.SaveAs(newfileinfo);
            }

完成会生成如下Excel

 

你可能感兴趣的:(获取Excel)