现在我碰到一个问题是我的EXECL表格导出有问题,
private void saveFileDialog1_FileOk(object sender, CancelEventArgs e)
{
string FileName = saveFileDialog1.FileName;
outfilepath = FileName;
FileStream objFileStream;
StreamWriter objStreamWriter;
string strLine = "";
objFileStream = new FileStream(FileName, FileMode.OpenOrCreate, FileAccess.Write);
objStreamWriter = new StreamWriter(objFileStream, System.Text.Encoding.Unicode);
for (int m = 0; m < dt.Columns.Count; m++)
{
strLine = strLine + dt.Columns[m].ColumnName.ToString() + Convert.ToChar(9);
}
objStreamWriter.WriteLine(strLine);
strLine = "";
for (int k = 0; k < dt.Rows.Count; k++)
{
//strLine = strLine + (k + 1) + Convert.ToChar(9);//添加序号列
for (int l = 0; l < dt.Columns.Count; l++)
{
strLine = strLine + dt.Rows[k][l].ToString()+ Convert.ToChar(9);
}
objStreamWriter.WriteLine(strLine);
strLine = "";
}
objStreamWriter.Close();
objFileStream.Close();
}
我是这样导出的,但是出来的文件格式是文本格式,不是EXCEL工作薄的格式,文本格式不是我想要的,我仍然需要microsoft office excel 工作薄的格式.该怎么解决呢,请各位前辈帮帮忙!