简体   繁体   中英

Is there a way to convert a HTML table to xls / xlsx-file using NPOI/C#?

my main goal is to dynamically create a xls containing a html table on serverside in my .NET-Application. The Datamodel of my HTMLtable is pretty complex, though, but I managed to create the Model using dotliquid for another use case - the export to pdf-feature of my application. Here I use the EO.pdf-library from essential objects.

Now I hope there's no need to do some "double work", for at some point of my code, I have the complete HTML-Markup from which the PDF actually is created.

Code to generate my pdf:

#region plan

string legend = string.Empty;
string allg = string.Empty;
int lineCount = 0;
int dayCount = 0;

var plan = Utils.Pdf.ConvertToPdf.ConvertPlanTemplate(out allg, out legend, out lineCount, out dayCount);

if (RequestValues.Extension.ToLower() == "pdf")
{
    ...
    var doc = new EO.Pdf.PdfDocument();
    EO.Pdf.HtmlToPdf.ConvertHtml(plan, doc, options);
    ...
}

Here I Use EO's "ConvertHtml"-Method to convert my html (created using dotliquid) to my PdfDocument-Instance. To make a long story short, I'm searching for a method like this in NPOI. Is there a way to convert a HTML table to xls / xlsx-file via NPOI (other than the "manual" way)?

Best Regards, getoveritde

Yes, there is a way to convert an html table to an xls/xlsx file using NPOI in C# and that method is discussed on StackOverflow in detail; you can find the solution for your problem in the link below:

Create Excel (.XLS and .XLSX) file from C#

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM