none
How to convert HTML to Word with indentation. RRS feed

  • Question

  • Hi,
    I am able to convert HTML to Word document using
    methods Application.Documents.Open() and 
    Document.SaveAs(). But how to do indentation while converting? I want some content of the file to be left aligned and some center. Also I want to embed some logo in Word Document.

    Please let me know the best possible way to do so without using third party tools.

    Thanks.


    -pavya

    • Moved by CoolDadTx Monday, May 9, 2016 2:35 PM Office related
    Monday, May 9, 2016 8:51 AM

Answers

  • I don't know how you'd achieve this with templates. You need to loop through the Body part of the HTML page and process each HTML tag, translating Paragraph, Table etc plus the corresponding CSS or inline style to Word format. Massive work.


    Best regards, George

    • Marked as answer by snooze1907 Thursday, May 12, 2016 10:32 AM
    Tuesday, May 10, 2016 10:30 AM

All replies

  • Monday, May 9, 2016 2:03 PM
  • I don't know if this is the "best way" but I have written VBA code to convert from .docx and .xlsx to HTML (without the massive code produced by Save As HTML). I loop through each line and produce HTML and CSS as needed. You need to do the same but opposite. There is no button to press to achieve this (unless you use third-party tools).

    Best regards, George

    Monday, May 9, 2016 2:44 PM
  • Ya, I agree its better to write own code to get required flexibility. But which would be better solution either templates or looping through each line and format each line?  

    Thanks


    -pavya

    Tuesday, May 10, 2016 9:23 AM
  • I don't know how you'd achieve this with templates. You need to loop through the Body part of the HTML page and process each HTML tag, translating Paragraph, Table etc plus the corresponding CSS or inline style to Word format. Massive work.


    Best regards, George

    • Marked as answer by snooze1907 Thursday, May 12, 2016 10:32 AM
    Tuesday, May 10, 2016 10:30 AM
  • Thank you 

    -pavya

    Thursday, May 12, 2016 10:31 AM
  • As far as I know it's hard to remain CSS layout when converting HTML to Word file without using 3rd party library, i suggest that you try this solution which requires a free DLL to be added as reference.

    http://www.nuget.org/packages/FreeSpire.Doc/

    Document document = new Document();

    document.LoadFromFile(@"D:\test.html",FileFormat.Html,XHTMLValidationType.None); document.SaveToFile("Html2Docx.docx", FileFormat.Docx);



    Thursday, July 21, 2016 4:02 AM