简体   繁体   English

有没有一种方法可以使用NPOI / C#将HTML表转换为xls / xlsx文件?

[英]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. 我的主要目标是在.NET应用程序的服务器端动态创建一个包含html表的xls。 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. 虽然,我的HTMLtable的Datamodel非常复杂,但是我设法在另一个用例中使用dotliquid创建了Model-将应用程序导出为pdf功能。 Here I use the EO.pdf-library from essential objects. 在这里,我使用基本对象的EO.pdf库。

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. 现在,我希望不需要做任何“双重工作”,因为在我的代码中,我有完整的HTML标记,可从中实际创建PDF。

Code to generate my pdf: 生成我的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. 在这里,我使用EO的“ ConvertHtml”方法将html(使用dotliquid创建)转换为PdfDocument-Instance。 To make a long story short, I'm searching for a method like this in NPOI. 长话短说,我正在NPOI中寻找这样的方法。 Is there a way to convert a HTML table to xls / xlsx-file via NPOI (other than the "manual" way)? 是否可以通过NPOI将HTML表转换为xls / xlsx文件(“手动”方法除外)?

Best Regards, getoveritde 最好的问候,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; 是的,有一种方法可以在C#中使用NPOI将html表转换为xls / xlsx文件,有关该方法的详细信息,请参见StackOverflow; you can find the solution for your problem in the link below: 您可以在下面的链接中找到解决问题的方法:

Create Excel (.XLS and .XLSX) file from C# 从C#创建Excel(.XLS和.XLSX)文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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