Get the value of the page text box. Generate word document with page Office

Requirement: fill in a text in the text box of the web page, and then export a word document, which is red, small, song and so on.

Step one:

Download the complete trial package on Zhuozheng's official website. http://www.zhuozhengsoft.com/dowm/

The second step:

Copy the jar package under lib and copy the code in the web.xml file

The third step:

Page form form form

<form id="formid" action="day1/Word.jsp" method="post">
    //Full name:
    <input type="text" name="username" id="username"/>
    <br>
    <br>
    //Age:
    <input type="text" name="age" id="age"/>
    <br>
    <br>
    //Mobile phone:
    <input type="text" name="phoneNum" id="phoneNum"/>
    <br>
    <br>
    <input type="submit" value="open" />
</form>

The fourth step:

Set the area specified in the word file (bookmarks in word, called data area in page office)

Step 5: word.jsp page

<%@ page language="java"
    import="java.util.*,com.zhuozhengsoft.pageoffice.*,com.zhuozhengsoft.pageoffice.wordwriter.*"
    pageEncoding="UTF-8"%>
<%@page import="java.awt.Color"%>
<%
    String name = (String) request.getParameter("username");
    String age = (String) request.getParameter("age");
    String phoneNum = (String) request.getParameter("phoneNum");

    PageOfficeCtrl poCtrl = new PageOfficeCtrl(request);
    //Setting up server pages
    poCtrl.setServerPage(request.getContextPath() + "/poserver.zz");
    //Add custom buttons
    poCtrl.addCustomToolButton("Preservation", "Save", 1);
    //Set up save page
    poCtrl.setSaveFilePage("SaveFile.jsp");

    WordDocument worddoc = new WordDocument();
    //Data area assignment
    DataRegion data1 = worddoc.openDataRegion("PO_name");
    data1.setValue(name);

    //Setting font style
    Font font = data1.getFont();
    //Set red
    font.setColor(Color.red);
    //Setting thickening
    font.setBold(true);
    //Set font
    font.setNameAscii("Song style");
    //Set font size
    font.setSize(14);
    //Set Underlines
    font.setUnderline(WdUnderline.wdUnderlineDash);

    DataRegion data2 = worddoc.openDataRegion("PO_age");
    data2.setValue(age);
    DataRegion data3 = worddoc.openDataRegion("PO_phoneNum");
    data3.setValue(phoneNum);

    poCtrl.setWriter(worddoc);
    //Open Word Document
    poCtrl.webOpen("doc/test.doc", OpenModeType.docNormalEdit, "Zhang Yi Ming");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
    </head>
    <body>
        <div style="height: 850px; width: 1036px; overflow: hidden;">
            <%=poCtrl.getHtmlCode("PageOfficeCtrl1")%>
        </div>
    </body>
</html>

Final effect

Tags: Front-end JSP Java xml Mobile

Posted on Mon, 07 Oct 2019 02:32:29 -0400 by b2k