Aspose. word easy to use, aspose. word easy to use

Source: Internet
Author: User

Aspose. word easy to use, aspose. word easy to use

Concepts

To generate a word report using aspose:

Load Template

Provides four overload Methods

?
12345 public Document();public Document(Stream stream);public Document(string fileName);public Document(Stream stream, LoadOptions loadOptions);public Document(string fileName, LoadOptions loadOptions);
Template Creation

Aspose uses a domain (MergeField) in the word template. A domain is equivalent to a placeholder. Domain, you can choose from menu Insert> document parts.

Data Filling

There are two cases: basic information and list.

Basic information: basic attributes. The list corresponds to the cyclic data structure, such as DataTable.

Use DataTable to fill the list.

Template creation:

The table starts with the keyword TableStart and ends with TableEnd. Add the DataTable table name after the keyword. E.g. TableStart: tableName

In the middle of the header, It is the name of a specific field.

Serial number Name Gender Age
<TableStart: Name> <Index> <Name> <Sex> <Age> <TableEnd: Name>
Document doc = new Document(Server.MapPath("~\\templet") + "\\" + name);doc.MailMerge.ExecuteWithRegions(DataTable)
Specific fields

There are two ways to achieve this:

Method 1,

?
123 DocumentBuilder builder = new DocumentBuilder(doc);builder.MoveToMergeField(MergeFiled Name);builder.Write(value;

In this way, one data is filled at a time. However, a field can be used multiple times and can be filled at a time.

Advantages: flexible customization. If you want to replace multiple domain fields at a time, you can do the same with a slight change.

DocumentBuilder builder = new DocumentBuilder(doc);while(builder.MoveToMergeField(MergeFiled Name)){    builder.Write(value;}

Method 2,

 doc.MailMerge.Execute(fieldNames, fieldValues);

In the specific development process, Entity is usually selected as the data source. You can obtain data through reflection.

How to obtain domain fields

?
1 doc.MailMerge.GetFieldNames()

Method returns the book string []

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.