string FileNamePath = "你要导出的EXCEL的路径";
System.Data.DataTable dt = new System.Data.DataTable();
FileStream myFileStream = new FileStream(FileNamePath,FileMode.OpenOrCreate,FileAccess.Write);
StreamWriter myStreamWriter = new StreamWriter(objFileStream,System.Text.Encoding.Unicode);
string writeLine = "";
for( int i = 0 ; i < dt.Columns.Count ; i++ )
{
writeLine = writeLine + dt.Columns[i].ColumnName.ToString()+Convert.ToChar(9);
}
myStreamWriter.WriteLine(strLine);
writeLine = "";
for(int i = 0 ; i < dt.Rows.Count ; i++)
{
writeLine = writeLine + (i+1) + Convert.ToChar(9);
for(int j = 1 ; j < dt.Columns.Count ; j++)
{
writeLine = writeLine + dt.Rows[i][j].ToString() + Convert.ToChar(9);
}
myStreamWriter.WriteLine(writeLine);
writeLine = "";
}
myStreamWriter.Close();
myFileStream.Close();
一个天才顶不上十个笨蛋!
书山有路勤为径,学海无涯友相伴。
我的E-mail:mylover624@.cn