This article describes the JSP implementation of Excel and Word document printing methods. Share to everyone for your reference, specific as follows:
Because MS Word and Excel documents support HTML text formatting, you can use Word or Excel to do the template, save as a Web page, and then change the HTML into a JSP, the data part of the dynamic fill can be, do not have to work hard to adjust the format
The word page simply sets the following instruction in the JSP header:
Copy Code code as follows:
<% @page contenttype= "APPLICATION/MSWORD;CHARSET=GBK"%>
Excel is as follows:
Copy Code code as follows:
<% @page contenttype= "APPLICATION/VND.MS-EXCEL;CHARSET=GBK"%>
In this way the client must have Office software installed and the page will be opened directly in IE with Word or Excel when the user accesses it.
This method advantage is the template design, the adjustment is convenient, does not need to use the complex poi or the JXL technology on the server side, also does not need to use the ActiveX control technology in the client, is more safe, convenient, easy to achieve the good printing effect.
Microsoft information about server-side dynamic creation of Office documents (ASP example):
http://support.microsoft.com/default.aspx?scid=kb;en-us;301044&
Simple example:
Use Word to create a document, drawing the following table:
----------------------------
| User name | Real name | sex |
----------------------------
| Guest | Passerby A | Male |
----------------------------
Save as a Web page test.htm, test.htm renamed to Test.jsp, modify the guest, passers-by a, male from the database dynamic query, as follows:
<%@ page contenttype= "APPLICATION/MSWORD;CHARSET=GBK"%> <%@ page import= "java.sql.*"%>
I hope this article will help you with JSP programming.