Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Wed Jun 22, 2016 10:25 am

Good morning,
How to convert HTML Text to Word not converting HTML File to Word
can you give me an example

ababab
 
Posts: 4
Joined: Tue Jun 21, 2016 6:06 am

Thu Jun 23, 2016 1:39 am

Hi,

Thanks for your posting.
Here is an example.
Code: Select all
 PdfDocument pdf = new PdfDocument();

            PdfHtmlLayoutFormat htmlLayoutFormat = new PdfHtmlLayoutFormat();

            //webBrowser loads html whether waiting
            htmlLayoutFormat.IsWaiting = false;

            //page setting
            PdfPageSettings setting = new PdfPageSettings();
            setting.Size = PdfPageSize.A4;

            //use single thread to generate the pdf from above html code
            Thread thread = new Thread(() =>
            { pdf.LoadFromHTML(htmlText, false, setting, htmlLayoutFormat); });
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();

            pdf.SaveToFile("output.doc",FileFormat.DOC);
            System.Diagnostics.Process.Start("output.doc");


Welcome to write to us again if you need further assistance.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Fri Jun 24, 2016 8:10 am

Hi,

How did the example work?
Please feel free to contact us if you have any problems.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Sun Jun 26, 2016 6:35 am

Good morning,
your example output came as a photo in msword, it can not be editable.

but i found this examlpe,
Code: Select all
        Dim document As New Document()
        Dim paragraph As Documents.Paragraph = document.AddSection().AddParagraph()
        paragraph.Format.IsBidi = True
        paragraph.AppendHTML(div.InnerHtml)
        Dim tr As TextRange = paragraph.AppendText("")
        tr.CharacterFormat.Bidi = True
        document.SaveToFile("output.doc", FileFormat.Docx)

also i found another one,
Code: Select all
        Dim document As New Spire.Doc.Document()
        Dim tr As TextReader = New StringReader(div.InnerText)
        document.LoadHTML(tr, Documents.XHTMLValidationType.None)
        document.SaveToFile("output.doc", FileFormat.Doc)

it's work fine, but i have problems in arabic language directions.
there is any way to solve this problem.

thanks for your helping and best regards,

ababab
 
Posts: 4
Joined: Tue Jun 21, 2016 6:06 am

Mon Jun 27, 2016 6:06 am

Hi,

Thanks for your feedback.
Please share your html code and point out the issue by your document.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Tue Jun 28, 2016 8:45 am

Hi Amy,

Attached input Html file and output Word document.

Thanks and best regards,

ababab
 
Posts: 4
Joined: Tue Jun 21, 2016 6:06 am

Tue Jun 28, 2016 9:26 am

Hi,

Thanks for sharing your html file.
I have replicated your issue and forwarded it to our dev team. We will inform you when it is fixed.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Wed Jun 29, 2016 2:15 am

Hi,

After investigating, we find out a solution to correct arabic characters directions. By testing, I found that there was a little issue that paragraph alignment was changed on two places. Our dev team will fix it. We will inform you when it is fixed.
Code: Select all
   
            Document document = new Document();
            //load html file
            document.LoadFromFile("..\\..\\input\\HTMLfile.html",FileFormat.Html,XHTMLValidationType.None);
             //or load html code
             //string htmlcode = File.ReadAllText("..\\..\\input\\HTMLfile.html");
             //TextReader tr = new StringReader(htmlcode);
             //document.LoadHTML(tr, XHTMLValidationType.None);

            foreach (Section section in document.Sections)
            {
                foreach (DocumentObject obj in section.Body.ChildObjects)
                {
                    if (obj.DocumentObjectType == DocumentObjectType.Paragraph)
                    {
                        Paragraph para = obj as Paragraph;
                        foreach (ParagraphBase paragraphBase in para.ChildObjects)
                        {
                            paragraphBase.CharacterFormat.Bidi = true;
                        }
                    }
                    if (obj.DocumentObjectType == DocumentObjectType.Table)
                    {
                        SetParagraphInTable(obj as Table);
                    }
                }
            }
            document.SaveToFile("output.docx", FileFormat.Docx);
            System.Diagnostics.Process.Start("output.docx");
       
        private static void SetParagraphInTable(Spire.Doc.Table table)
        {
            for (int i = 0; i < table.Rows.Count; i++)
            {
                Spire.Doc.TableRow row = table.Rows[i];
                for (int j = 0; j < row.Cells.Count; j++)
                {
                    Spire.Doc.TableCell cell = row.Cells[j];
                    if (cell.Tables.Count > 0)
                    {
                        foreach (DocumentObject cellChild in cell.ChildObjects)
                        {
                            if (cellChild.DocumentObjectType == DocumentObjectType.Table)
                            {
                                SetParagraphInTable(cellChild as Spire.Doc.Table);
                            }
                        }
                    }
                    foreach (Paragraph paragraph in cell.Paragraphs)
                    {
                        foreach (ParagraphBase paragraphBase in paragraph.ChildObjects)
                        {
                            paragraphBase.CharacterFormat.Bidi = true;
                        }
                    }
                }
            }
        }



Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Wed Jun 29, 2016 6:04 am

Hi Amy,

Thanks for your cooperation.

Best regards,

ababab
 
Posts: 4
Joined: Tue Jun 21, 2016 6:06 am

Thu Sep 01, 2016 11:42 pm

Such style, many type, so appealing

OvelagahFoelo
 
Posts: 2
Joined: Wed Dec 05, 2012 7:49 am

Fri Sep 02, 2016 1:44 am

Dear OvelagahFoelo,

Thanks for your feedback.
Please feel free to contact us if there is any question or needs. We are here for hlep.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Return to Spire.Doc