Demand Scenarios
Developing a Web Office system if you need to work with a large number of Word documents (such as thousands of documents), users must ask for a document that contains some keywords, which requires the ability to read text in Word, ignoring text styles, tables, pictures, and so on.
Scenario Analysis
Scenario One: Use Apache POI technology to store the text of documents on all servers in the database, and find documents using SQL statements to retrieve document text stored in the data containing keywords to search for related documents. However, Microsoft Word now has two document formats, Doc and docx, and there are considerable differences in the format in which the two versions store data. The research found that Apache POI provides two different API interfaces for Doc and docx, requiring different code for both document formats, a complex format for Word documents, and code that reads the contents of Word documents, which can cause pressure on the server. And it is not possible to allow users to work with Word documents online.
POI Home Address: https://poi.apache.org/
Scenario Two: Use the Getdocumenttext method of the Filesaver object of the Pageoffice component to get plain text content in a Word document, and if you call Pageoffice to implement this functionality, you can also implement online editing of the Word file.
Implementation steps
1. Call Pageoffice to open Word file online, for example: Test.doc
Pageofficectrl poctrl=new Pageofficectrl (request);//Set Server Page Poctrl.setserverpage (request.getcontextpath () + "/ Poserver.zz ");//Set save page to savefile.jsp, or savefile.do savefile.action The action method or Requestmapping method can be Poctrl.setsavefilepage ("savefile.jsp");//Open Word document Poctrl.webopen ("Doc/test.doc", Openmodetype.docnormaledit, "Tom");
2. Perform the save file and get the plain text content in the document in the page (savefile.jsp) or method that handles the save operation:
Filesaver fs=new Filesaver (request,response); Fs.savetofile (Request.getsession (). Getservletcontext (). GetRealPath ( "doc/") + "/" +fs.getfilename ());//save file string strdocumenttext = Fs.getdocumenttext ();//Get the plain text content of the document without any additional formatting//-Write code, Save the text content of the document to the database-//......fs.close ();
3. When a full-text search is required, simply make a SQL query for the database field that holds the plain-content of the Word file in the database.
[Reprint]java get the text inside word