java如何導出excel_java導出excel的工具及方電腦知識
導讀:電腦知識電腦知識很多網友不知道java如何導出excel,相信很多做java系統開發的網友經常會很頻繁的遇到Excel導出問題,而很多時候遇到這樣的情況不知道應該如何操作,今天itil知識itss知識庫管理和使用制度。
很多網友不知道java如何導出excel,相信很多做java系統開發的網友經常會很頻繁的遇到Excel導出問題,而很多時候遇到這樣的情況不知道應該如何操作,今天就為大家分享這個java導出excel的工具及方法,希望能夠幫助到有需要的網友。
java導出excel的工具及方法
今天為大家推薦的這個工具名叫EasyExcel,該工具是一個基于Java的、快速、簡潔、解決大文件內存溢出的Excel處理工具,他能讓你在不用考慮性能、內存的等因素的情況下,快速完成Excel的讀、寫等功能。
- easyexcel官網:https://easyexcel.opensource.alibaba.com/
1、先進行pom.xml要導入包進行添加:excel表格隱藏的行怎么恢復(excel表格取消隱藏的方法) <!-- excel工具包 https://easyexcel.opensource.alibaba.com/qa/--> <dependency> <groupId>com.alibaba</groupId> <artifactId>easyexcel</artifactId> <version>2.2.10</version> <exclusions> <exclusion> <groupId>org.apache.poi</gro高端網站建設upId> <artifactId>poi</artifactId> </exclusion> <exclusion> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> </exclusion> <exclusion> <artifactId>poi-ooxml-schemas</artifactId> <groupId>org.apache.poi</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>4.1.2</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>4.1.2</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml-schemas</artifactId> <version>4.1.2</version> </dependency> <dependency> <groupId>com.deepoove</groupId> <artifactId>poi-tl</artifactId> <version>1.10.0</version> </dependency>
2、接著我們寫個通用EasyExcel工具類:
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.support.ExcelTypeEnum; import lombok.extern.slf4j.Slf4j; import javax.servlet.http.HttpServletResponse; import java.net.URLEncoder; import java.util.List; /** * EasyExcel工具類 */ @Slf4j public class EasyExcelUtil { /** * 導出Excel(07版.xlsx)到web * * @param response 響應 * @param excelName Excel名稱 * @param sheetName sheet頁名稱 * @param clazz Excel要轉換的類型 * @param data 要導出的數據 * @throws Exception */ public static void export2Web(HttpServletResponse response, String excelName, String sheetName, Class clazz, List data) throws Exception { response.setContentType("application/vnd.ms-excel"); response.setCharacterEncoding("utf-8"); // 這里URLEncoder.encode可以防止中文亂碼 excelName = URLEncoder.encode(excelName, "UTF-8"); response.setHeader("Content-disposition", "attachment;filename=" + excelName + ExcelTypeEnum.XLSX.getValue()); EasyExcel.write(response.getOutputStream(), clazz).sheet(sheetName).doWrite(data); } }聲明: 本文由我的SEOUC技術文章主頁發布于:2023-05-31 ,文章java如何導出excel_java導出excel的工具及方電腦知識主要講述電腦知識,工具,java如何導出excel_java導出ex網站建設源碼以及服務器配置搭建相關技術文章。轉載請保留鏈接: http://www.bifwcx.com/article/news_13090.html