简体   繁体   中英

How to export data from database to excel sheet using spring MVC?

How to export data from MySQL table to excel using spring MVC?

I tried many from Google, but nothings works. As I required, I tried this code but its not from a database.

How to export from a database?

Instead of Apache POI, I recommend you to use another library to write Excel file, EasyXLS . You can export your data directly from MySQL to Excel using the ResultSet. See here how to export ResultSet to Excel .

    ExcelDocument xls = new ExcelDocument();
    xls.easy_WriteXLSFile_FromResultSet("Excel.xls", resultset,  
              new ExcelAutoFormat(Styles.AUTOFORMAT_EASYXLS1), "Sheet name");

or

    ExcelDocument xls = new ExcelDocument();
    xls.easy_WriteXLSXFile_FromResultSet("Excel.xlsx", resultset,  
              new ExcelAutoFormat(Styles.AUTOFORMAT_EASYXLS1), "Sheet name");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM