visual studio 怎么将数据导出到EXCEL表中,要用什么控件,写什么代码,在线等
2个回答
展开全部
楼主:这是C# 导出数据的方法
string strcon = ConfigurationManager.ConnectionStrings["ConnectionStringBOBExecl "].ToString();
SqlConnection cn = new SqlConnection(strcon);
SqlDataAdapter da = new SqlDataAdapter("SELECT ftitle,senddate,sender,RecCom FROM [Bulletin] ORDER BY [senddate]", cn);
DataSet ds = new DataSet();
da.Fill(ds, "Bulletin");
DataTable dt = ds.Tables["Bulletin"];
System.IO.StringWriter sw = new System.IO.StringWriter();
sw.WriteLine("标题\t发布时间\t发布人\t发送范围");
foreach (DataRow dr in dt.Rows)
{
sw.WriteLine(dr["ftitle"] + "\t " + dr["senddate"] + "\t" + dr["sender"] + "\t" + dr["RecCom"]);
}
sw.Close();
Response.AddHeader("Content-Disposition", "attachment;filename=SmartOA.xls");
Response.ContentType = "application/ms-excel";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.Write(sw);
Response.End();
string strcon = ConfigurationManager.ConnectionStrings["ConnectionStringBOBExecl "].ToString();
SqlConnection cn = new SqlConnection(strcon);
SqlDataAdapter da = new SqlDataAdapter("SELECT ftitle,senddate,sender,RecCom FROM [Bulletin] ORDER BY [senddate]", cn);
DataSet ds = new DataSet();
da.Fill(ds, "Bulletin");
DataTable dt = ds.Tables["Bulletin"];
System.IO.StringWriter sw = new System.IO.StringWriter();
sw.WriteLine("标题\t发布时间\t发布人\t发送范围");
foreach (DataRow dr in dt.Rows)
{
sw.WriteLine(dr["ftitle"] + "\t " + dr["senddate"] + "\t" + dr["sender"] + "\t" + dr["RecCom"]);
}
sw.Close();
Response.AddHeader("Content-Disposition", "attachment;filename=SmartOA.xls");
Response.ContentType = "application/ms-excel";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.Write(sw);
Response.End();
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
不是很明白你的意思.只要你能读取到你所需要的数据,就可以通过转换直接导出到excel中的 你能否说的明白点呢
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询