How to Use Spire. Office for. NET (Word, Excel, PPT, PDF, etc.)

Source: Internet
Author: User
Tags watermark images


Preface

Most of the content in this article is from http://www.codeproject.com/articles/742547/first-thoughts-on-spire-doc-for-net.

For me, there is little need for office automation. But as a developer, it is best to have a library tool if needed. Some time ago, one of E-iceblue's sales staff contacted me and hoped that I could help them perform a Assessment for Spire. Office. First of all, I am very glad that they can find me. This also gives me a chance to get in touch with and learn new technologies. I am very grateful to E-iceblue's employee here. Their official website is http://www.e-iceblue.com /.

Spire. Office for. NET is a compiled enterprise-level Office. NET component provided by E-iceblue. It contains Spire. doc, Spire XMLS, Spire. presentation, Spire. PDF, Spire. dataExport, Spire. PDFViewer, Spire. docViewer, and Spire. barCode. spire. the Office includes. the latest version of the. Net component.

With Spire. Office for. NET, developers can create more extensive applications. It enables developers to open, create, modify, convert, print, and view Microsoft Word, Excel, PowerPoint, and PDF documents. In addition, it allows users to export data to popular files, such as MS Word/Excel/RTF/Access, PowerPoint, PDF, XPS, HTML, XML, Text, CSV, DBF, clipboard, SYLK, etc.

The most independent Office. NET Component, Spire. Office does not need to install Microsoft Office files on the system. In addition, it can better replace Microsoft Office Automation in terms of security, stability, scalability, speed, price, and function.

Spire. office. NET can be linked to any type of 32-bit or 64-bit.. NET application, which includes. NET Framework 2.0 to 4.5 versions of Asp.. NET, Web Services, WinForms, and other applications.

Next, I will briefly introduce Spire. Doc and Spire. PDF. Let's take a look at my usage.

Spire. Doc for. NET

