[Original] java merge word file

demand background

  In the Internet education industry, a problem often encountered in content-related projects is how to dynamically generate a word test paper. Each test question in the question bank has been saved as an independent word file in advance, but when you select some test questions to generate a word test paper, if you cannot merge the selected word test file through the java program, then The word content can only be merged by manual input and copy, which is inefficient, and the labor cost and input error rate are high.

Difficulty

  The difficulties that need to be faced in using POI to realize word merging mainly include the following aspects:

  • Word structure problem - Word is not open source, and contains a lot of non-text content, such as charts and pictures, and known conventional methods can only parse plain text content, so if you don't know the internal hierarchical structure of word, parsing will be difficult.
  • Word version problem - At present, word has two document formats, docx and doc. Are all parsing compatible? Provided, of course, that a type has been successfully resolved.
  • Word specification issues - some words may have been made early, and rework is too expensive, so the format content is diverse. And even if the word format specification is formulated, the newly produced word cannot be guaranteed to be in the correct format.

  The problems to be faced when using Jacob to implement word document merging:

  • The server must be a Windows operating system - the reason why most web projects are developed in Java is because the server can be a non-Windows system such as Linux and Unix to reduce the cost of the project.
  • Office must be installed on the server - Jacob means: Java COM Bridge, Java calls the com interface provided by office to realize the operation of Office files.
  • Concurrency problem - If multiple users are generating word files at the same time, they must deal with this concurrency problem. A little carelessness will cause Office dead processes on the server side, deadlocking the server's memory resources.

solution

  After researching the problem for a period of time, the progress is slow, the mountains and rivers are full of doubts, and there are still dark flowers and bright villages, and then I found that PageOffice provides a solution to this problem, and there is a related demonstration in the sample program of PageOffice, but PageOffice In the demo example, the word file is saved in the database in the form of a binary stream, and you only need to save the word file in the form of a disk file in your own project.

  Download address: http://www.zhuozhengsoft.com/dowm/ Visit this address to download the development kit of PageOffice for Java, copy the unzipped Samples4 folder to the Webapps directory of Tomcat, and visit: http://localhost:8080/ Samples4/index.html, view the comprehensive demo: 3. 2. Dynamically generate a test paper in a Word document

  

  

  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325521884&siteId=291194637