HtmlToOpenXml

repository·master·Indexed 18 days ago

https://github.com/onizet/html2openxml

A .NET library that converts HTML markup into OpenXml components for programmatically generating Word documents. It supports .NET Framework 4.6.2, .NET Standard 2.0, .NET 8, and .NET 10, utilizing AngleSharp for HTML5 parsing and DocumentFormat.OpenXml for output.

Tokens
722
Snippets
1
Records
4
Agent score
14%

What's inside HtmlToOpenXml

  1. Run the HtmlToOpenXml benchmark tool

    master

    To evaluate the performance of the library, you can run the benchmark tool provided in the examples/Benchmark directory. The process involves building the project in Release mode and then executing the performance tests against multiple target runtimes (e.g., .NET Framework 4.8 and .NET 8.0).

    # Build the project in Release mode
    dotnet build -c Release
    
    # Run the performance test targeting multiple runtimes
    dotnet run -c Release -f net8.0 --runtimes net48 net8.0
  2. How to debug and implement OpenXml features

    master

    When implementing custom features or debugging the output of HtmlToOpenXml, you can inspect the underlying OpenXml structure of a .docx file:

    1. Create a document in Microsoft Word or Apple Pages that represents your desired output.
    2. Save the file as a .docx.
    3. Rename the file extension from .docx to .zip.
    4. Extract the contents of the zip file.
    5. Inspect the following XML files to understand the structure:
      • document.xml: The main document content.
      • numbering.xml: Definitions for lists.
      • styles.xml: Document styles.

    For technical reference, consult the MDN HTML documentation and the OpenXml MSDN documentation.

  3. Supported HTML tags in HtmlToOpenXml

    master

    The library converts a wide variety of HTML tags into their OpenXml equivalents.

    Supported Tags:

    • Headings: h1 through h6
    • Text Formatting: b, i, u, s, del, ins, em, strike, strong, sub, sup, abbr, acronym, cite, q, dfn
    • Structure & Layout: div, span, p, br, hr, blockquote, article, aside, section, time, font
    • Lists: ul, ol, li, dd, dt
    • Tables: table, thead, tbody, tfoot, tr, th, td, caption, col
    • Media: img, figcaption, svg
    • Preformatted: pre
    • Links: a

    Ignored or Treated as div:

    • Ignored: Javascript (script), CSS (style), meta tags, comments, buttons, and input controls.
    • Treated as div: Any other tags not explicitly supported.

    Note: Since v3, the library uses the AngleSharp package for parsing, which follows W3C HTML5 specifications.