一、从txt文件中读取数据
StreamReader read = new StreamReader(strFilePath);
if (read == null)
string strTxt = read.ReadToEnd();
其中strTxt为txt文件内容;这种读取效率比逐行读取高些;
二、将数据存入DateTable中
此处省略,根据具体需求处理字符串;
三、存入Excel中
1、创建Excel
xslApp = new Microsoft.Office.Interop.Excel.Application();
xslApp.SheetsInNewWorkbook = 5;
xslApp.Workbooks.Add();
xslApp.Visible = true; //是否显示Excel
workbook.Saved = true; //是否保存
System.Globalization.CultureInfo CurrentCI = System.Threading.Thread.CurrentThread.CurrentCulture;
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
2、导出数据
object[,] data = new object[dt.Rows.Count, 11];
int count = 0;
for (int i = 0; i < dt.Rows.Count;i++ )
{
System.Data.DataRow dr = dt.Rows[i];
for (int j = 0; j < dt.Columns.Count - 1; j++)
{
data[count, j] = "'" + dr[j];
}
count++;
}
//填充数据
Microsoft.Office.Inte