1. Overview
The recent project has one such requirement: Export Word documents, require that the format of the document is not fixed, users can easily adjust the data table columns in the export content is dynamic, for example, to export the name and gender, you need to export the two columns of data, And this document is not exported after the adjustment but after the guidance has been adjusted. See here, you may immediately think of using template export! And. NET with this component: Microsoft.Office.Interop.Word, you can meet the demand. However, this component is also limited, such as the client must install Office components, and high coding complexity. The most troublesome requirement is the----Dynamic table column header in the back! The following is a description of how to use the aspose.words for. NET to dynamically generate a table of data in a Word document.
2, the text
Aspose.words, is one of the Aspose "Family Class library". In addition to this, there are many other powerful class libraries such as Aspose.pdf (Operation PDF file class library), Aspose.flash (operation of the Flash File class library), Aspose.report (operation of the report of the class library) and so on, you can be interested in the official web research. These class libraries all contain two languages, one is Java, the other is. NET. This is mainly about aspose.words for. Net. Aspose.words for. NET is very powerful, you don't need to install Office components, you can use this to build Word documents. Aspose.words supports DOC,DOCX,OOXML,RTF format, HTML format, OpenDocument format, PDF format, and other formats. From the figure below, you can learn more about the Aspose.words architecture. A little forgot to mention, this set of class library is charged, in this article I will provide a crack version of the download address to everyone.
Before describing how to dynamically generate a table, let's look at how this class library generates values based on the template:
First, let's build a Word template: Template.doc. Create a bookmark in the document where you want the data to be generated, as shown in figure: