把html导出到excel文件时候 style="display: none"失效了该怎么办呀?

嘴哥臭鼬 2009-03-23 11:24:59
把html导出到excel文件时候 style="display: none"失效了该怎么办呀?如何在exceL文件中实现display:none的效果?
...全文
470 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
嘴哥臭鼬 2009-03-23
  • 打赏
  • 举报
回复
    public void RepeaterToExcel(Repeater rpTemp)
{
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();
}
Robin 2009-03-23
  • 打赏
  • 举报
回复
display:none 导出Excel 是无效的

<div id="div1" runat="server">
<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);
}
wanglei0420 2009-03-23
  • 打赏
  • 举报
回复
首先你是能得到你要导出的EXCEL的字符串的。。然后你这样
string content="sdfsfsfdsf";//你要导出的东西
content = content.Replace("none","");

然后再输出content 就OK了
嘴哥臭鼬 2009-03-23
  • 打赏
  • 举报
回复
我知道了
嘴哥臭鼬 2009-03-23
  • 打赏
  • 举报
回复
ding

62,268

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