把html导出到excel文件时候 style="display: none"失效了该怎么办呀?如何在exceL文件中实现display:none的效果?
解决方案 »
- GridView中多个超链接的问题
- ASP.NET中使用parameters.add一直出错请帮忙看一下,谢谢,
- SoftMarketSrv.discomap,SoftMarketSrv.disco,SoftMarketSrv.wsdl文件问题
- 如何实现鼠标单击 选中 GridView 中的一行?急!
- 调查: 请问一个项目中大家的任务是多少?按代码量算 还是 按页面算,分别是多少?
- 用语句Response.Redirect("http://www.sohu.com")打开网页后出现的问题。
- GridView中使用了checkbox如何绑定到数据源的列中
- 为什么Textbox上传到数据库后变成乱码
- 是否有符合CLR标准的判断对象是否为空的方法。
- 插入问题!
- asp.net 查找时间段的问题,在线等待,
- 如何将repeater中的内容,追条村如数据中呢?
string content="sdfsfsfdsf";//你要导出的东西
content = content.Replace("none","");然后再输出content 就OK了
<table id="Table2" border="1" cellpadding="0" class="cGrid2" cellspacing="" width="100%"
align="center">
<tr style="height: 25px" class="cGridHeader1">
<td rowspan="2" id="TD1" runat="server">
<input id="checkAll" type="checkbox" runat="server" onclick="checkAll1(this);" />
</td>
<td rowspan="2" style="text-align: center">
序号</td>
<td rowspan="2" style="text-align: center">
企业名称</td>
<td rowspan="2" style="text-align: center">
申请许可事项</td>
<td colspan="3" style="text-align: center">
企业具备条件</td>
<td rowspan="2" style="text-align: center">
初审意见</td>
<td rowspan="2" style="text-align: center">
备注</td>
<td colspan="3" style="text-align: center">
业务指导组成员单位监督意见</td>
<td rowspan="2" id="TD2" runat="server">
批次
</td>
<td rowspan="2" id="TD3" runat="server">
状态</td>
</tr>
<tr class="cGridHeader1" style="height: 25px; text-align: center">
<td>
资金</td>
<td>
人员</td>
<td>
业绩</td>
<td>
诚信不良记录</td>
<td>
安全违规记录</td>
<td>
违纪违规记录</td>
</tr>
<asp:Repeater ID="JustAppInfo_List" runat="server">
<ItemTemplate>
<tr style="height: 25px; text-align: center">
<td id="repTD1" runat="server">
<input type="checkbox" id="CheckItem" runat="server" onclick='<%# Eval("Fid","document.getElementById(\"cb{0}\").checked=this.checked;") %>' />
<input type="checkbox" style="display: none" name='IsCheck' id='<%# Eval("Fid","cb{0}") %>'
value='<%# Eval("Fid") %>' />
</td>
<td>
<%# (Container.ItemIndex + 1) + this.Pager1.pagecount * (this.Pager1.curpage - 1)%>
</td>
<td style="text-align: left">
<%# Eval("FEntName")%>
</td>
<td>
<%# rc.GetSignValue(Approve.EntityBase.EntityTypeEnum.EsManageType, "FName", "FNumber='" +Eval("FManageTypeId") + "'") %>
</td>
<td>
<%# GetRegistFund( Eval("FBaseInfoId"),Eval("FLinkId")) %>
</td>
<td>
</td>
<td>
</td>
<td>
<%# GetResult( Eval("FResult")) %>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
<td id="repTD2" runat="server">
<%# GetBatchNo(Eval("FLinkId"))%>
</td>
<td id="repTD3" runat="server">
<%# GetState(Approve.EntityBase.EConvert.ToString(Eval("FMeasure")),Approve.EntityBase.EConvert.ToString(Eval("FState"))) %></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
</div>
protected void btnOut_Click(object sender, EventArgs e)
{
//JustAppInfo_List.Columns[0].Visible = false;
string fOutTitle = lPostion.Text;
TD1.Visible = false;
TD2.Visible = false;
TD3.Visible = false;
foreach (RepeaterItem item in JustAppInfo_List.Items)
{
HtmlTableCell repTD = item.FindControl("repTD1") as HtmlTableCell;
if (repTD != null)
{
repTD.Visible = false;
}
repTD = item.FindControl("repTD2") as HtmlTableCell;
if (repTD != null)
{
repTD.Visible = false;
}
repTD = item.FindControl("repTD3") as HtmlTableCell;
if (repTD != null)
{
repTD.Visible = false;
}
if (!string.IsNullOrEmpty(Request.Form["IsCheck"]))
{
HtmlInputCheckBox cb = item.FindControl("CheckItem") as HtmlInputCheckBox;
if (cb != null && !cb.Checked)
{
item.Visible = false;
}
}
}
Export(this, div1, fOutTitle +DateTime.Now.ToString("yyyy年MM月dd日")+ ".xls", "application/ms-excel", fOutTitle);
}
{
StringBuilder strExcel = new StringBuilder();
string FileName = DateTime.Now.ToLongTimeString();
//去掉display:none的行
Regex reg = new Regex(@"<(\S+)([^>]*?)style(\s*?)=(\s*?)[^\=]*?display(\s*?)\:(\s*?)none([^<]*?)<\/\1>", RegexOptions.Multiline); System.IO.StringWriter SW = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter HTW = new System.Web.UI.HtmlTextWriter(SW);
rpTemp.RenderControl(HTW); //Page为要导出的对象,当前是Page,如果是DataGrid,DataList等都可以
Response.Buffer = true;
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/vnd.ms-excel";
//Response.ContentType是输出流的 HTTP MIME 类型
//Response.ContentType --- word文件
//application/vnd.ms-excel --- excel文件
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AddHeader("Content-Disposition", "attachment;filename=" + FileName + ".xls");
//attachment --- 作为附件下载
//inline --- 在线打开
//filename如过是中文,则可以用HttpUtility.UrlEncode(fileName,System.Text.Encoding.UTF8)
//进行进行编码,以解决文件名乱码的问题
//strExcel.Append("<table>").Append(SW.ToString()).Append("</table>"); //<td id="ctl00_Content_rpImportAcResource_ctl24_tdImportformat" style="display: none">
// 飞扬视频广告
// </td>
string temp = SW.ToString();
strExcel.Append(reg.Replace(temp, ""));
Response.Write(strExcel.ToString());
Response.Flush();
Response.Close();
}