A simple way to export JSP data to Excel __jsp

Source: Internet
Author: User

Try to generate Excel directly from the Web page, although not directly from SQL to Excel, but more convenient and humane.

The internet has found a lot of information, found a piece of JavaScript function to implement code, very good:
var eltable = document.getElementById ("TB");
var orangeref = Document.body.createTextRange ();
Orangeref.movetoelementtext (eltable);
Orangeref.execcommand ("Copy");

var appexcel = new ActiveXObject ("Excel.Application");
Appexcel.visible = true;
APPEXCEL.WORKBOOKS.ADD (). Worksheets.item (1). Paste ();
Appexcel = null;

The implementation function is to make the data in the table ID TB into Excel, I tried a feasible, but put to the server to run is the script error prompts, and then ask around the Internet, but also to find some of the Baidu space master friend asked, but still not its law. But thank you very much for their kind help.

No way, I can only use other methods to achieve, in fact, like the above JavaScript function, more humane. Unfortunately, I am at my wits ' wit, can't use it, eh. ~

Since I help the client use JSP to write the program, then I will use JSP to achieve this function bar.

So I found a way to do this:
Original: http://www.jsp.mlc.edu.tw/viewitem.jsp?itemid=0000000065

***************************************************************************************************
First, the Web page data in Excel report to the online browsing method presented
Xls651.jsp The original code is as follows


<%@ page contenttype= "Application/msexcel"%>
<!--above this line to set this page for Excel format pages-->
<%
Response.setheader ("content-disposition", "inline; Filename=test1.xls");
The above line sets the filename to Test1.xls when it is passed to the front-end browser.
This is the line that allows the front-end browser to assume that an Excel file is received
%>
<title>excel File Presentation Mode </title>
<body>
<table border= "1" width= "100%" >
<tr>
<td> name </td><td> ID card size </td><td> birthday </td>
</tr>
<tr>
<td> Coco </td><td>N111111111</td><td>1900/11/12</td>
</tr>
<tr>
<td> Liang </td><td>N222222222</td><td>1923/10/1</td>
</tr>
<tr>
<td> Sherry </td><td>N333333333</td><td>1934/12/18</td>
</tr>
</table>
</body>

Second, the Web page information in the form of Excel report presented
This JSP file is similar to the previous one, only the difference is in this line:
Online Browsing mode: Response.setheader ("content-disposition", "inline; Filename=test1.xls");
Download the way: Response.setheader ("Content-disposition", "attachment; Filename=test2.xls");
Note: 1. The above purely static Web page rendering Excel file, with the database, you will be able to dynamic report form to make Excel report
2. Do not install any components, or only limited to the win platform, a simple way to solve your report requirements
3. Smart you, should be able to extrapolate, know how to the Web page information in Word doc format to show it.
(is not as long as the contenttype changed to "Application/msword" and filename of the secondary file name changed to. doc on it. )

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.