Original Java assigns a value to a table in Word

Source: Internet
Author: User

First, the preparatory work:

Download Pageoffice for java:http://www.zhuozhengsoft.com/dowm/

Second, the realization method:

To invoke Pageoffice operations on a table in Word, you must do so with the data region (DataRegion) (because the table in Word has index only, no name), and the data region is required to contain the entire table content. This allows you to control and manipulate the table through the data region. In addition, table inserts can be inserted manually in the Word Template: the toolbar "insert" → "table", and can be dynamically added through the data region in the program.

  If you do not understand what "data region" is, visit: http://www.zhuozhengsoft.com/PageOffice/course/2017/0719/276.html

  1. Edit the Word template. For example, if you have a person information table in your Word document that you want to populate with data in this person information table, you must first insert the table for the entire table into a bookmark: po_regtable. Be sure to select the entire table when inserting bookmarks.


  

2. Write code to populate table

Pageofficectrl POCTRL1 =NewPageofficectrl (Request); Poctrl1.setserverpage (Request.getcontextpath ()+ "/poserver.zz"); //OperationTableWorddocument doc =Newworddocument (); DataRegion DataRegion= Doc.opendataregion ("po_regtable"); //the index in the Open Table,opentable (Index) method represents the indexed table position in the current bookmark, starting with 1Table table = dataregion.opentable (1); //assigns a value to a cell in a table, the parameters in OPENCELLRC (Int,int) represent the first row, the first column, starting with 1TABLE.OPENCELLRC (3, 1). SetValue ("Company A")); TABLE.OPENCELLRC (3, 2). SetValue ("Development Department"); TABLE.OPENCELLRC (3, 3). SetValue ("Liqingfeng");    //Insert a row, the parameter in the Insertrowafter method represents the cell below which a blank line is insertedTable.insertrowafter (TABLE.OPENCELLRC (3, 3)); TABLE.OPENCELLRC (4, 1). SetValue ("Company B")); TABLE.OPENCELLRC (4, 2). SetValue ("Sales Department"); TABLE.OPENCELLRC (4, 3). SetValue ("Zhang San");    Poctrl1.setwriter (DOC); //Open FilePoctrl1.webopen ("Doc/test.doc", Openmodetype.docnormaledit, "user name");

3. Effects of generating files

  

Three, sample code

Unzip the downloaded Pageoffice for Java development Package, copy the Samples4 folder to the Tomcat WebApps directory, Access: http://localhost:8080/Samples4/index.html

Refer to Samples4: One, 17, a simple example (wordsettable) that assigns a value to a table in a Word document.

Original Java assigns a value to a table in Word

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.