C # export Word documents and batch export Word documents (1 ),

Source: Internet
Author: User

C # export Word documents and batch export Word documents (1 ),
Two dll files are used here, and one is aspose. word. dll, the other is ICSharpCode. sharpZipLib. dll, ICSharpCode. sharpZipLib. dll is used to export Word documents in batches. By packaging a file into a compressed package, it is output and downloaded as a file stream. Aspose. word. dll is best to use the latest version, 14.5 or higher. I use version 14.5, and the page uses the mvc syntax. Here, I would like to thank Zhao for his help. First, make the word template. using the template can avoid formatting the word in the code, which is convenient and simple. The methods of bookmarks and text fields are described respectively. (1) Click "insert"> "bookmarks" to open the Word documents. In the displayed dialog box, enter the name of the bookmarks to be added. You can define the name of the bookmarks at will, but it is best to keep the data tables consistent, in this way, the judgment is reduced in the code generation, and then click Add. Bookmarks are invisible and hidden, but they do exist. The limitations of bookmarks are that only one bookmarks in a Word document cannot have the same name. If you get a list, bookmarks can only start with a document, but cannot be prefixed with other bookmarks or fields. text fields are not limited. However, if the document contains two identical fields, this will cause the subsequent values to be overwritten. For example, if there are two 2D regions of starttime, the value of the second starttime is the value of the first starttime, instead of the values in the real data table. This is not the case in the cyclic list. Therefore, I use text fields. The related settings are as follows:
(2) open Word documents in text fields, place the cursor at the insertion point, and select "insert"> "document parts"> "domain". In the displayed dialog box, select "mail merge"> "MergeField", enter the name to be added, and the name can be defined at will, but it is best to have the same data table, so that the judgment is reduced in the code, and then click OK,. Note that Image: Must be added to define the Image domain. For example, the above bookmarks and domains obtain a single record. If there are multiple records, you need to cycle the list and fill in the data. The related settings are as follows:

  • The bookmarklist, the above number, name, and time must also be inserted into the bookmarklist. The table is the position of the List inserted in the loop at that time:
  • Domain, mainly pay attention to tablestart and tableend. The title does not need to be inserted into the domain. You only need to define the domain in the next line:

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.