Using Spire.Doc Introduction

Introduction

Hi I hope you all are fine. Today we will see a new product for easily creating Office documents. Have you ever worked with any Office documents? If yes then I am sure you would encounter very problems and complex operations for loading and showing that loaded file and converting between them, like Word to PDF, PDF to Word, Word to HTML and so on. We developers may need to spend much time for these operations. Now I will introduce a new product that helps you to do it.

Please see this article in my blog: Using Spire.Doc Introduction.
 

Background

A few days ago my manager asked me to integrate a featire in my project to load an Excel file, show that file and prepare to convert it to another format. As you all know these operations are not as easy as it sounds. I began developing it. During my research I became familiar with the product (e-iceblue). Trust me, this product is simply awesome and it does the work it must.

What is explained here

Once you download the necessary file from spire-office-for-net you are ready to go. Please install the application in your system. If you want, you can add the controls to your Visual Studio tool box during installation. Or you can manually load those. We will explain basics of the Spire Doc for .Net. I hope you will enjoy reading.

Starting

We will start with a “Hello World” program. Before getting started, please install Spire.Doc and Visual Studio 2008 or above. I am using Visual Studio 2015 RC. I hope everything is set.

Open your Visual Studio, click on "File" -> "New" -> "Project..." then select Visual C# (if you are good in C# or select Visual Basic) then select Project -> Windows -> Windows Forms Application then name your project (I am naming it IntroSpireDoc).

 

Right-click on your project and click Add reference. In the browse tab determine the folder in which you have installed Spire Doc. Usually it will be in the C:\Program Files\e-iceblue\Spire.Doc. Now just find your framework version from the BIN folder and add Spire.Doc.dll.

 
 
 

Cool! Now you are ready to go.

Create a button in the form and in the button click event we will start our coding part deal.

Before that please do not forget to load the references as in the following:

  1. using Spire.Doc;  
  2. using Spire.Doc.Documents;  

Now please add the following code to the button click event:

  1. //Create word document  
  2. Document document = new Document();  
  3. //Create word document  
  4. Paragraph paragraph = document.AddSection().AddParagraph();  
  5. //Append Text  
  6. paragraph.AppendText("Hello World!");  
  7. //Save doc file.  
  8. document.SaveToFile("Sample.doc", FileFormat.Doc);  
  9. //Launching the MS Word file.  
  10. try  
  11. {  
  12.    System.Diagnostics.Process.Start("Sample.doc");  
  13. }  
  14. catch { }  

As you see in the preceding code, it is so simple, right? We have done the following processes by the preceding mentioned few:

  • Create Word document
  • Create Word document
  • Append Text
  • Save doc file
  • Launching the Microsoft Word file

    So we have done it. Now we will run our program and see the output. Are you ready?

    Output

     
     
     

    Conclusion

    I hope you liked this article. Please share your valuable suggestions and feedback with me.

    Kindest Regards,
    Sibeesh Venu

  • X

    Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

    Start Learning Now