今天预实现一功能,将txt中的数据转到excel表中,做为matlab的数据源。搜集一些c#操作excel的程序。步骤如下:
下载一个Microsoft.Office.Interop.Excel.dll 在项目中引用。
编写代码如下:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 string path = "c://date//xyu.txt";
2 StreamReader sr = new StreamReader(path);
3 string strLine = sr.ReadLine();
4 int rowNum = 1;
5 object missing = System.Reflection.Missing.Value;
6
7 ApplicationClass app = new ApplicationClass();
8
9 app.Application.Workbooks.Add(true);
10
11 Workbook book = (Workbook)app.ActiveWorkbook;
12 Worksheet sheet = (Worksheet)book.ActiveSheet;
13 while (!string.IsNullOrEmpty(strLine))
14 {
15 string[] tempArr;
16 tempArr = strLine.Split(',');
17 for (int k = 1; k |