Creating Word document in Silverlight

Creating a Word document programatically is a frequent client requirement. In Silverlight, if you are creating Out-Of-Browser application, you have option to use Office Interop. But if you need to create a Word, Excel or PDF report in Silverlight browser application, Spire Suits can help you. Though it is not free, but you can download its free evaluation version from http://www.e-iceblue.com/Introduce/word-for-net-introduce.html. Evaluation version leaves a warning message on top of document. To remove the warning message you have to buy a license.

Download Spire, Install it, Add DLL reference in your Silverlight project (DLLs are found in installation folder, usually c:\program files\) and use following code to get started. Detail documentation can be found on Spire. website.


        //Add References
        using Spire.Doc;
        using Spire;
        using System.IO;
        private void btnDownload_Click(object sender, RoutedEventArgs e)
        {
            Stream st = null;
            //Create word document
            Document document = new Document();
            //Create a new secition
            Spire.Doc.Section section =null;
            SaveFileDialog dlg = new SaveFileDialog();
            dlg.Filter = "Word files (*.doc)|*.doc";
            dlg.ShowDialog();
            st=  dlg.OpenFile();
            //Create a new secition
            section=document.AddSection();

            //Create a new paragraph
            Spire.Doc.Documents.Paragraph Heading = section.AddParagraph();

            //Create Header
            Heading.AppendText("Prady Blog - http://www.pradyblog.com");
            Heading.ApplyStyle(Spire.Doc.Documents.BuiltinStyle.Heading1);

            //Save doc file.
            document.SaveToFile(st, FileFormat.Doc);
            st.Close();

        }
This entry was posted in Silverlight. Bookmark the permalink.

5 Responses to Creating Word document in Silverlight

  1. Pretty interesting information !Perfect just what I was looking for!

  2. ErichBerg says:

    This was some interesting stuff. Posting to facebook

  3. I was suggested this web site by way of my cousin. I am now not positive whether this put up is written by way of him as nobody else know such distinctive about my problem. You’re amazing! Thank you!

  4. magnificent points altogether, you simply received a new reader. What would you recommend in regards to your submit that you simply made some days ago? Any sure?

  5. Thanks for the share!
    Hellen

Leave a Reply