赞
踩
EPPlus(Excel读写)
EPPlus官网:https://github.com/JanKallman/EPPlus
首先随意设置一个文件路径文件路径string filepath=@“\Assets\Test.xlsx”
1、获取文件属性:
FileInfo fileInfo = new FileInfo(filepath);
2、打开Excel表格:
ExcelPackage excelPackage = new ExcelPackage(fileInfo)
3、打开后文件后关闭:
using (ExcelPackage excelPackage = new ExcelPackage(fileInfo)){}//当using语句结束之后自动释放资源
4、获取Excel中的第n张表:
ExcelWorksheet worksheet = excelPackage.Workbook.Worksheets[n];
5、取得表中第i行第j列的数据
string s = worksheet.Cells[i, j].Value.ToString();
6、往第i行第j列写入数据Data:
worksheet.Cells[i, j].Value = “Data”;
7、保存文件:
excelPackage.Save();
8、添加页面sheet1:
ExcelWorksheet worksheet = excelPackage.Workbook.Worksheets.Add(“sheet1”);
9、删除页面sheet1:
excelPackage.Workbook.Worksheets.Delete(“sheet1”);
10、表的最后一行/列:
worksheet.Dimension.End.Row / Column;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。