Skip to content
Advertisement

How to download an excel file in Spring RestController

I am using Apache POI to generate .xlsx file.

I would like to return that file from Spring controller. Here’s what I’ve done so far:

Controller:

JavaScript

Is it possible to return actual excel file from rest controller so user can download it to his computer ? As for now controller returning byte[] but I would like to return it actual file. How can I achieve that ?

Advertisement

Answer

You can use ByteArrayResource to download as a file. Below is the modified code snippet of yours

JavaScript

If you are trying to generate excel using apache poi, please find the code snippet below

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement