1、Aspose组件下载
Aspose下载地址:https://products.aspose.com/cells/net
破解版下载地址:https://download.csdn.net/download/wylcy/10389581?utm_source=bbsseo
官方文档地址:https://docs.aspose.com/display/cellsnet/Home
官方Demo代码:https://github.com/aspose-cells/Aspose.Cells-for-.NET
2、安装Nuget包
.Net Core使用Aspose.Cells
组件,还要安装两个的Nuget包:
System.Drawing.Common
System.Text.Encoding.CodePages
Nuget使用教程:VS(Visual Studio)中Nuget的使用
3、创建Excel文件代码
public static void SaveExcelData(string path) { //Aspose.Cells.License li = new Aspose.Cells.License(); //li.SetLicense("Aspose.Cells.lic"); Aspose.Cells.Workbook wk = new Aspose.Cells.Workbook(); Worksheet ws = wk.Worksheets[0]; for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { ws.Cells.Rows[i][j].Value = (i + 1) + "*" + (j + 1) + "=" + (i + 1) * (j + 1); } } wk.Save(path); }
4、读取Excel文件代码
public static void ReadExcelData(string path) { DataTable dt = new DataTable(); //验证license //Aspose.Cells.License li = new Aspose.Cells.License(); //li.SetLicense("Aspose.Cells.lic"); Aspose.Cells.Workbook wk = new Aspose.Cells.Workbook(path); Worksheet ws = wk.Worksheets["人力资源报表"]; dt = ws.Cells.ExportDataTable(0, 0, ws.Cells.MaxDataRow + 1, ws.Cells.MaxDataColumn + 1); for (int k = 1; k < dt.Rows.Count; k++) { var code = dt.Rows[k][2].ToString(); var subDept = dt.Rows[k][0].ToString(); var dept = dt.Rows[k][1].ToString(); var userName = dt.Rows[k][3].ToString(); var gender = dt.Rows[k][4].ToString(); Console.WriteLine($"code={code},subDept={subDept},dept={dept},userName={userName},gender={gender}"); } }
5、本文项目代码下载
下载地址:https://www.cjavapy.com/download/5c4c4e49dc72d93b685b6f63/