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 ...
随机推荐
- choice接口、同花顺使用
一 choice接口使用 1.choice软件-->量化-->下载中心,下载python接口文件 EMQuantAPI_Python 2.要先绑定手机号,绑定后账户权限不够,暂时放弃. 二 ...
- vector删除指定元素
#pragma once #include "stdafx.h" #include<windows.h> #include <vector> #includ ...
- java-正则表达式判断移动联通电信手机号
package com.linbilin.phone; import java.util.regex.Matcher; import java.util.regex.Pattern; public c ...
- mybatis-地区三表生成地区树
package com.dhht.manager.vo.area; import lombok.Data; import java.io.Serializable;import java.util.L ...
- PAT Advanced 1094 The Largest Generation (25) [BFS,DFS,树的遍历]
题目 A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level ...
- cmake 中的 compile_commands.json 文件
cmake 是支持多种编译方式的工具,产生多种编译工具可以使用的编译文件,例如常用的gdb. 但是对于clang 编译工具,还需要一个compile_commands.json 这个文件是由cmake ...
- [RoarCTF 2019]Easy Java
0x01知识点: WEB-INF/web.xml泄露 WEB-INF主要包含一下文件或目录: /WEB-INF/web.xml:Web应用程序配置文件,描述了 servlet 和其他的应用组件配置及命 ...
- dfs--迷宫
题目背景 给定一个N*M方格的迷宫,迷宫里有T处障碍,障碍处不可通过.给定起点坐标和终点坐标,问: 每个方格最多经过1次,有多少种从起点坐标到终点坐标的方案.在迷宫中移动有上下左右四种方式,每次只能移 ...
- vue每次运行起来端口不一致问题
原因:portfinder新发布的版本异常 解决方案:npm install portfinder@1.0.21
- mongodb的常见使用命令行
由于cms工程要连接mongodb所以需要在在cms服务端工程添加如下依赖:项目使用spring data mongodb操作mongodb数据库 <dependency> <gro ...