J2EE sample code: Export data from database to Excel file

WBOY
Release: 2024-01-23 16:27:19
forward
912 people have browsed it

J2EE sample code: Export data from database to Excel file

1. Query database field information.

2. Use poi or jxl tool class to write fields to excel

3. Set the response attachment and output excel to the response output stream.

HttpServletResponse response=ServletActionContext.getResponse();

response.setContentType("application/octet-stream;charset=UTF-8");

response.reset(); //Clear the output stream

fileName = new String(fileName.getBytes(), "ISO-8859-1");

response.setHeader("Content-disposition", "attachment; filename=" fileName ".xls");

OutputStream out = response.getOutputStream();

The above is the detailed content of J2EE sample code: Export data from database to Excel file. For more information, please follow other related articles on the PHP Chinese website!

source:docexcel.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!