Spire. doc. NET is a professional Word.. NET library, developers can use this tool in any. NET platform (C #, VB. NET, ASP.. NET. As an independent Word component, Spire. Doc for. NET does not require Microsoft Word to be installed on your machine. In addition, it can integrate the Microsoft Word document creation function into any developer's. NET application.

How to get it?

First you can go to the official website http://www.e-iceblue.com/


Then you can click on the components you need, for example, the Spire. Doc for. NET that I need now. After entering, you can download and finally purchase Spire. Doc from their website.

After the download, you will find that it is an MSI Installation File.

The Spire. Doc installation package is clean and professional MSI installation program. The first few dialog boxes contain prompts and license agreement. By the way, who will read all the warning information carefully? However, if you are a company preparing to invest in and use the product for commercial purposes, read the license agreement of any software company.


The Spire. Dco package only uses MB space.


The MSI installation options provide comprehensive information, including:

1. install components (multiple components of different. NET Framework versions are supported)

2. install demo and source code

3. Install the file on the local machine of the developer.

4. Add the component to the reference dialog box of Visual Studio.

After the installation is complete, the developer must manually add the referenced assembly. Here, you can install the file locally with the help of Windows HTML.



 

Create a Word document

A problem we faced many years ago was to find an effective way to insert formatted text into a document. Specifically, it is to generate a multi-paragraph, multi-text file with a special format of Word documents.

Let's use Spire. Doc to create a familiar word document to write Hello World. The procedure is as follows:

1. I used VS2012 to create a console application.


2. In Solution Explorer, add a new reference to Spire. Doc. dll (in the bin path after MSI is installed)


3. I want to see if the naming convention of Spiral. Doc is consistent with my intuition. So I started to check their documents and use the object browser to check available interfaces. According to my guess, I think the following code can help me build the Word text I want.

Static void Main(string[] args)
         {
             Spire.Doc.Document document = new Document();
             Section section = document.AddSection();
             Paragraph paragraph = section.AddParagraph();
             paragraph.AppendText("Hello World");
             document.SaveToFile("Hello Wrold.doc", FileFormat.Doc);
             Console.WriteLine("Word document created successfully!");
             Console.ReadLine();
         }

After compilation is successful, F5 runs



If you have a license, the Evaluation information (Evaluation Warning) will disappear.

4. Although we are very busy, let's see if it can export Word documents as PDF or HTML.

Spire.Doc.Document document = new Document();
             Section section = document.AddSection();
             Paragraph paragraph = section.AddParagraph();
             paragraph.AppendText("Hello World");
             document.SaveToFile("Hello Wrold.doc", FileFormat.Doc);
             document.SaveToFile("Hello World.pdf", FileFormat.PDF);
             Console.WriteLine("Word document created successfully!");
             Console.ReadLine(); 

The world spelling is wrong, haha. I will not modify it after I mention it.


Here is a PDF file opened through a browser.

Well, it's good. I just use a single line of code. I can convert it. My Word documents are saved in PDF format. It is very convenient for our developers to convert Word to PDF almost every day. From my personal experience, this is one of the hottest questions on the Forum every day.

5. This is one of the simplest examples, but you can also use stream to read HTML to create Word documents, insert html files, format files, or add any metadata attributes to Word documents.

Supported file formats

Spire. PDF for. NET

Spire. PDF for. NET is a professional PDF document creation component developed by e-iceblue. It allows users to read, write, and manipulate PDF documents using. NET applications without using Adobe Acrobat and other external controls. Spire. PDF for. NET can be used not only on the server, such as ASP. NET or other environments, but also in Windows Forms applications. Spire. PDF. NET is suitable for all common bad environments. For example, a created PDF file can be saved to a disk, Windows Forms applications, ASP.. NET application client browser.

Spire. PDF for. NET features are abundant. In addition to basic functions such as drawing multiple types of images, creating form fields, inserting headers and footers, inputting data tables, and automatically paging large tables, Spire. PDF. NET also supports PDF digital signatures, converts HTML to PDF format, extracts text information and images in PDF documents, and saves them as text and various image formats, you can even extract attachments from PDF files.

Main functions
1. Supports embedded fonts, Truetype fonts, and CJK fonts.

2. drawing is supported. For example, a rectangle, a ring, an arc, or an elliptical shape can be filled with a custom brush.

3. You can load images from data streams and disk files to PDF files. In the PDF document, you can draw ladder images and vector images, as well as masks and watermark images.

4. data tables can be loaded in PDF documents. You can set the format of rows and columns in a table, and add graphic elements to the table.

5. Automatic paging of large tables in PDF.

6. Create a form field. For example, you can create buttons, text boxes, list boxes, and check boxes in a PDF file.

7. Insert the header and footer in the PDF file.

8. encrypt the PDF document by setting the owner password and user password.

9. Use the author's signature to protect PDF documents.

10. Read the table of the current PDF document and fill the table.

11. HTML pages are split into multiple large pages when being converted to a PDF document. These pages can be displayed in the original PDF document, in addition, there is no text Truncation on the page of the PDF document. Users can also directly convert these webpages into data streams without temporary files to create PDF documents.

12.

 

Let's create a PDF file.

1. Create another console application project


2. Add the Spire. PDF reference. This time I add it through the Nuget plug-in.


Below is a simple PDF code.

Class Program {static void Main (string [] args) {// 1. Create a PDF Document using Document doc = new using Document (); PdfUnitConvertor unitCvtr = new PdfUnitConvertor (); when margins margin = new when margins (); margin. top = unitCvtr. convertUnits (2.54f, PdfGraphicsUnit. centimeter, PdfGraphicsUnit. point); margin. bottom = margin. top; margin. left = unitCvtr. convertUnits (3.17f, PdfGraphicsUnit. centimeter, PdfGraphicsUnit. point); margin. right = margin. left; // 2. Create a margin for the Page PdfPageBase page of the PDF defined above = doc. pages. add (PdfPageSize. a4, margin); // 3. Insert a background image System. drawing. image img = System. drawing. image. fromFile (@ "1.png"); page. backgroundImage = img; /// 4. Add the watermark PdfTilingBrush brush = new PdfTilingBrush (new SizeF (page. canvas. clientSize. width/2, page. canvas. clientSize. height/3); brush. graphics. setTransparency (0.3f); brush. graphics. save (); brush. graphics. translateTransform (brush. size. width/2, brush. size. height/2); brush. graphics. rotateTransform (-45); brush. graphics. drawString ("www.cnblogs.com/aehyok", new PdfFont (PdfFontFamily. helvetica, 24), hybrid brushes. viotlet, 0, 0, new inclustringformat (effectextalignment. center); brush. graphics. restore (); brush. graphics. setTransparency (1); page. canvas. drawRectangle (brush, new RectangleF (new PointF (0, 0), page. canvas. clientSize); float y = 10; // 5. Set the title to required brush brush1 = required brushes. black; required truetypefont font1 = new required truetypefont (new Font ("Arial", 16f, FontStyle. bold); required stringformat format1 = new required stringformat (required textalignment. center); page. canvas. drawString ("Country List", font1, brush1, page. canvas. clientSize. width/2, y, format1); y = y + font1.MeasureString ("Country List", format1 ). height; y = y + 5; // 6. Define the Table metadata String [] data = {"Name; Capital; Continent; Area; Population", "Argentina; buenoch; South America; 2777815; 32300003 "," Bolivia; La Paz; South America; 1098575; 7300000 "," Brazil; Brasilia; South America; 8511196; 150400000 ", "Canada; Ottawa; North America; 9976147; 26500000" ,}; String [] [] dataSource = new String [data. length] []; for (int I = 0; I <data. length; I ++) {dataSource [I] = data [I]. split (';');} // 7. Bind data PdfTable Table = new PdfTable (); table. style. cellPadding = 2; table. style. headerSource = Your HeaderSource. rows; table. style. headerRowCount = 1; table. style. showHeader = true; table. dataSource = dataSource; // directly bind the data source PdfLayoutResult result = table. draw (page, new PointF (0, y); y = y + result. bounds. height + 5; required brush brush2 = required brushes. gray; trusted truetypefont font2 = new trusted truetypefont (new Font ("Arial", 9f); page. canvas. drawString (String. format ("* {0} countries in the list. ", data. length-1), font2, brush2, 5, y); // 8. Save the file doc. saveToFile ("simpletableexample"); doc. close (); // 9. open the file System. diagnostics. process. start ("SimpleTable.pdf ");}}View Code

After running


Several simple elements can be found.

1. Background Image

2. Add a watermark

3. Table

 

 

In general, I was impressed by the features and ease of use provided by this product. Although it doesn't always do what I want, it may be because I don't know how the Spire. Office component works correctly.

 

Tips for English

1. SUSAN: Excuse me! I am new to the campus. Do you know where the student cafeteria is? -- Excuse me. I'm a freshman. Do you know where the cafeteria is?

2. KATHY: Sure! Do you have a map? -- Of course! Do you have a map?

3. Susan: Yes, here it is. -- Yes. The map is here.

4. KATHY: Let's see -- Here's where we are right now. to get to the cafeteria, you'll need to cross this square and go to the south. -- let's see -- we are here. to go to the cafeteria. you have to pass through this square and go south.

5. SUSAN: OK -- OK.

6. KATHY: And then the cafeteria is about five hundred yards past the gym, on your left. you'll see a sign in front of the building. -- The cafeteria is about 500 yards away from the gymnasium. on your left. you will see a sign in front of the building.

7. SUSAN: No wonder I got lost. I was heading in the wrong ction! Anyway, thanks a lot for your help. -- no wonder I will be lost. I am in the wrong direction. In any case. Thank you very much for your help.

8. KATHY: No problem. Good luck! -- You're welcome. Good luck.

Author: aehyok

Source: http://www.cnblogs.com/aehyok/

Thank you for reading this article. If you are interested in the content described in my blog, please make a suggestion. Thank you for your support:-O.

Sample Code http://url.cn/S7Znij


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.