Nov 06, 2018 In this article, we will demonstrate how to upload Excel files and display their content in a web page using the Spring MVC framework. Uploading Excel Files. In order to be able to upload files, we will first create a controller mapping that receives a MultipartFile and saves it in the current location.
- Spring Mvc Download Excel File Controller Example
- Spring Mvc Download File
- C# Mvc Download File
- Spring Mvc Jar Download
- Mvc Download File From Server
Active2 years, 9 months ago
I'am working on an excel export functionality in one of my webapps. I set up a little test case and got the download working, but the xlsx file is corrupted and don't know what else I could try. If I write the excel to file it opens without problem, so the error must occure when downloading.
![Spring mvc download excel file in java Spring mvc download excel file in java](/uploads/1/2/6/0/126033113/231723445.png)
The setup:
spring-mvc 3.2.7poi 3.10.1Tomcat 8.0
Controller method:
Spring Mvc Download Excel File Controller Example
Abstract Custom View:
ExcelBuilder:
Response Header:
It confuses me that the charset will be set, when this is binary data. Could that be the problem?
![File File](/uploads/1/2/6/0/126033113/300399498.png)
user3734130user3734130
2 Answers
Spring Mvc Download File
Don't return ModelAndView but just write the excel file to the response's outputStream
Check all the streams flushed/closed
StanislavLStanislavL52.9k88 gold badges4646 silver badges8181 bronze badges
I would suggest to use existing solution rather than trying to deal with the response stream by yourself.
I would use AbstractExcelView instead of your
AbstractPOIExcelView
to do the job. Check this tutorial using AbstractExcelView for inspiration.For Spring 4.2 or newer use AbstractXlsView (or AbstractXlsxView) because the original
AbstractExcelView
is deprecated.C# Mvc Download File
The Student Soul1,07011 gold badge77 silver badges1010 bronze badges
Spring Mvc Jar Download
betatester07betatester07