html2openxml icon indicating copy to clipboard operation
html2openxml copied to clipboard

In-document Links with HTML anchor tag

Open denizalpaslan opened this issue 3 years ago • 1 comments

Issue Description

Anchor tags (with # links) are converted into links in word document, however they are not navigating to the specified place when clicked.

Environment

Using version 2.3.0 with .net 6.0 application.

Input

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
     <body>
          <a href="#bookmark1">Bookmark 1</a><br/>
          <a href="#bookmark2">Bookmark 2</a><br/>
          Looks how cool is <font size="x-large"><b>Open Xml</b></font>.
          Now with <font color="red"><u>HtmlToOpenXml</u></font>, it nevers been so easy to convert html.
          <p>
               If you like it, add me a rating on <a href="https://github.com/onizet/html2openxml">github</a>
          </p>
          <div id="bookmark1">
               some text here.some text here.some text here.some text here.some text here.some text here.some text here.some text here.
               some text here.some text here.some text here.some text here.some text here.some text here.some text here.some text here.
          </div>
          <div id="bookmark2">
               some more text...
          </div>
          <hr>
     </body>
</html>

Method to convert HTML to Docx

        private static void ConvertHtmlToWord(string outputFileName, string html)
        {
            using (MemoryStream generatedDocument = new MemoryStream())
            {
                using (WordprocessingDocument package = WordprocessingDocument.Create(generatedDocument, WordprocessingDocumentType.Document))
                {
                    MainDocumentPart mainPart = package.MainDocumentPart;
                    if (mainPart == null)
                    {
                        mainPart = package.AddMainDocumentPart();
                        new Document(new Body()).Save(mainPart);
                    }

                    HtmlConverter converter = new HtmlConverter(mainPart);
                    converter.ParseHtml(html);

                    mainPart.Document.Save();
                }

                File.WriteAllBytes(outputFileName, generatedDocument.ToArray());
            }
        }

Expected Behavior In the converted document it should navigate to the section specified in the link, when clicked.

Current Behavior Click on the link does not have any effect, it seems to be navigating to the top where it is already.

denizalpaslan avatar Jun 08 '22 21:06 denizalpaslan

Hello, this has never really been implemented, but time to get this feature! Be sure to subscribe when v3 will be shipped

onizet avatar May 01 '24 21:05 onizet