In this example, we create excel sheet and display image on that. We can request that the browser open the results in Excel and suggest the file to use when the user saves the file by setting the following two response headers: Content-Type and Content-Disposition
Here, we use page directive and set the contentType
attribute by the value "application/vnd.ms-excel". The purpose of setting this contentType is to display the output
in excel format.
<%@ page contentType="application/vnd.ms-excel" %>
We set the header as: response.setHeader("Content-Disposition", "attachment; filename=\"mult-table.xls\"").The response object provides a convenience method for setting the Content-Type header. Both can be set with the setHeader method.
In this example we insert the image and the output will display in excel format with image.You can use third party APIs to create the excel sheet, which you can learn in our next example. The third party APIs are provided by Jakarta Apache Foundation group.
The code of the program is given below:
The output of the program is given below:
If you enjoyed this post then why not add us on Google+? Add us to your Circles
Liked it! Share this Tutorial