首页 新闻 赞助 找找看

页面上的table怎么导出excel

0
悬赏园豆:5 [待解决问题]

网上搜了一下,用js好像没有兼容所有浏览器的,求教啊

拖鞋王子的主页 拖鞋王子 | 初学一级 | 园豆:37
提问于:2014-09-06 12:40
< >
分享
所有回答(4)
0

一般导出excel都是在服务器端编码处理的吧,怎么是使用js的?

诶碧司 | 园豆:1912 (小虾三级) | 2014-09-06 14:12
0

这个是都是用后台做的, ie用Active可以其他浏览器,就不行,还是在后台实现吧,比如用第三方组件npoi或者openxml实现吧

秋壶冰月 | 园豆:5903 (大侠五级) | 2014-09-06 19:39
0

页面发起导出请求(随带把数据源需要的参数传递回去),后台拿表格数据,然后利用多种方式(Excel组件,NPOI,EPPlus)生成Excel文件,然后返回这个文件供客户下载。

幻天芒 | 园豆:37175 (高人七级) | 2014-09-07 23:17
0
//dataTable导出Excel   
     protected void ExcelImport(DataTable dt, string ExportFileName)
        {
            StringWriter sw = GetStringWriter(dt);
            //当前编码  
            HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
            //把输出的文件名进行编码  
            string fileName = HttpUtility.UrlEncode(ExportFileName, System.Text.Encoding.UTF8);
            //文件名  
            string str = "attachment;filename=" + fileName + ".xls";
            //把文件头输出,此文件头激活文件下载框  
            HttpContext.Current.Response.AppendHeader("Content-Disposition", str);//http报头文件  
            HttpContext.Current.Response.ContentType = "application/ms-excel";

            Response.Write(sw);
            Response.End();
        }
  private StringWriter GetStringWriter(DataTable dt)
        {
            StringWriter sw = new StringWriter();
            //读列名  
            foreach (DataColumn dc in dt.Columns)
                sw.Write(dc.ColumnName + "\t");
            //读列值  
            //重新的一行  
            sw.Write(sw.NewLine);
            if (dt != null)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    for (int i = 0; i < dt.Columns.Count; i++)
                    {
                        sw.Write(dr[i].ToString() + "\t");
                    }
                    sw.Write(sw.NewLine);
                }
            }
            sw.Close();

            return sw;
        }
风醉 | 园豆:1197 (小虾三级) | 2014-09-09 14:06
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册