添加的maven依賴:
十多年的內(nèi)鄉(xiāng)網(wǎng)站建設(shè)經(jīng)驗(yàn),針對(duì)設(shè)計(jì)、前端、開(kāi)發(fā)、售后、文案、推廣等六對(duì)一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。成都全網(wǎng)營(yíng)銷(xiāo)的優(yōu)勢(shì)是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整內(nèi)鄉(xiāng)建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無(wú)論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。創(chuàng)新互聯(lián)公司從事“內(nèi)鄉(xiāng)網(wǎng)站設(shè)計(jì)”,“內(nèi)鄉(xiāng)網(wǎng)站推廣”以來(lái),每個(gè)客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。
創(chuàng)新互聯(lián)專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于網(wǎng)站建設(shè)、成都網(wǎng)站制作、和布克賽爾蒙古網(wǎng)絡(luò)推廣、成都小程序開(kāi)發(fā)、和布克賽爾蒙古網(wǎng)絡(luò)營(yíng)銷(xiāo)、和布克賽爾蒙古企業(yè)策劃、和布克賽爾蒙古品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營(yíng)等,從售前售中售后,我們都將竭誠(chéng)為您服務(wù),您的肯定,是我們最大的嘉獎(jiǎng);創(chuàng)新互聯(lián)為所有大學(xué)生創(chuàng)業(yè)者提供和布克賽爾蒙古建站搭建服務(wù),24小時(shí)服務(wù)熱線:18982081108,官方網(wǎng)址:aaarwkj.com
org.jxls
jxls-poi
${jxsl.poi.version}
org.jxls
jxls
${jxls.version}
org.jxls
jxls-reader
2.0.3
導(dǎo)出模板類(lèi):
package com.ismartgo.uqcode.common.utils;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jxls.common.Context;
import org.jxls.util.JxlsHelper;
/**
* JXSL excel模板工具方法
*
* JXSL detail please see http://jxls.sourceforge.net/
* User: Foy Lian
* Date: 2017-07-04
* Time: 17:44
*/
public class JxlsTemplate {
/**
* 模板路徑
*/
private static final String TEMPLATE_DIR = "/excel";
protected static Log logger = LogFactory.getLog(JxlsTemplate.class);
/**
* 使用JxlsTemplate.class.getResourceAsStream load 模板
*
* @param template 模板名稱,相當(dāng)于TEMPLATE_DIR設(shè)置的路徑
* @param out 生成excel寫(xiě)入的輸出流
* @param params 交給jxls處理模板需要的參數(shù)
* @throws IOException
*/
public static void processTemplate(String template, OutputStream out, Map params) throws IOException {
processTemplate(JxlsTemplate.class, template, out, params);
}
/**
* 使用resourceBaseClassgetResourceAsStream load 模板
*
* @param resourceBaseClass class load的類(lèi)
* @param template 模板名稱
* @param out 生成excel寫(xiě)入的輸出流
* @param params 交給jxls處理模板需要的參數(shù)
* @throws IOException
*/
public static void processTemplate(Class resourceBaseClass, String template, OutputStream out, Map params) throws IOException {
InputStream in = resourceBaseClass.getResourceAsStream(TEMPLATE_DIR + template);
if (null == in) {
logger.error("can't find excel template by path:" + TEMPLATE_DIR + template);
throw new TemplateNotFoundException("找不到excel模板!,位置:" + TEMPLATE_DIR + template);
}
processTemplate(in, out, params);
}
/**
* @param templateStream excel模板流
* @param out 生成excel寫(xiě)入的輸出流
* @param context jxsl上下文
* @throws IOException
*/
private static void processTemplate(InputStream templateStream, OutputStream out, Context context) throws IOException {
JxlsHelper.getInstance().processTemplate(templateStream, out, context);
}
/**
* @param templateStream excel模板流
* @param out 生成excel寫(xiě)入的輸出流
* @param params 交給jxls處理模板需要的參數(shù)
* @throws IOException無(wú)錫×××醫(yī)院 https://yyk.familydoctor.com.cn/20612/
*/
public static void processTemplate(InputStream templateStream, OutputStream out, Map params) throws IOException {
Context context = new Context();
if (params != null) {
for (String key : params.keySet()) {
context.putVar(key, params.get(key));
}
}
processTemplate(templateStream, out, context);
}
}
Controller類(lèi)導(dǎo)出接口方法:
@RequestMapping(value="/export", method = RequestMethod.GET)
public void export(HttpServletResponse response,HttpServletRequest req) {
AuthUser user = (AuthUser) req.getSession().getAttribute("loginUser");
UqcProduct product = new UqcProduct();
//product.setSysTenantCode(user.getSysTenantCode());
product.setSysTenantCode("1");
ServletOutputStream out = null;
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
List list = productService.queryList(product);
Map params = new HashMap();
params.put("items", list);
try {
response.setHeader("Expires", "0");
response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
response.setHeader("Content-Disposition", "attachment; filename=\"product.xls\"");
response.setHeader("Pragma", "public");
response.setContentType("application/x-excel;charset=UTF-8");
out = response.getOutputStream();
JxlsTemplate.processTemplate("/productList_export.xls", out, params);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
Excel模板:
Excel模板添加的批注:上圖ID批注:zsy:jx:area(lastCell="N2")
${item.id}的批注:zsy:jx:each(items="items" var="item" lastCell="N2")
模板識(shí)別到Controller傳入的items值進(jìn)行for循環(huán)進(jìn)行值得填充
文章標(biāo)題:Springboot集成jxls實(shí)現(xiàn)導(dǎo)出excel功能
路徑分享:http://aaarwkj.com/article44/iijpee.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供軟件開(kāi)發(fā)、營(yíng)銷(xiāo)型網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)公司、動(dòng)態(tài)網(wǎng)站、關(guān)鍵詞優(yōu)化、服務(wù)器托管
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)