[英]Export HTML content to Excel in ASP.NET MVC
I'm developing an MVC application with razor view engine and I need to export the view result to Excel. 我正在使用剃刀视图引擎开发MVC应用程序,并且需要将视图结果导出到Excel。 The view result contains a list of
div
and ul
tags. 查看结果包含
div
和ul
标签的列表。 My view will be look like this. 我的看法将是这样。
@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>
}
I referred this link Export to Excel 我引用了此链接导出到Excel
It writes the HTML string in the Excel file instead HTML styled result. 它将HTML字符串写入Excel文件,而不是HTML样式的结果。 How can I do this without using ExcelWorksheet class or something else?
不使用ExcelWorksheet类或其他方法该怎么办?
I recently done this thing and I wanted the same thing. 我最近做了这个事情,我想要同样的事情。 After googled, I found that Html styles is not export into excel because excel is support xml or html, not css or any other custom properties.
谷歌搜索后,我发现HTML样式不会导出到excel中,因为excel支持xml或html,而不是css或任何其他自定义属性。
So you want to add tag for style like inline style in HTML. 因此,您想为HTML中的内联样式等样式添加标签。
For example 例如
<table width='100%' cellspacing='0' cellpadding='2'>
<tr><td align='center' style='background-color: #18B5F0' colspan = '2'><b>Order Sheet</b></td></tr>
</table
you can use <b> <i> <p> or any other tag, properties
. 您可以使用
<b> <i> <p> or any other tag, properties
。
http://aspforums.net/Threads/916114/Export-HTML-string-to-Excel-with-formatting-in-ASPNet/ http://aspforums.net/Threads/916114/Export-HTML-string-to-Excel-with-formatting-in-ASPNet/
Export HTML Table to Excel using ASP.NET 使用ASP.NET将HTML表导出到Excel
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.