jsp 页面内容导出到Excel中
日常使用网络资源时经常需要把网页中的内容下载到本地,并且导出到Excel中,现在介绍一种非常简单的方式实现网络资源的下载。只需要讲jsp的最上面加上一句话
<%
response.reset();
response.setContentType("application/vnd.ms-excel;charset=GBK");
%>
就可以将网页的内容导出为Excel。
目前给出的例子为了方便起见,就是使用了纯粹的静态页面,一个table其中有一行是标题,一行是内容,但是实际使用中不可能这么简单,都是保持静态的内容,如果需要保存的内容是从数据库中取出,则只需要循环遍历取出的内容,添加行就行了,假如从数据库中取出的数据存入UserList中,可以使用struts标签进行遍历如下:
<table class="common1" cellpadding="5" cellspacing="1" align="center" >
<tr>
<td class=formtitle colspan="4"><CENTER> 清单</CENTER> </td>
</tr>
<tr>
<td class=formtitle align="center" nowrap style="width:13%">姓名</td>
<td class=formtitle align="center" nowrap style="width:13%">年龄</td>
<td class=formtitle align="center" nowrap style="width:13%">性别</td>
<td class=formtitle align="center" nowrap style="width:13%">住址</td>
</tr>
<logic:present name="UserList">
<logic:iterate id="user" name="UserList">
<tr>
<td align="center" nowrap style="width:13%">
<bean:write name = "user",property="name"/>
</td>
<td align="center" nowrap style="width:13%">
<bean:write name = "user",property="age"/>
</td>
<td align="center" nowrap style="width:13%">
<bean:write name = "user",property="sex"/>
</td>
<td align="center" nowrap style="width:13%">
<bean:write name = "user",property="address"/>
</td>
</tr>
</logic:iterate>
</logic:present>
</table>
下面是完整的例子,新建Dynamic Web Project,在WebContent下新建一个index.jsp,里面只需要一个超链接<a href = 'DownLoadExcel.jsp'>导出Excel</a>
再新建一个DownLoadExcel.jsp,内容如下:
<%
response.reset();
response.setContentType("application/vnd.ms-excel;charset=GBK");
%>
<html>
<head>
<title>刷卡消费情况</title>
<style type="text/css">
table.common1 { width: 100%;
font-size: 9pt;
style-align: center;
background-color: #ffffff;
}
td.formtitle { font-size: 9pt;
background:#a480b2;
color:#ffffff;
height:30px;
text-align: center;}
</style>
</head>
<body>
<form name="fm" method="post" >
<table class="common1" cellpadding="5" cellspacing="1" align="center" >
<tr>
<td class=formtitle colspan="4"><CENTER> 清单</CENTER> </td>
</tr>
<tr>
<td class=formtitle align="center" nowrap style="width:13%">姓名</td>
<td class=formtitle align="center" nowrap style="width:13%">年龄</td>
<td class=formtitle align="center" nowrap style="width:13%">性别</td>
<td class=formtitle align="center" nowrap style="width:13%">家庭住址</td>
</tr>
<tr>
<td align="center" nowrap style="width:13%">张三</td>
<td align="center" nowrap style="width:13%">25</td>
<td align="center" nowrap style="width:13%">男</td>
<td align="center" nowrap style="width:13%">北京中关村</td>
</tr>
</table>
</form>
</body>
</html>
jsp 页面内容导出到Excel中的更多相关文章
- 将jsp页面内容保存到excel(转)
在此,强调一下搜索时关键词的重要性,这样一下子可以定位到文章,否则处于盲人摸象,毫无目的尴尬境地.本篇就是通过export jsp to excel找到的. 原文地址:How to Export We ...
- 将页面上的内容导出到Excel
<asp:Button ID="lkbExport" runat="server" Name="Save" Text="导出 ...
- html table表格导出excel的方法 html5 table导出Excel HTML用JS导出Excel的五种方法 html中table导出Excel 前端开发 将table内容导出到excel HTML table导出到Excel中的解决办法 js实现table导出Excel,保留table样式
先上代码 <script type="text/javascript" language="javascript"> var idTmr; ...
- 使用NPOI将TABLE内容导出到EXCEL
项目中需要将页面中的table内容导出到EXCEL,在用了几种方法后发现NPO是最快&最好的 需要应用 NPOI.dll 还有个Ionic.Zip.dll不知道有用没,没去研究,两个DLL都放 ...
- C# html的Table导出到Excel中
C#中导出Excel分为两大类.一类是Winform的,一类是Web.今天说的这一种是Web中的一种,把页面上的Table部分导出到Excel中. Table导出Excel,简单点说,分为以下几步: ...
- HTML table导出到Excel中的解决办法
第一部分:html+js 1.需要使用的表格数据(先不考虑动态生成的table) <table class="table tableStyles" id="tabl ...
- 【WPF】将DataGrid内容导出到Excel
引言 在做项目时要求将datagrid的内容导出到Excel,以前做winform项目时遇到过,就把代码搬过来用,但wpf和winform还是有些不同,就修改了一些东西,使其能实现这个功能. 本文是导 ...
- 将datagrid中数据导出到excel中 -------<<工作日志2014-6-6>>
前台datagrid数据绑定 #region 导出到excel中 /// <summary> /// 2014-6-6 /// </summary> / ...
- 将Datagridview中的数据导出至Excel中
首先添加一个模块ImportToExcel,并添加引用 然后导入命名空间: Imports Microsoft.Office.Interop Imports System.Da ...
随机推荐
- POJ 1519:Digital Roots
Digital Roots Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25766 Accepted: 8621 De ...
- C++ 模板练习1
//特定的模板友元关系 #include "stdafx.h" #include <iostream> using namespace std; template< ...
- JZOJPJ-C 8/21题解
原题大战D1 吐槽: T1 \(O(N^2)\; N \leq 26\) N大时还要写高精, 可以增加难度 T2 不给范围 T3 居然没有完全卡掉 不对应该赞美出题人 T4 PJ考个四边形不等式?? ...
- Asp.NET CORE安装部署
先安装IIS再安装这两个,不然后面各种bug HTTP 错误 500.19 代码 0x8007000d 解决方案 for win7_64 asp.net core IIS Web Core 1.比如最 ...
- css选择器,选择指定属性的值
选择属性为href的值: <a class='test' href='www.baidu.com' >test</a> response.css('.test::attr(hr ...
- 批量导入数据表(oracle)
批量导入数据表(oracle) 1.登陆plsql 2.找到菜单栏 工具>>导入数据>>新增图标(会提示选择*.csv文件) 选择如上图所示 3.选择数据并导入 4.下图为执行 ...
- 通过ES6 封装了一个上传文件的方法 XMLHttpRequest() 通用
### 上传进度回显,上传速度回显 ### 源码如下,新建index.js装起来 export class UploadServers { constructor (options) { this.x ...
- 视图家族之视图工具集viewsets
视图家族之视图工具集viewsets 一.视图集ViewSet 使用视图集ViewSet,可以将一系列逻辑相关的动作放到一个类中: list() 提供一组数据 retrieve() 提供单个数据 cr ...
- java 实现递归实现tree(2)
import com.google.common.collect.Lists; import org.springframework.cglib.beans.BeanCopier; import ja ...
- 基于libcurl的GET与POST(HTTP1.1)
#include <stdio.h> #include <curl/curl.h> bool getUrl(char *filename) { CURL *curl; CURL ...