将 HTML 内容导出到 ASP.NET MVC 中的 Excel

Export HTML content to Excel in ASP.NET MVC

我正在使用 Razor 视图引擎开发 MVC 应用程序,我需要将视图结果导出到 Excel。查看结果包含 divul 标记的列表。我的视图将是这样的。

@foreach (var alphabet in Model)
{
    <div class="ioslist-group-container-rule" data-value="@alphabet.Alphabet">      
        <div class="ioslist-group-header-rule alphabet">@alphabet.Alphabet</div>
        <ul style="margin-left: -40px; margin-top: 0px;">

          @foreach (var rule in alphabet.Rules)
            {
                <li class="rule-item" id="@rule.RuleID">@rule.Name</li>
            }

       </ul>
    </div>
}

我提到了这个 link Export to Excel

它将 HTML 字符串写入 Excel 文件而不是 HTML 样式的结果。如何在不使用 ExcelWorksheet class 或其他东西的情况下执行此操作?

我最近做了这件事,我也想要同样的东西。谷歌搜索后,我发现 Html 样式未导出到 excel,因为 excel 支持 xml 或 html,而不是 css 或任何其他自定义属性。

所以您想在 HTML 中为内联样式等样式添加标签。

例如

<table width='100%' cellspacing='0' cellpadding='2'>
<tr><td align='center' style='background-color: #18B5F0' colspan = '2'><b>Order Sheet</b></td></tr>
</table

你可以使用 <b> <i> <p> or any other tag, properties.

http://aspforums.net/Threads/916114/Export-HTML-string-to-Excel-with-formatting-in-ASPNet/

Export HTML Table to Excel using ASP.NET