asp.net中的table 导出问题 急!!
小弟在做一个考勤系统,计算数据库中的打卡时间以得出迟到早退等信息并将其显示在Table中,现在要求将Table中显示的信息导出成doc或xls格式,该怎么做啊,哭求各位高手请教!急!!
参考答案:private void GetCSVFile(DataTable st)
{
FileStream out = new FileStream(Server.MapPath(@"\" + "csv.csv"), FileMode.OpenOrCreate); //FileMode.OpenOrCreate使用导的中文不是乱码
StreamWriter sw = new StreamWriter(out, System.Text.Encoding.Default);
string temp = "";
for (int i = 0; i < st.Columns.Count; i++)
{
temp += st.Columns[i].ToString() + ",";
}
if(temp.Substring(temp.Length-1,1) == ",")
{
temp = temp.Substring(0,temp.Length-1);
}
sw.WriteLine(temp);
temp = "";
for (int j = 0; j < st.Rows.Count; j++)
{
for (int k = 0; k < st.Columns.Count; k++)
{
temp += st.Rows[j][k].ToString() + ",";
}
if (temp.Substring(temp.Length-1, 1) == ",")
{
temp = temp.Substring(0,temp.Length-1);
}
sw.WriteLine(temp);
temp = "";
}
sw.Close();
out.Close();
}