Home >Software Tutorial >Office Software >J2EE sample code: Export data from database to Excel file

J2EE sample code: Export data from database to Excel file

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBforward
2024-01-23 16:27:191064browse

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!

Statement:
This article is reproduced at:docexcel.net. If there is any infringement, please contact admin@php.cn delete