[Original]java Read and write Word document, perfect solution

Source: Internet
Author: User

In the process of doing the project, often need to read the data in the data, after processing, in Word format output. Find a lot of solutions on the Internet is not ideal, occasionally found Pageoffice, a domestic office plug-in, development calls very simple! More than the online introduction of Poi,jacob and other solutions to easy to get started! The functional interface is not as poi,jacob as it is, but it satisfies 80% or 90% of the general requirements and does not need to differentiate between the 07 format and the 03 format, as is the case with POI.

The following is the introduction of Baidu Encyclopedia Pageoffice:

Https://baike.baidu.com/item/PageOffice/2737741?fr=aladdin

The basic features of Pageoffice include:

Open, edit, print preview, print Office documents in Word, Excel, PowerPoint, and more in a Web page.
Document concurrency control mechanism.
Provide the necessary functions of the OA document module such as word revision marks, handwritten annotations, redlining, keyboard annotations, electronic stamps, etc.
Dynamically populate data, including text, pictures, tables, and so on, from a database, export to a location specified in Word, Excel templates, and dynamically specify the various formats of the content.
Extracts the content at the specified location in Word and Excel documents, including text, pictures (not supported by Excel), tables, and so on, to the database.
Other features will not be discussed in detail ...

More interface instructions refer to Pageoffice official website api:http://www.zhuozhengsoft.com/help/java3/index.html

: http://www.zhuozhengsoft.com/dowm/

After downloading the Pageoffice development Kit, copy the Samples4 folder to the Tomcat Webapps directory and visit: http://localhost:8080/Samples4/index.html will see a list of all the official sample effects. Here are a few examples of key points to consider:

One, 11, a simple example of assigning a value to a data region (dataregion) in a Word document
One, 17, a simple example of assigning a value to a table in a Word document
One, 18, use data labels (datatag) to fill Word files with text data
Second, 6, background programming insert Word file into data region
Second, 7, background programming insert picture to data area
Second, 8, background programming insert Excel file into data region
Two, 9, add a watermark to a Word document
Second, 10, using data labels (datatag) to fill the Word file with formatted data
Two, 11, dynamic creation of data regions in Word

We can write a simple program to test the effect:

Pageofficectrl POCTRL1 =NewPageofficectrl (Request); Poctrl1.setserverpage (Request.getcontextpath ()+ "/poserver.zz"); Worddocument WordDoc=Newworddocument (); //To insert a bookmark manually in the location where you want to insert the Word file, the bookmark must be prefixed with "Po_"//assigns a value to DataRegion, in the form of: "Plain text content, [word]word file path [/word], [image] picture path [/image]"DataRegion data1 = worddoc.opendataregion ("Po_p1"); Data1.setvalue ("Test string");//Plain Text contentDataRegion data2 = worddoc.opendataregion ("Po_p2"); Data2.setvalue ("[Word]doc/2.doc[/word]");//Insert Word fileDataRegion data3 = worddoc.opendataregion ("Po_p3"); Data3.setvalue ("[Image]doc/1.jpg[/image]");//Insert Picture//Open file, populate dataPoctrl1.setwriter (WordDoc); Poctrl1.webopen ("Doc/template.doc", Openmodetype.docnormaledit, "user name");

The code is simple. Just a few words to complete the insertion of text, pictures, sub-word file Features! However, to do the project, you can first define the good one Word template, which is conducive to typesetting, reduce the workload of writing code, you can also call the interface provided by Pageoffice to control the style of data area in the template, but the coding effort is increased. Its function is far more than these, according to specific needs to deal with it.

[Original]java Read and write Word document, perfect solution

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.