VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > Python基础教程 >
  • C#教程之C# -- 使用Aspose.Cells创建和读取Excel文件

使用Aspose.Cells创建和读取Excel文件

1. 创建Excel

复制代码
 1             Aspose.Cells.License li = new Aspose.Cells.License();
 2             li.SetLicense("Aspose.Cells.lic");
 3             Aspose.Cells.Workbook wk = new Aspose.Cells.Workbook();
 4             Worksheet ws = wk.Worksheets[0];
 5             for (int i = 0; i < 9; i++)
 6             {
 7                 for (int j = 0; j < 9; j++)
 8                 {
 9                     ws.Cells.Rows[i][j].Value = (i + 1) + "*" + (j + 1) + "=" + (i + 1) * (j + 1);
10                 }
11             }
12             wk.Save("d:\\zzz\\d.xls");
13             Console.WriteLine("ok");
14             Console.ReadKey();
复制代码

产生的Excel文件:

 

 

2.读取Excel

复制代码
 1             DataTable dt = new DataTable();
 2             Aspose.Cells.License li = new Aspose.Cells.License();
 3             li.SetLicense("Aspose.Cells.lic");
 4             Aspose.Cells.Workbook wk = new Aspose.Cells.Workbook("d:\\zzz\\d.xls");
 5             Worksheet ws = wk.Worksheets[0];
 6 
 7             dt = ws.Cells.ExportDataTable(0, 0, 9, 9);
 8 
 9             for (int k = 0; k < dt.Rows.Count; k++)
10             {
11                 for (int h = 0; h < dt.Columns.Count; h++)
12                 {
13                     Console.Write(dt.Rows[k][h].ToString() + " ");
14                 }
15                 Console.WriteLine();
16             }
17             Console.WriteLine("ok");
18             Console.ReadKey();
复制代码

运行读取的结果:


相关教程