Export data from a JSP page to an Excel table

Source: Internet
Author: User
Tags visibility
Export data from JSP page to Excel table, this content is for reference only. (The "Graduate Information Inquiry" project written during the junior year training)

1. Generate Excel template

1) Create a new Excel file (template.xls) by yourself, enter a record, and then set the font style. As shown in the figure:

    Export data from Jsp page to Excel table

2) Save the Excel file as a web page ("File" —> "Save as web page")

     Export data from Jsp page to Excel table

3) Use Notepad or UE to open the template .htm, you can see the source code (the source file is relatively long and is omitted here)

 

2. Generate a Jsp page and make a little modification

 

note:

1) The green code needs to be written by yourself, in which you need to modify the contentType attribute to application/vnd.ms-excel, and the encoding method to gb2312 to prevent garbled codes)

2) The red code should be written according to your own needs, such as which classes to import and what content to output

3) The rest of the code is the source code of the copied template .htm, in which the yellow code needs to be modified (add "" or ’’ to some of the attribute values)

 

ExportToExcel.Jsp:

<%@ page language="java" contentType="application/vnd.ms-excel; charset=gb2312" pageEncoding="gb2312"%>

      

<%@page import="com.gsms.dao.*"%>

<%@page import="com.gsms.dao.impl.*"%>

<%@page import="com.gsms.domain.Student"%>

<%@page import="java.util.List"%>

 

 

 

<html xmlns:o="urn:schemas-microsoft-com:office:office"

      xmlns:x="urn:schemas-microsoft-com:office:excel"

      xmlns="http://www.w3.org/TR/REC-html40">

 

    <head>

       <meta http-equiv="Content-Type" content="text/html; charset=gb2312">

       <meta name="ProgId" content="Excel.Sheet">

       <meta name="Generator" content="Microsoft Excel 11">

       <link rel="File-List" href="template.files/filelist.xml">

       <link rel="Edit-Time-Data" href="template.files/editdata.mso">

       <link rel="OLE-Object-Data" href="template.files/oledata.mso">

       <!--[if gte mso 9]><xml>

        <o:DocumentProperties>

         <o:Created> 1996-12-17T01:32:42Z</o:Created>

         <o:LastSaved>2012-12-20T06:47:47Z</o:LastSaved>

         <o:Version>11.6568</o:Version>

        </o:DocumentProperties>

        <o:OfficeDocumentSettings>

         <o:RemovePersonalInformation/>

        </o:OfficeDocumentSettings>

       </xml><![endif]-->

       <style>

       <!--table

           {mso-displayed-decimal-separator:"\.";

           mso-displayed-thousand-separator:"\,";}

       @page

           {margin:1.0in .75in 1.0in .75in;

           mso-header-margin:.5in;

           mso-footer-margin:.5in;}

       tr

           {mso-height-source:auto;

           mso-ruby-visibility:none;}

       col

           {mso-width-source:auto;

           mso-ruby-visibility:none;}

       br

           {mso-data-placement:same-cell;}

       .style0

           {mso-number-format:General;

           text-align:general;

           vertical-align:bottom;

           white-space:nowrap;

           mso-rotate:0;

           mso-background-source:auto;

           mso-pattern:auto;

           color:windowtext;

           font-size:12.0pt;

           font-weight:400;

           font-style:normal;

           text-decoration:none;

           font-family: Times New Roman;

           mso-generic-font-family:auto;

           mso-font-charset:134;

           border:none;

           mso-protection:locked visible;

           mso-style-name: regular;

           mso-style-id:0;}

       td

           {mso-style-parent:style0;

           padding-top:1px;

           padding-right:1px;

           padding-left:1px;

           mso-ignore:padding;

           color:windowtext;

           font-size:12.0pt;

           font-weight:400;

           font-style:normal;

           text-decoration:none;

           font-family: Times New Roman;

           mso-generic-font-family:auto;

           mso-font-charset:134;

           mso-number-format:General;

           text-align:general;

           vertical-align:bottom;

           border:none;

           mso-background-source:auto;

           mso-pattern:auto;

           mso-protection:locked visible;

           white-space:nowrap;

           mso-rotate:0;}

       .xl24

           {mso-style-parent:style0;

           text-align:center;}

       .xl25

           {mso-style-parent:style0;

           mso-number-format:"Short Date";

           text-align:center;}

       .xl26

           {mso-style-parent:style0;

           font-size:14.0pt;

           font-weight:700;

&n
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.