java web for online editing word, and the word is derived (a)

  Some time ago a leader confessed requirements: client needed a web online editing text, edit word documents as the same, while being able to edit the content of the export is complete word document and downloaded to the local.

  We chose the form of future use of plug-ins for editing rich text content, using UEditor (official website: http://ueditor.baidu.com/website/ ), the plug-in is similar to writing articles for the blog garden reception function function using the source code of the plug-in version of jsp (Download: http://ueditor.baidu.com/build/build_down.php?n=ueditor&v=1_4_3_3-utf8-jsp ).

  Examples editor, and passes the content data word background (html form) displayed in the editing area.

var ue = UE.getEditor('editor',{
            toolbars: [
                ['undo', 'redo', 'bold','italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|' ,
                    'rowspacingtop', 'rowspacingbottom', 'lineheight', '|', 'directionalityltr', 'directionalityrtl', 'indent', '|',
                    'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
                    'simpleupload', 'insertimage', 'link', 'unlink', '|', 'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|', 'imagenone', 'imageleft', 'imageright ',' ImageCenter ',' | ' , 
                    , ' Horizontal ',' DATE ',' Time ',' spechars', '|', 'preview', 'searchreplace', 'Print' ] 
            ], 
        }); 


UE. READY ( function () {
     // content html tag content, accompanied by css style 
      ue.setContent (content, to true ) 
});

  These are the simple realization the front desk, this plug even can be directly pasted pictures!

  The background is the realization of ideas: As reception allows online editing, all can not generate a report document directly in the background, content needs to be fully transmitted to the front display background, there is the code behind the front desk html interface converts into a word document.

  I have a background in project implementation Two herein, this presentation first before an implementation, another way to be introduced next.

  Doc generated in this way is a suffix of the document is Word2003 previous word document specification.

    @RequestMapping("/defectV2/defect/analysis/tranformHtmlToWord")
    @ResponseBody
    public MessageBean tranformHtmlToWordDocx(@RequestParam Map params,HttpServletRequest request, HttpServletResponse response) {
        try {
//params包含前台传回的html内容
// analysisService.tranformHtmlToWordDoc(params,response); String content = "<html><head></head><body>" + (String) params.get("editorValue") + "</body></html>"; InputStream is = new ByteArrayInputStream(content.getBytes());//utf-8 // OutputStream os = new FileOutputStream("F:/analysis/test.doc"); OutputStream os = response.getOutputStream(); response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode("问题统计分析.doc","utf-8")); POIFSFileSystem fs = new POIFSFileSystem(); fs.createDocument(is, "WordDocument"); fs.writeFilesystem(os); os.close(); is.close(); fs.close(); return new MessageBean("success", "生成报告成功!", null); } the catch (Exception E) { e.printStackTrace (); utils.WriteSystemLog (SLS, "ERROR", "Generate Report", "Failed to generate report!" + e.getCause ()); return new new MessageBean ( "error", " failed to generate report ",! null ); } }

  In this way the direct use of POI attendant functions, in pom.xml need to introduce relevant dependent POI.

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.14</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.14</version>
        </dependency>       
 

Guess you like

Origin www.cnblogs.com/guaniu2750/p/12201554.html