用户信息批量导出至EXCEL

用户信息批量导出至EXCEL

说明:批量导出信息就是将页面查询到的结果,写出到EXCEL文件中。
操作步骤:
一、预备工作

0、引入包

XLS文件解析:poi-3.7-20101029.jar

1、建表users

create table users(
id int primary key auto_increment,
name varchar(20) not null,
password varchar(32) not null,
sex varchar(2) not null,
birthday date not null,
hobby varchar(50) not null,
telephone varchar(15) not null,
address varchar(50) not null,
type int not null -- 1 admin 2 common user
);

插入测试数据:

insert into users values(1,'admin','202CB962AC59075B964B07152D234B70','男',
'1980-1-1','体育,旅游','13953311099','山东淄博',1);
insert into users values(2,'abc','202CB962AC59075B964B07152D234B70','女',
'1990-1-1','体育,音乐','1895330000','山东济南',2);
…………

效果如下:

2、建立相应的JavaBean:

package cn.sdut.po;
public class User {
   
private int id;
private String name;
private String password;
private String sex;
private String birthday;
private String hobby;
private String telephone;
private String address;
private int type;
public User() {
super();
}
public User(int id, String name, String password, String sex,
String birthday, String hobby, String telephone, String address,
int type) {
super();
this.id = id;
this.name = name;
this.password = password;
this.sex = sex;
this.birthday = birthday;
this.hobby = hobby;
this.telephone = telephone;
this.address = address;
this.type = type;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getBirthday() {
return birthday;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}
public String getHobby() {
return hobby;
}
public void setHobby(String hobby) {
this.hobby = hobby;
}
public String getTelephone() {
return telephone;
}
public void setTelephone(String telephone) {
this.telephone = telephone;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
@Override
public String toString() {
return "User [id=" + id + ", name=" + name + ", password=" + password
+ ", sex=" + sex + ", birthday=" + birthday + ", hobby="
+ hobby + ", telephone=" + telephone + ", address=" + address
+ ", type=" + type + "]";
}
}

二、查询用户信息并写出至EXCEL文件中

1、准备前端页面——userMain.jsp,内容如下。

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'userMain.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script src="js/calendar.js"></script>
<script>
function selectUser()
{
    
form1.action="<%=path%>/UserServlet?method=bycond";
form1.submit();
}
function exportexcel()
{
    
form1.action="<%=path%>/UserServlet?method=exportExcel";
form1.submit();
}
</script>
</head>
<body>
<center>
<h1>用 户 管 理</h1>
</center>
<br>
<form action="" method="post" name="form1">
<p>
查询条件: <input type="text" name="condition" 
  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Access数据库是微软公司开发的一款用于管理和处理大量数据的软件,可以轻松地将数据保存在表格中,并且可以对这些数据进行各种处理和管理,但是Access数据库并不擅长数据的可视化展示,而Excel是一款专注于数据可视化的软件。因此,Access批量导出Excel可以让用户更好地展示和分析数据。 批量导出在Access的菜单中非常简单,只需要正确的设置导出参数即可高效地导出,下面介绍一下具体步骤: 1. 打开Access数据库 2. 选择需要导出的表格并双击,进入表格查看的状态 3. 在工具栏中点击“外部数据”,然后选择“导出Excel” 4. 在弹出的窗口中选择保存导出Excel文件的路径和名称,点击“下一步” 5. 在下一窗口中选择导出的方式和格式,包括字段分隔符、文本分隔符等参数设置,然后点击“下一步” 6. 在下一个窗口中选择数据的筛选条件,可以选择导出全部数据或者筛选需要导出的数据,然后点击“下一步” 7. 在最后一个窗口中可以修改导出Excel文件的名称或者添加描述信息等,设置完成后点击“完成” 8. 此时Excel文件已经成功导出,可以在文件所在目录下打开查看。 通过上面的操作步骤,Access批量导出Excel就可以轻松地完成,用户可以选择不同的文件格式和导出选项,满足不同的数据处理需求。同时,这也是一种有效的数据备份和共享方式。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值