C# 报表功能
csharp
public class ExcelHelper
{
ExcelPackage objExcelPage;
public ExcelHelper(string excelPath)
{
objExcelPage = new ExcelPackage(new FileInfo(excelPath));
}
public void Write(int sheetIndex, int rowIndex, int columnIndex, string msg)
{
objExcelPage.Workbook.Worksheets[sheetIndex].Cells[rowIndex, columnIndex].Value = msg;
}
public string Read(int sheetIndex, int rowIndex, int columnIndex)
{
return objExcelPage.Workbook.Worksheets[sheetIndex].Cells[rowIndex, columnIndex].Value.ToString();
}
public void Close()
{
objExcelPage.Dispose();
}
public void SaveAs(string path)
{
objExcelPage.SaveAs(new FileInfo(path));
// 关闭Excel对象
objExcelPage.Dispose();
}
}
需引用EPPlus.dll(在NuGet中下载)
命名空间:using OfficeOpenXml;