C#实现把txt文本数据快速读取到excel中

您所在的位置:网站首页 文本生成excel C#实现把txt文本数据快速读取到excel中

C#实现把txt文本数据快速读取到excel中

2023-12-15 22:51| 来源: 网络整理| 查看: 265

 

今天预实现一功能,将txt中的数据转到excel表中,做为matlab的数据源。搜集一些c#操作excel的程序。步骤如下:

下载一个Microsoft.Office.Interop.Excel.dll   在项目中引用。

编写代码如下:

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


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3