Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
yangxiujun
/
paidan_demo
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 9264d8d7
authored
Jan 10, 2024
by
yangxiujun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:优化模版下载
1 parent
c904e08e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
7 deletions
project-order/src/main/java/com/dituhui/pea/order/controller/FileController.java
project-order/src/main/java/com/dituhui/pea/order/controller/FileController.java
View file @
9264d8d
...
...
@@ -12,6 +12,9 @@ import com.dituhui.pea.order.service.impl.OrderCreateServiceImpl;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
com.alibaba.excel.EasyExcel
;
...
...
@@ -112,20 +115,25 @@ public class FileController {
* @param response
*/
@GetMapping
(
value
=
"/file/downOrder"
)
public
void
downOrderTemplate
(
HttpServletResponse
response
)
{
public
ResponseEntity
<
byte
[]>
downOrderTemplate
(
)
{
try
{
ArrayList
arrayList
=
new
ArrayList
<
OrderInfoExcelDTO
>();
response
.
setContentType
(
"application/vnd.ms-excel"
);
response
.
setCharacterEncoding
(
"utf-8"
);
ArrayList
<
OrderInfoExcelDTO
>
arrayList
=
new
ArrayList
<>();
// 假设您有方法获取需要导出的数据,然后添加到 arrayList 中
HttpHeaders
headers
=
new
HttpHeaders
();
String
fileName
=
URLEncoder
.
encode
(
"ORDER-"
+
new
SimpleDateFormat
(
"yyyyMMddHHmmss"
).
format
(
new
Date
()),
"UTF-8"
).
replaceAll
(
"\\+"
,
"%20"
);
response
.
setHeader
(
"Content-disposition"
,
"attachment;filename*=utf-8''"
+
fileName
+
".xlsx"
);
EasyExcel
.
write
(
response
.
getOutputStream
(),
OrderInfoExcelDTO
.
class
)
headers
.
setContentDispositionFormData
(
"attachment"
,
fileName
+
".xlsx"
);
headers
.
setContentType
(
MediaType
.
APPLICATION_OCTET_STREAM
);
ByteArrayOutputStream
outputStream
=
new
ByteArrayOutputStream
();
EasyExcel
.
write
(
outputStream
,
OrderInfoExcelDTO
.
class
)
.
registerWriteHandler
(
ExcelUtil
.
getDefaultWriteHandler
())
//注入原生 或 自定义转换器
.
registerConverter
(
new
DateStringConverter
())
.
registerConverter
(
new
BigDecimalStringConverter
())
.
sheet
(
"工单列表"
).
doWrite
(
arrayList
);
byte
[]
excelBytes
=
outputStream
.
toByteArray
();
return
new
ResponseEntity
<>(
excelBytes
,
headers
,
HttpStatus
.
OK
);
}
catch
(
IOException
e
)
{
throw
new
BusinessException
(
"订单列表模版下载异常:"
+
e
.
getMessage
());
}
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment