0

I'm developing an MVC application with razor view engine and I need to export the view result to Excel. The view result contains a list of div and ul tags. 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

It writes the HTML string in the Excel file instead HTML styled result. How can I do this without using ExcelWorksheet class or something else?

Mathemats
  • 1,185
  • 4
  • 22
  • 35
Guna
  • 113
  • 3
  • 9

1 Answers1

1

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.

So you want to add tag for style like inline style in 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.

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

Export HTML Table to Excel using ASP.NET

Community
  • 1
  • 1
Ajay2707
  • 5,690
  • 6
  • 40
  • 58