问题描述
數據導出到excel的問題,excel中顯示的是RadioButton,需要根據頁面中dropdownlist的選中情況使excel中的對應RadioButton選中。怎么办?我现在会将数据导出到excel,但如何操作excel中的radiobutton呢?
解决方案
解决方案二:
//使用GridView导出excel表格,导出excel对特殊的控件进行模式化处理publicstaticvoidPrepareGridViewForExport(Controlgv)//模式化特殊元素的函数{HyperLinklb=newHyperLink();LinkButtonbt=newLinkButton();Literall=newLiteral();stringname=String.Empty;RadioButtonrb=newRadioButton();for(inti=0;i<gv.Controls.Count;i++){if(gv.Controls[i].GetType()==typeof(HyperLink)){l.Text=(gv.Controls[i]asHyperLink).Text;gv.Controls.Remove(gv.Controls[i]);gv.Controls.AddAt(i,l);}elseif(gv.Controls[i].GetType()==typeof(DropDownList)){DropDownListdl=gv.Controls[i]asDropDownList;for(intj=0;j<this.dl.Items.Count;j++){rb.Text=dl.Items[j].Text;if(rb.Text==dl.SelectedItem.Text)rb.Checked=true;gv.Controls.AddAt(i,l);}gv.Controls.Remove(dl);//移除DropDownlist}elseif(gv.Controls[i].GetType()==typeof(CheckBox)){l.Text=(gv.Controls[i]asCheckBox).Checked?"":"";gv.Controls.Remove(gv.Controls[i]);gv.Controls.AddAt(i,l);}elseif(gv.Controls[i].GetType()==typeof(ImageButton)){l.Text="图片";gv.Controls.Remove(gv.Controls[i]);gv.Controls.AddAt(i,l);}if(gv.Controls[i].HasControls()){PrepareGridViewForExport(gv.Controls[i]);}}}//GridView导出excel数据源///<summary>///从GridView导出excel///</summary>///<paramname="sender"></param>///<paramname="e"></param>protectedvoidibtnExport_Click(objectsender,ImageClickEventArgse){getgvDataSource();//绑定GridView控件gvResponse.Charset="GB2312";Response.ContentEncoding=System.Text.Encoding.UTF7;Response.AppendHeader("Content-Disposition","attachment;filename="+HttpUtility.UrlPathEncode("人员信息表.xls"));Response.ContentType="application/ms-excel";this.EnableViewState=false;StringWritertw=newStringWriter();HtmlTextWriterhw=newHtmlTextWriter(tw);PrepareGridViewForExport(gv);//调用模式化特殊元素gv.RenderControl(hw);Response.Write(tw.ToString());Response.End();}
解决方案三:
楼上的好像不太试用啊!!
解决方案四:
elseif(gv.Controls[i].GetType()==typeof(DropDownList)){DropDownListdl=gv.Controls[i]asDropDownList;for(intj=0;j<this.dl.Items.Count;j++){rb.Text=dl.Items[j].Text;if(rb.Text==dl.SelectedItem.Text)rb.Checked=true;gv.Controls.AddAt(i,rb);//这里错了应该是rb}gv.Controls.Remove(dl);//移除DropDownlist}我曾经遇到也是这样的问题,就是这样解决的。。。
解决方案五:
我的意思是radiobutton(在excel中的名字是OptionButton)已经存在与excel模板中了,而不是将gridview导出到excel,需要更具页面的dropdownlist的不同选项使excel模板中的不同OptionButton选中!!麻烦再帮忙想想