【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)

1年前 (2022) 程序员胖胖胖虎阿
149 0 0

图表+table

【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)    protected void Button3_Click(object sender, EventArgs e)
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)    
{
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)        Response.Clear();
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)        Response.Buffer 
= true;
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)        Response.Charset 
= "GB2312";
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)        Response.AppendHeader(
"Content-Disposition""attachment;filename=FileName.xls");
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)        
// 
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)
        Response.ContentEncoding = System.Text.Encoding.UTF7;
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)        Response.ContentType 
= "application/ms-excel";//
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)

【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)        System.IO.StringWriter oStringWriter 
= new System.IO.StringWriter();
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)        System.Web.UI.HtmlTextWriter oHtmlTextWriter 
= new System.Web.UI.HtmlTextWriter(oStringWriter);
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)        
//path like http://【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版) 
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)
        string strPath = "select pms_value from code_list where pms_type='chart_path'";
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)        DataSet ds 
= db.GetDataSet(strPath);
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)        
string path = ds.Tables[0].Rows[0][0].ToString();
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)        
string imagePath = path + this.DaxonTechChartWeb1.ID + "." + this.DaxonTechChartWeb1.ImageType.ToString();
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)        oHtmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Src, imagePath);
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)        
//tableExcel is the Table
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)
        tableExcel.RenderControl(oHtmlTextWriter);
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)        Response.Output.Write(oStringWriter.ToString());
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)        Response.Flush();
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)        Response.End();
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)    }


gridview:

    protected void Button_toExcel_Click(object sender, EventArgs e)
    {
        Response.Clear();
        Response.Buffer 
= true;
        Response.Charset 
= "GB2312";
        Response.AppendHeader(
"Content-Disposition""attachment;filename=FileName.xls");
        
// 如果设置为 GetEncoding("GB2312");导出的文件将会出现乱码!!!
        Response.ContentEncoding = System.Text.Encoding.UTF7;
        Response.ContentType 
= "application/ms-excel";//设置输出文件类型为excel文件。 
        System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter oHtmlTextWriter 
= new System.Web.UI.HtmlTextWriter(oStringWriter);
       
//  turn off paging 
       
        GridView1.AllowPaging 
= false;
        GridView1.Columns[
0].Visible = false;
        GridView1.DataBind(); 
        GridView1.RenderControl(oHtmlTextWriter);
        Response.Output.Write(oStringWriter.ToString());
        Response.Flush();
        Response.End();
        
// turn the paging on again 
        GridView1.AllowPaging = true;
        GridView1.DataBind();

    }

07-12-5更新版
因有些chart在前台有加特效之类的,造成HtmlTextWriter在锁定元件上出错。
此就需要RenderBeginTagRenderEndTag来全部手动写入。

【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)    protected void Button3_Click(object sender, EventArgs e)
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)    
{
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)        Response.Clear();
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)        Response.Buffer 
= true;
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)        Response.Charset 
= "GB2312";
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)        Response.AppendHeader(
"Content-Disposition""attachment;filename=FileName.xls");
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)        
// 
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)
        Response.ContentEncoding = System.Text.Encoding.UTF7;
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)        Response.ContentType 
= "application/ms-excel";//
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)

【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)        System.IO.StringWriter oStringWriter 
= new System.IO.StringWriter();
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)        System.Web.UI.HtmlTextWriter oHtmlTextWriter 
= new System.Web.UI.HtmlTextWriter(oStringWriter);
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)        
//path
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)
        string strPath = "select pms_value from code_list where pms_type='chart_path'";
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)        DataSet ds 
= db.GetDataSet(strPath);
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)        
string path = ds.Tables[0].Rows[0][0].ToString();
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)        
string imagePath = path + this.DaxonTechChartWeb1.ID + "." + this.DaxonTechChartWeb1.ImageType.ToString();
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)        
//this.DaxonTechChartWeb1.ImagePath = imagePath;
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)
        oHtmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Table);
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)            oHtmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Height, 
this.DaxonTechChartWeb1.Height.Value.ToString());
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)            oHtmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Tr);
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)                oHtmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Td);
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)                    oHtmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Src, imagePath);
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)                    oHtmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Img);
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)                oHtmlTextWriter.RenderEndTag();
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)            oHtmlTextWriter.RenderEndTag();
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)            oHtmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Tr);
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)                oHtmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Td);
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)                    VegasGood.RenderControl(oHtmlTextWriter);
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)                oHtmlTextWriter.RenderEndTag();
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)             oHtmlTextWriter.RenderEndTag();
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)        oHtmlTextWriter.RenderEndTag();
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)        Response.Output.Write(oStringWriter.ToString());
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)        Response.Flush();
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)        Response.End();
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)
【Vegas原创】页面(图表+table+GridView)导出为excel(07-12-5更新版)    }

 

相关文章

暂无评论

暂无评论...