java 实现页面上的table导出为EXCEL

本文介绍了一个使用Java生成包含大量数据的Excel文件的方法。通过设置HTTP响应头实现文件下载,并展示了如何利用JSP动态生成带有7万行记录的Excel表格。此示例适用于需要批量导出数据的应用场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<%
response.setHeader("Content-disposition","attachment; filename=export_data.xls");
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE> New Document </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
 </HEAD>

 <BODY>
 
<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" >
<head>

<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;}
.font0
  {color:windowtext;
  font-size:12.0pt;
  font-weight:400;
  font-style:normal;
  text-decoration:none;
  font-family:宋体;
  mso-generic-font-family:auto;
  mso-font-charset:134;}
.font6
  {color:windowtext;
  font-size:12.0pt;
  font-weight:400;
  font-style:normal;
  text-decoration:none;
  font-family:"Times New Roman", serif;
  mso-font-charset:0;}
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:;
  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:宋体;
  mso-generic-font-family:auto;
  mso-font-charset:134;
  border:none;
  mso-protection:locked visible;
  mso-style-name:常规;
  mso-style-id:0;}
td
  {mso-style-parent:style0;
  padding-top:5px;
  padding-right:5px;
  padding-left:5px;
  mso-ignore:padding;
  color:windowtext;
  font-size:12.0pt;
  font-weight:400;
  font-style:normal;
  text-decoration:none;
  font-family:宋体;
  mso-generic-font-family:auto;
  mso-font-charset:134;
  mso-number-format:General;
  text-align:general;
  vertical-align:bottom;
  border-top:.5pt solid windowtext;
  border-right:.5pt solid windowtext;
  border-bottom:.5pt solid windowtext;
  border-left:.5pt solid windowtext;
  mso-background-source:auto;
  mso-pattern:auto;
  mso-protection:locked visible;
  white-space:;
  mso-rotate:0;}
.left
  {mso-style-parent:style0;
  text-align:left;
  border:.5pt solid windowtext;}
.left_red
  {mso-style-parent:style0;
  text-align:left;
  border:.5pt solid windowtext;
  color:red;}
.center
  {mso-style-parent:style0;
  text-align:center;
  border:.5pt solid windowtext;}
.right
  {mso-style-parent:style0;
  font-family:"Times New Roman", serif;
  text-align:right;
  mso-font-charset:0;
  mso-number-format:"/@";}
.right_red
  {mso-style-parent:style0;
  font-family:"Times New Roman", serif;
  text-align:right;
  mso-font-charset:0;
  mso-number-format:"/@";
  color:red;}
ruby
  {ruby-align:left;}
rt
  {color:windowtext;
  font-size:9.0pt;
  font-weight:400;
  font-style:normal;
  text-decoration:none;
  font-family:宋体;
  mso-generic-font-family:auto;
  mso-font-charset:134;
  mso-char-type:none;
  display:none;}
-->
</style>
</head>
<body >
<table class=main cellspacing="0" cellpadding="0" align="center">
 <tr><td valign="top">
 
 <FORM name="thisform" method="post">

 <table width="100%" cellSpacing=0 borderColorDark=#F3FBF0 cellPadding=1 align=center borderColorLight=#999999 border=1>
<%

for(int m = 0; m < 70000; m++)
{
 out.print("<TR>");
 out.print("<td align='center'>" + m + "</td>");
 out.print("<td align='center'>" + m + "</td>");
 out.print("</TR>");
}

 

%>
 </table>
    </td></tr>
</table>
</form>
</body>
</html>

 </BODY>
</HTML>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值