我自己有個函數.但只能導出一個DATAGRID.:(大家有好建議嗎?請各位指示一下.

解决方案 »

  1.   

    看看这个帖子吧http://community.csdn.net/Expert/topic/4199/4199288.xml?temp=.7531702
      

  2.   

    導出函數是這樣的. public static void ExportToExcel(DataGrid m_grid, Page _page)
    {
    _page.Response.Clear();
    _page.Response.Buffer = true;
    _page.Response.Charset = "UTF-8"; //Encoding.Default.ToString() ;//"GB2312", StringBuilder m_strName = new StringBuilder();
    m_strName.Append(DateTime.Now.Year.ToString()).Append(DateTime.Now.Month.ToString())
    .Append(DateTime.Now.Day.ToString()).Append(DateTime.Now.Hour.ToString())
    .Append(DateTime.Now.Minute.ToString()).Append(DateTime.Now.Second.ToString()); _page.Response.AppendHeader("Content-Disposition", "attachment;filename=ExportData" + m_strName.ToString() + ".xls"); _page.Response.ContentEncoding = Encoding.GetEncoding("UTF-8"); //
    //_page.Response.ContentEncoding = Encoding.Default; _page.Response.ContentType = "application/ms-excel"; _page.EnableViewState = false; //CultureInfo m_CI = new CultureInfo("zh-hk", true); //("EN-US",true);
    //StringWriter m_stringWriter = new StringWriter(m_CI);
    StringWriter m_stringWriter = new StringWriter();
    HtmlTextWriter m_htmlTextWriter = new HtmlTextWriter(m_stringWriter); //added by kevin start
    //string header = string.Format("<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset={0}\"></head><body>",_page.Response.ContentEncoding.WebName);
    string header =
    string.Format("<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset={0}\"></head><body>",
                  "UTF-8"); string footer = "</body></html>"; //added by kevin end //htmlTextWriter
    m_grid.RenderControl(m_htmlTextWriter); _page.Response.Write(header + m_stringWriter.ToString() + footer); //
    _page.Response.End();
    }
      

  3.   

    帮你up一下 顺便做个广告 谁帮我解答一下这个问题啊,帖子地址:
    http://community.csdn.net/Expert/TopicView.asp?id=4843558为什么我的帖子老上不了问题列表呢?