码迷,mamicode.com
首页 > Web开发 > 详细

asp.net 查询到的数据导出为excel格式

时间:2015-11-19 19:22:10      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:asp.net   excel   

            DataTable pDataTable = newBLL.PRODUCT().GetModel(1862);          

            inttRowCount = pDataTable.Rows.Count;

            inttColumnCount = pDataTable.Columns.Count;

 

            Response.Expires = 0;

            Response.Clear();

            Response.Buffer = true;

            Response.Charset = "utf-8";

            Response.ContentEncoding =System.Text.Encoding.UTF8;

            Response.ContentType = "application/vnd.ms-excel";

            Response.AddHeader("Content-Disposition", "attachment; filename=Excel.xls");

            Response.Write("<meta http-equiv=Content-Typecontent=text/html;charset=utf-8>");          

            Response.Write("<Table borderColor=black border=1>");

            Response.Write("\n <TR>");

            for(int i = 0; i < tColumnCount; i++)

            {

                Response.Write("\n <TD bgcolor = #fff8dc>");

               Response.Write(pDataTable.Columns[i].ColumnName);

                Response.Write("\n </TD>");

            }

            Response.Write("\n </TR>");

            for(int j = 0; j < tRowCount; j++)

            {

                Response.Write("\n <TR>");

                for(int k = 0; k < tColumnCount; k++)

                {                

                    Response.Write("\n <TD align=\"right\"style=‘vnd.ms-excel.numberformat:@‘>");

 

                   Response.Write(pDataTable.Rows[j][k].ToString());

 

 

 

                    Response.Write("\n </TD>");

                }

                Response.Write("\n </TR>");

            }

 

            Response.Write("</Table>");

 

            Response.End();


asp.net 查询到的数据导出为excel格式

标签:asp.net   excel   

原文地址:http://smileface.blog.51cto.com/5740492/1714695

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!