C# 报表功能

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;

相关推荐
weixin_482565531 小时前
USB有驱IC卡读卡器
c#
闪电麦坤955 小时前
C#:Time.deltaTime
开发语言·c#
InCerry11 小时前
.NET周刊【3月第3期 2025-03-16】
c#·asp.net·.net
观无13 小时前
C# 扩展方法
开发语言·c#
画个逗号给明天"15 小时前
C#从入门到精通(4)
数据库·c#
观无18 小时前
c#中的virtual方法
开发语言·c#
code bean19 小时前
【C#】ForEach vs foreach
开发语言·c#
OpenSeek20 小时前
【设计模式】面向对象的设计模式概述
设计模式·c#·设计原则
码观天工21 小时前
10年+ .NET Coder 心语 ── 继承的思维:从思维模式到架构设计的深度解析
c#·.net·继承·思维·面相对象
FAREWELL000751 天前
C#核心学习(一)面向过程与面向对象编程---初识类和对象
学习·c#·面向对象