搜索
查看
编辑修改
首页
UNITY
NODEJS
PYTHON
AI
GIT
PHP
GO
CEF3
JAVA
HTML
CSS
搜索
从前慢现在也慢
这个屌丝很懒,什么也没留下!
关注作者
热门标签
jquery
HTML
CSS
PHP
ASP
PYTHON
GO
AI
C
C++
C#
PHOTOSHOP
UNITY
iOS
android
vue
xml
爬虫
SEO
LINUX
WINDOWS
JAVA
MFC
CEF3
CAD
NODEJS
GIT
Pyppeteer
article
热门文章
1
【解决】SQL Server无法连接本机服务器,彻底卸载SQL Server
2
网站localhost和127.0.0.1可以访问,本地ip不可访问解决方案_localhost可以访问 ip不能访问
3
【Unix/Linux】发展历程_unix和linux的历史
4
Python酷库之旅-第三方库openpyxl(14)_第三方库 openpyxl-style-writer
5
爬虫实践:爬取有道翻译(附带UI界面)
6
问题 I: 第9关:递归求解单链表中的最大值_用递归求链表最大值
7
Kotlin Misk Web框架
8
leetcode238.除自身以外数组的乘积(Python实现)_238 python leetcode
9
【STM32协议讲解】STM32CubeMX + STM32F103 + 逻辑分析仪分析IIC、SPI和串口协议_stm32f103的iic驱动原理
10
暑假第一周学习内容-ZARA仿写
当前位置:
article
> 正文
springmvc生成Excel并且返回给客户端_springmvc返回excel
作者:从前慢现在也慢 | 2024-07-17 23:32:00
赞
踩
springmvc返回excel
springmvc
生成Excel并且返回给客户端
1、首先是springmvc生成文件。
2、生成excel。==》这个可以参考我的apache POI EXCEL生成专题。
点击打开链接
好了,下面是代码:
[java]
view plain
copy
package
enht.soft.newhotelstn.controller;
import
org.apache.poi.hssf.usermodel.HSSFWorkbook;
import
org.apache.poi.ss.usermodel.Cell;
import
org.apache.poi.ss.usermodel.Row;
import
org.apache.poi.ss.usermodel.Sheet;
import
org.apache.poi.ss.usermodel.Workbook;
import
org.apache.poi.ss.util.CellReference;
import
org.springframework.http.HttpHeaders;
import
org.springframework.http.HttpStatus;
import
org.springframework.http.MediaType;
import
org.springframework.http.ResponseEntity;
import
org.springframework.stereotype.Controller;
import
org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.bind.annotation.RequestMethod;
import
java.io.*;
/**
* Created by Administrator on 2016-09-02.
*/
@Controller
@RequestMapping
(value =
"/downloadFile"
, method = {RequestMethod.GET, RequestMethod.POST})
public
class
FileDownLoad {
@RequestMapping
(
"download"
)
public
ResponseEntity<
byte
[]> download()
throws
IOException {
Workbook wb =
new
HSSFWorkbook();
Sheet sh = wb.createSheet();
for
(
int
rownum =
0
; rownum <
50
; rownum++) {
Row row = sh.createRow(rownum);
for
(
int
cellnum =
0
; cellnum <
30
; cellnum++) {
Cell cell = row.createCell(cellnum);
CellReference cr =
new
CellReference(cell);
String address = cr.formatAsString();
cell.setCellValue(address +
"row:"
+ cr.getRow() +
" col:"
+cr.getRow());
}
}
ByteArrayOutputStream out =
new
ByteArrayOutputStream();
try
{
wb.write(out);
}
catch
(IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
HttpHeaders headers =
new
HttpHeaders();
String fileName =
new
String(
"测试.xls"
.getBytes(
"UTF-8"
),
"iso-8859-1"
);
//为了解决中文名称乱码问题
headers.setContentDispositionFormData(
"attachment"
, fileName);
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
ResponseEntity<
byte
[]> filebyte =
new
ResponseEntity<
byte
[]>(out.toByteArray(),headers, HttpStatus.CREATED);
try
{
out.close();
}
catch
(IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return
filebyte;
}
}
3、需要的jar包
4、运行后的结果:
5、如果运行的时候发现比较慢的话,可以把数据弄的少一些。
原文转载:http://blog.csdn.net/wild46cat/article/details/52413884
声明:
本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:
https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/842549
推荐阅读
article
什么是
Microsoft
Office
365?
Excel
on Cloud 的好处_offic...
Office
365 是
Microsoft
的一套程序,可以在本地运行,也可以同步到云存储。可以从访问程序。借助 Of...
赞
踩
article
kettle
从入门到精通 第五十六课 ETL之
kettle
Microsoft
Excel
Outp...
如果您希望流式传输XLSX文件,请选择此选项。8)在接收数据前不创建文件:如果选择了此选项,则在检测到一行后,步骤才会创...
赞
踩
article
java
使用
openOffice
将
excel
转换为
pdf
前
,
对
excel
进
行
预处理
,
将
所有
列显示在一...
【代码】
java
使用
openOffice
将
excel
转换为
pdf
前
,
对
excel
进
行
预处理
,
将
所有
列显示在一页
,
将
所有
已...
赞
踩
article
java
给
img
、
pdf
、
ppt
、
doc
x
、
doc
、
wps
、wpt、rtf、xlsx、xls、et...
给
img
、
pdf
、
ppt
、
doc
x
、
doc
、
wps
、wpt、rtf、xlsx、xls、et、csv添加水印
img
、wor...
赞
踩
article
Apache
Openoffice
(2):
Java
实现
word
、
excel
、ppt、txt等办公
文件
...
项目
文件
结构如下: 传入
文件
的URL 弹出
文件
下载框,如果实在浏览器则会弹出页面_
java
实现在线
预览
excel
并保存j...
赞
踩
article
Java
通过
open
Office实现
word
,excel,ppt转成
pdf
实现在线预览_
open
o...
Java
通过
open
Office实现
word
,excel,ppt转成
pdf
实现在线预览一、OpenOffice1.1 下...
赞
踩
article
毕设项目:
超市
后台
管理系统
(JSP+
java
+
springmvc
+
mysql
+
MyBatis
)...
系统可以实现商品信息、库存管理、销售统计、员工管理等多种功能,方便
超市
管理者进行数据分析和决策。通过系统,
超市
可以实现自...
赞
踩
article
springMVC
/
boot
的
Echart
图表数据展示_
springmvc
引入
echarts5.3
...
Echart
的图表展示_
springmvc
引入
echarts5.3
springmvc
引入
echarts5.3
...
赞
踩
article
python
-
自动化
篇-办公-
Excel
-
Openpyxl
库_
openpyxl
使用
...
本文详细介绍了如何
使用
Python的
Openpyxl
库进行
Excel
文件的操作,包括安装、新建、读取、保存工作簿,创建、...
赞
踩
article
javaweb
ajax
maven
mybatis
spring
spring
mvc 在项目中有什...
假设我们正在开发一个在线商城的网站,使用JavaWeb技术,我们可以借助Maven来管理项目的依赖库和构建过程,使用AJ...
赞
踩
article
云
计算
的西安
工商学院
学报稿件
管理系统
开发(JSP+
java
+
springmvc
+
mysql
+MyBa...
随着信息技术的快速发展,云
计算
作为一种新型的
计算
模式,为数据存储和处理提供了高效、灵活的解决方案。西安
工商学院
作为一个培...
赞
踩
article
Python
实现
Excel
办公
自动化
之
openpyxl
_
python
接口
自动化
测试
excel
op...
Python
实现
Excel
办公
自动化
之
openpyxl
安装
openpyxl
基本操作引入库工作簿创建或者加载工作簿获取当前...
赞
踩
article
使用
openpyxl
处理
Excel
电子表格
_
openpyxl
修改
excel
...
`
openpyxl
`模块让 Python 程序能读取和修改
Excel
电子表格
文件。例如,可能有一个无聊的任务,需要从...
赞
踩
article
Python -
openpyxl
Excel 操作示例与实践_
value
error:
value
...
Python
openpyxl
库常用操作与实例分析~_
value
error:
value
must
be one of ...
赞
踩
article
python
-处理
Excel
电子表格-
openpyxl
模块_
import
openpyxl
...
openpyxl
模块:可以读取和修改
Excel
电子表格文件软件名及软件下载地址一个
Excel
电子表格文档称为一...
赞
踩
article
SSM
框架(
spring
+
spring
mvc+
mybatis
)+
Mysql
实现的社区
物业
管理
系统(功...
SSM
框架(
spring
+
spring
mvc+
mybatis
)+
Mysql
实现的社区
物业
管理
系统(功能包含分角色,
报修
管...
赞
踩
article
Python
系列(3)--
Python
读取
EXCEL
(XLS、CSV)写入
txt
文件_pytho...
本人尝试了很多网上的方法,发现下面这些不同的错误 TypeError: a bytes-like object is r...
赞
踩
article
python3
读写
excel
文件
_13-用
Python
读写
Excel
文件
...
在以前,商业分析对应的英文单词是Business Analysis,大家用的分析工具是
Excel
,后来数据量大了,Exc...
赞
踩
article
python
实现读
Excel
写入.
txt
_
python
excel
转
txt
...
因为今天要用到把
Excel
中的数据写入到.
txt
文件中,所以简单的写了个代码:import numpy as npimp...
赞
踩
article
python
创建
excel
文件
报错_13-用
Python
读写
Excel
文件
...
在以前,商业分析对应的英文单词是Business Analysis,大家用的分析工具是
Excel
,后来数据量大了,Exc...
赞
踩
相关标签
microsoft
excel
etl
kettle
kettle excel教程
kettle教程
java
pdf
powerpoint
wps
apache
word
linux
centos
课程设计
mysql
echarts
前端
javascript
python
自动化
开发语言
spring