I want to convert html to xls format without Microsoft Office

Asked 2 years ago, Updated 2 years ago, 57 views

I am using .NET Framework 3.5.

The target program uses Microsoft.Interop.Excel.dll to convert the Html format file to an Xls format file, but the target customer environment still has Excel installed, but it may be restricted or the dll does not call Excel.
It behaves as if Excel is not installed.

Currently, the above investigation is difficult, so we are investigating how to convert Html to xls without using the Excel function installed in the operating environment using the above dll. Do you know any samples?
It is possible to do the following without using a program using Excel, but I would like to use a third-party program such as NPOI to print xls without Excel installed.Until html can be generated, it can be verified in the target customer environment.

If you have a sample code, could you please let me know?It doesn't have to be NPOI.

excel

2022-09-30 13:48

2 Answers

For a fee, Aspose.Cells for .NET can be converted from html to .xls.I don't know how complicated the html is, but I think you should try it.

using System.IO;

using Aspose.Cells;
using System;

namespaceAspose.Cells.Examples.CSharp.Files.Handling
{
    public class OpeningHTMLFile
    {
        public static void Run()
        {
            // ExStart—1
            // The path to the documents directory.
            string dataDir=RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);


            US>//#string filePath=dataDir+"Book1.html";

            // Instantiate LoadOptions specified by the LoadFormat.
            Html LoadOptions loadOptions = new Html LoadOptions (LoadFormat.Html);

            // Create a Workbook object and opening the file from its path
            Workbook wb = new Workbook (filePath, loadOptions);
            // Save the MHT file
            wb.Save(filePath+"output.xlsx");
            // ExEnd:1
        }
    }
}

.NET Framework 3.5 is also supported.


2022-09-30 13:48

You can try this product by converting html to xls.
https://jp.e-iceblue.com/introduce/spire-xls-for-net.html
There is a free version.

Here's the code.

using Spire.Xls;

namespace HTML_to_Excel
{
    class program
    {
        static void Main (string[]args)
        {
            // Load the sample document 
            Workbook = new Workbook();
            workbook.LoadFromHtml("Sample.html");

            // AutoFitrows
            Worksheet sheet=workbook.Works[0];
            sheet.AllocatedRange.AutoFitRows();

            // Save the document to file
            workbook.SaveToFile("Result.xlsx", FileFormat.Version 2010);
            
        }
    }
}


2022-09-30 13:48

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.