从找到特定HTML标记的字符串中删除行

sla*_*dau 0 .net c# string export-to-excel asp.net-mvc-2

所以我有这个HTML页面通过MVC动作导出到Excel文件.该操作实际上将呈现此部分视图,然后将具有正确格式的呈现视图导出到Excel文件.但是,在导出之前,视图的呈现方式完全呈现,并且该视图包含"导出到Excel"按钮,因此当我导出它时,按钮图像在左上角显示为红色X. Excel文件.

我可以截取包含此HTML的字符串以在ExcelExport操作中呈现,并且它看起来像这样一个示例:

<div id="summaryInformation" >
<img id="ExportToExcel" style=" cursor: pointer;" src="/Extranet/img/btn_user_export_excel_off.gif" />
<table class="resultsGrid" cellpadding="2" cellspacing="0">
                <tr>
                    <td id="NicknameLabel" class="resultsCell">Nick Name</td>
                    <td id="NicknameValue"  colspan="3">
                        Swap
                    </td>
                </tr>
                <tr>
                    <td id="EffectiveDateLabel" class="resultsCell">
                        <label for="EffectiveDate">Effective Date</label>
                    </td>
                    <td id="EffectiveDateValue" class="alignRight">
                        02-Mar-2011
                    </td>
                    <td id ="NotionalLabel" class="resultsCell">
                        <label for="Notional">Notional</label>
                    </td>
                    <td id="NotionalValue" class="alignRight">
                        <span>
                            USD
                        </span>
                        10,000,000.00
                    </td>
                </tr>
                <tr>
                    <td id="MaturityDateLabel" class="resultsCell">
                        <label for="MaturityDate">Maturity Date</label>
                    </td>
                    <td id="MaturityDateValue" class="alignRight">
                        02-Mar-2016
                        -
                        Modified Following
                    </td>
                        <td id="TimeStampLabel" class="resultsCell">
                        Rate Time Stamp
                    </td>
                    <td id="Timestamp" class="alignRight">
                        28-Feb-2011 16:00
                    </td>
                </tr>
                <tr >
                    <td id="HolidatCityLabel" class="resultsCell"> Holiday City</td>
                    <td id="ddlHolidayCity" colspan="3">

                            New York, 
                            London
                    </td>
                </tr>
            </table>
</div>

<script>
    $("#ExportToExcel").click(function () {
        // ajax call to do the export
        var actionUrl = "/Extranet/mvc/Indications.cfc/ExportToExcel";
        var viewName = "/Extranet/Views/Indications/ResultsViews/SummaryInformation.aspx";
        var fileName = 'SummaryInfo.xls';
        GridExport(actionUrl, viewName, fileName);
    });
</script>
Run Code Online (Sandbox Code Playgroud)

<img id="ExportToExcel"顶部的那个标签是我想要为导出删除的标签.您看到的所有内容都包含在C#字符串中.我如何从字符串中删除该行,以便它不会尝试在Excel中渲染图像?

编辑:也许有意义的是我们也不需要<script>出口中的任何一个,但是因为这不会出现在Excel中,我认为这不是一件大事.

jim*_*415 7

删除所有img标签:

string html2 = Regex.Replace( html, @"(<img\/?[^>]+>)", @"",
    RegexOptions.IgnoreCase );
Run Code Online (Sandbox Code Playgroud)

包括参考:

using System.Text.RegularExpressions;
Run Code Online (Sandbox Code Playgroud)