wordpress hit counter
Welcome to OpenXML Developer Sign in | Join | Help

html markup to word ml

Last post 03-02-2009, 1:06 AM by goodol. 2 replies.
Sort Posts: Previous Next
  •  11-24-2008, 5:48 AM 3892

    html markup to word ml

    How can I convert a block of text containing html tags for bold italic and underline into wordml tags.

    for eg. " This is test <b>comment</b> .The authors have <i>done</i> a fairly <u>good</u> job. <b><u>Please help</u><b>".

     

    Basically I am taking in text input from user in an web based html text editor and generating the word document on the fly.

  •  02-25-2009, 10:41 AM 4161 in reply to 3892

    Re: html markup to word ml

    Hi,

    have you found a solution for that?

     

    Jerry

  •  03-02-2009, 1:06 AM 4189 in reply to 3892

    Re: html markup to word ml

    You just need to create new Run Properties to preserve bold, italic and underline style of characters in Word document.

    This is what I want to store in a word document:

    This is the example for applying bold, italic and underline style to characters in Word document.

    Below are the codes generated by DocumentReflector (a tool shipped with SDK), you may pay attention to codes in red.

    using DocumentFormat.OpenXml.Wordprocessing;
    using DocumentFormat.OpenXml;

    namespace GeneratedCode
    {
        public class GeneratedClass
        {
            public static Document GenerateDocument()
            {
                var element =
                    new Document(
                        new Body(
                            new Paragraph(
                                new Run(
                                    new Text("This is the example for applying "){ Space = "preserve" }),
                                new Run(
                                    new RunProperties(
                                        new Bold()),
                                    new Text("bold")
                                ){ RsidRunProperties = "00FA7F5A" },
                                new Run(
                                    new Text(", "){ Space = "preserve" }),
                                new Run(
                                    new RunProperties(
                                        new Italic()),
                                    new Text("italic")
                                ){ RsidRunProperties = "00FA7F5A" },
                                new Run(
                                    new Text(" and "){ Space = "preserve" }),
                                new Run(
                                    new RunProperties(
                                        new Underline(){ Val = UnderlineValues.Single }),
                                    new Text("underline")
                                ){ RsidRunProperties = "00FA7F5A" },
                                new Run(
                                    new Text(" style to characters in Word document."){ Space = "preserve" })
                            ){ RsidParagraphAddition = "004E0028", RsidRunAdditionDefault = "00FA7F5A" },
                            new SectionProperties(
                                new PageSize(){ Width = (UInt64Value)12240UL, Height = (UInt64Value)15840UL },
                                new PageMargin(){ Top = 1440, Right = (UInt64Value)1800UL, Bottom = 1440, Left = (UInt64Value)1800UL, Header = (UInt64Value)720UL, Footer = (UInt64Value)720UL, Gutter = (UInt64Value)0UL },
                                new Columns(){ Space = (UInt64Value)720UL },
                                new DocGrid(){ LinePitch = 360 }
                            ){ RsidR = "004E0028", RsidSect = "004E0028" }));
                return element;
            }

        }
    }

    Is it helpful?

View as RSS news feed in XML