java導(dǎo)出到excel常用的幾種方式總結(jié)
java導(dǎo)出excel常用的方式使用poi apache開源方式導(dǎo)入導(dǎo)出,很多公司自己研發(fā)導(dǎo)出組件對于常用的導(dǎo)入導(dǎo)出其實(shí)都使用開源組件。
介紹常用的excel導(dǎo)出方式:
1,poi 方式
上圖一個(gè)我之前寫的很老的導(dǎo)出,代碼比較麻煩,但是也是比較穩(wěn)定的一個(gè)版本:
pom依賴:
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
</dependency>定義一個(gè)下載抽象接口:
package com.bootdo.common.service;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;
public interface DownExcelService {
void downexcel(HttpServletResponse response, Map<String, String> params) throws Exception;
}定義一個(gè)抽象接口實(shí)現(xiàn)類
package com.bootdo.common.controller.detail;
import com.bootdo.common.service.DownExcelService;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;
public abstract class AbstractDetaliCallBackServiceImpl implements DownExcelService {
@Override
public void downexcel(HttpServletResponse response, Map<String, String> params) throws Exception {
}
}定義實(shí)現(xiàn)類集成抽象接口:
package com.bootdo.common.downInterface;
import com.bootdo.common.config.Constant;
import com.bootdo.common.config.WorkflowConfigCodeConstants;
import com.bootdo.common.domain.AdvanceDO;
import com.bootdo.common.service.AdvanceService;
import com.bootdo.common.utils.CommonMethod;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service(WorkflowConfigCodeConstants.ADVANCE_DOWNXECEL)
public class AdvaceDownExcelServiceImpl extends AbstractExcelCallBackServiceImpl {
@Autowired
private AdvanceService advanceService;
@Override
public void downexcel(HttpServletResponse response, Map<String, String> params) throws Exception {
String date = params.get("date");
String name = params.get("name");
String proparentId = params.get("proparentId");
Map<String, Object> map = new HashMap();
if (StringUtils.isNotBlank(ObjectUtils.toString(params.get("date"), ""))) {
String[] dateBteetn = CommonMethod.getDate(params.get("date").toString());
map.put("startDate" , dateBteetn[0]);
map.put("stopDate" , dateBteetn[1]);
}
if (StringUtils.isNotBlank(ObjectUtils.toString(params.get("name"), ""))) {
map.put("name" , params.get("name").toString());
}
if (StringUtils.isNotBlank(ObjectUtils.toString(params.get("proparentId"), ""))) {
map.put("proparentId" , params.get("proparentId").toString());
}
String typeNames = CommonMethod.typeNameExcel(date, name, proparentId);
List<AdvanceDO> list = advanceService.list(map);
CommonMethod.downexcel(response, list, Constant.EXCELE_ADVANCE_STATUS, typeNames, 6);
}
}常量策略類:
package com.bootdo.common.config;
/**
* Excel 下載接口
*
* @author yangchang
*/
public interface WorkflowConfigCodeConstants {
/**
* 工人總賬目
*/
String ADVANCE_SUM_DOWNXECEL = "advacnsum_downexcel";
/**
* 工人借支
*/
String ADVANCE_DOWNXECEL = "advacn_downexcel";
/**
* 材料
*/
String METATLE_DOWNXECEL = "metail_downexcel";
/**
* 公司生活費(fèi)
*/
String COMPANYREMITTANCE_DOWNXECEL = "companyremittance_downexcel";
/**
* 突擊信息
*/
String ASSAULT_DOWNXECEL = "assault_downexcel";
}控制器的調(diào)用方式:
package com.bootdo.common.controller;
import com.bootdo.common.annotation.Log;
import com.bootdo.common.config.ApplicationContextProvider;
import com.bootdo.common.service.DownExcelService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;
@Controller
@RequestMapping("/common/excel")
public class DownExcelController extends BaseController {
@Log("下載到Excel")
@RequestMapping("/downexcel")
@RequiresPermissions("common:downexcel:downexcel")
public void downexcel(HttpServletResponse response, @RequestParam Map<String, String> params) {
String type = params.get("type");
try {
DownExcelService workflowCallBackService = (DownExcelService) ApplicationContextProvider.getBean(type);
workflowCallBackService.downexcel(response, params);
} catch (Exception e) {
e.printStackTrace();
}
}
}工具類導(dǎo)出:
/**
* 下載excel
*
* @param response
* @param list
* @param status
* @param typename
* @throws Exception
*/
public static void downexcel(HttpServletResponse response, List<?> list, String status, String title, int size) throws Exception {
response.setContentType("application/vnd.ms-excel");
DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
double money = 0.0;
List<CompanyremittanceDO> colist = null;
String fileName = URLEncoder.encode(title + "信息表" , "utf-8");
response.setHeader("Content-disposition" , "attachment;fileName=" + fileName + ".xls");
// 創(chuàng)建一個(gè)輸出流
// 創(chuàng)建一個(gè)輸出流
OutputStream out = response.getOutputStream();
// 創(chuàng)建一個(gè)excel工作簿,將輸出流給我們的workbook
WritableWorkbook wb = Workbook.createWorkbook(out);
// 創(chuàng)建一個(gè)sheet(sheet名,位置)
WritableSheet sheet = wb.createSheet(title, 200);
// 設(shè)置樣式
// sheet.
sheet.getSettings().setDefaultColumnWidth(15);// 設(shè)置列寬
sheet.getSettings().setDefaultRowHeight(500);// 設(shè)置行高
// 設(shè)置字體(字體,大小,粗細(xì))只創(chuàng)建了字體,但是沒有應(yīng)用這個(gè)字體
WritableFont font = new WritableFont(WritableFont.ARIAL, 12, WritableFont.NO_BOLD);
// 將字體應(yīng)用到單元格
WritableCellFormat format = new WritableCellFormat(font);
// 設(shè)置邊框
format.setBorder(Border.ALL, BorderLineStyle.THIN);
// 設(shè)置對齊方式
format.setAlignment(Alignment.CENTRE);
// 如果內(nèi)容超出列寬,自動(dòng)換行
format.setWrap(true);
// 將內(nèi)容寫入
WritableFont font2 = new WritableFont(WritableFont.ARIAL, 30, WritableFont.BOLD);
WritableCellFormat format2 = new WritableCellFormat(font2);
format2.setAlignment(Alignment.CENTRE);
sheet.mergeCells(0, 0, size, 0);
// 創(chuàng)建一個(gè)標(biāo)簽,存放標(biāo)題title(存放的同時(shí),將title的位置和格式都存好了)
Label label = new Label(0, 0, title, format2);
// 將標(biāo)題放入到sheet中
sheet.addCell(label);
switch (status) {
case "1":
// 小標(biāo)題
sheet.addCell(new Label(0, 1, "編號" , format));
sheet.addCell(new Label(1, 1, "工作內(nèi)容" , format));
sheet.addCell(new Label(2, 1, "工作進(jìn)度" , format));
sheet.addCell(new Label(3, 1, "工作名稱" , format));
sheet.addCell(new Label(4, 1, "工作記錄人" , format));
sheet.addCell(new Label(5, 1, "工作計(jì)劃開始時(shí)間" , format));
sheet.addCell(new Label(6, 1, "工作計(jì)劃結(jié)束時(shí)間" , format));
sheet.addCell(new Label(7, 1, "分類" , format));
List<WorkPlan> dictList = (List<WorkPlan>) list;
for (int i = 0; i < dictList.size(); i++) {
sheet.addCell(new Label(0, (i + 2), i + 1 + "" , format));
sheet.addCell(new Label(1, (i + 2), dictList.get(i).getWorkmessage() + "" , format));
sheet.addCell(new Label(2, (i + 2), dictList.get(i).getWorkprogress(), format));
sheet.addCell(new Label(3, (i + 2), dictList.get(i).getWorkname() + "" , format));
sheet.addCell(new Label(4, (i + 2), dictList.get(i).getWorkthis() + "" , format));
sheet.addCell(new Label(5, (i + 2), formatDate(dictList.get(i).getWorkstartdate()) + "" , format));
sheet.addCell(new Label(6, (i + 2), formatDate(dictList.get(i).getWorkstopdate()) + "" , format));
sheet.addCell(new Label(7, (i + 2), getProjectname(dictList.get(i).getProparentid().toString()), format));
}
break;
case "2":
// 小標(biāo)題
sheet.addCell(new Label(0, 1, "編號" , format));
sheet.addCell(new Label(1, 1, "打款金額" , format));
sheet.addCell(new Label(2, 1, "打款日期" , format));
sheet.addCell(new Label(3, 1, "匯款人名稱" , format));
sheet.addCell(new Label(4, 1, "備注" , format));
sheet.addCell(new Label(5, 1, "公司名稱" , format));
sheet.addCell(new Label(6, 1, "分類" , format));
List<CompanyadvanceDO> companyadvanceDOS = (List<CompanyadvanceDO>) list;
double companyMoney = 0.0;
for (int i = 0; i < companyadvanceDOS.size(); i++) {
companyMoney += companyadvanceDOS.get(i).getCompanyMoney();
sheet.addCell(new Label(0, (i + 2), i + 1 + "" , format));
sheet.addCell(new Label(1, (i + 2), companyadvanceDOS.get(i).getCompanyMoney() + "" , format));
sheet.addCell(new Label(2, (i + 2), companyadvanceDOS.get(i).getCompanyDate(), format));
sheet.addCell(new Label(3, (i + 2), companyadvanceDOS.get(i).getCmpname(), format));
sheet.addCell(new Label(4, (i + 2), companyadvanceDOS.get(i).getDecptions() + "" , format));
sheet.addCell(new Label(5, (i + 2), companyadvanceDOS.get(i).getCompanyName() + "" , format));
sheet.addCell(new Label(6, (i + 2), getProjectname(companyadvanceDOS.get(i).getProparentId().toString()), format));
}
WritableCellFormat format3 = new WritableCellFormat(font2);
// 追加最后一行
Label label2 = new Label(0, companyadvanceDOS.size() + 2, "合計(jì):" + String.valueOf(companyMoney) + "\n\n\n\n\n" , format3);
sheet.addCell(label2);
break;
WritableCellFormat processFormat = new WritableCellFormat(font2);
// 追加最后一行
Label processLabel = new Label(0, node, "合計(jì):" + formatNumber(win).toString(), processFormat);
sheet.addCell(processLabel);
break;
}
if (status.equals("7")) {
WritableCellFormat format3 = new WritableCellFormat(font2);
// 追加最后一行
Label label2 = new Label(0, colist.size() + 2, "合計(jì):" + String.valueOf(money), format3);
sheet.addCell(label2);
}
// 關(guān)閉資源
wb.write();
wb.close();
out.flush();
out.close();
}這種方式代碼其實(shí)是比較冗余的,這也是比較老的一種方式,當(dāng)然代碼肯定還有優(yōu)化的程度,封裝公共的列名導(dǎo)出。
2,easypoi-base 方式
package com.volvo.admin.charging.provider.service.impl;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.usermodel.Workbook;
import cn.afterturn.easypoi.excel.export.styler.AbstractExcelExportStyler;
import cn.afterturn.easypoi.excel.export.styler.IExcelExportStyler;
/**
* @Description: 自定義報(bào)表導(dǎo)出樣式,可以修改表頭顏色,高度等
**/
public class ExcelExportMyStylerImpl extends AbstractExcelExportStyler implements IExcelExportStyler {
public ExcelExportMyStylerImpl(Workbook workbook) {
super.createStyles(workbook);
}
@Override
public CellStyle getTitleStyle(short color) {
CellStyle titleStyle = workbook.createCellStyle();
Font font = workbook.createFont();
font.setBold(true);// 加粗
titleStyle.setFont(font);
titleStyle.setAlignment(HorizontalAlignment.CENTER);// 居中
titleStyle.setVerticalAlignment(VerticalAlignment.CENTER);// 垂直居中
titleStyle.setFillForegroundColor(IndexedColors.AQUA.index);// 設(shè)置顏色
titleStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
titleStyle.setBorderRight(BorderStyle.THIN);
titleStyle.setWrapText(true);
return titleStyle;
}
@SuppressWarnings("deprecation")
@Override
public CellStyle stringSeptailStyle(Workbook workbook, boolean isWarp) {
CellStyle style = workbook.createCellStyle();
style.setAlignment(CellStyle.ALIGN_CENTER);
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
style.setDataFormat(STRING_FORMAT);
if (isWarp) {
style.setWrapText(true);
}
return style;
}
@Override
public CellStyle getHeaderStyle(short color) {
CellStyle titleStyle = workbook.createCellStyle();
Font font = workbook.createFont();
font.setBold(true);// 加粗
font.setColor(IndexedColors.RED.index);
font.setFontHeightInPoints((short) 11);
titleStyle.setFont(font);
titleStyle.setAlignment(HorizontalAlignment.CENTER);// 居中
titleStyle.setFillForegroundColor(IndexedColors.WHITE.index);// 設(shè)置顏色
titleStyle.setVerticalAlignment(VerticalAlignment.CENTER);// 垂直居中
titleStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
titleStyle.setBorderRight(BorderStyle.THIN);
titleStyle.setWrapText(true);
return titleStyle;
}
@SuppressWarnings("deprecation")
@Override
public CellStyle stringNoneStyle(Workbook workbook, boolean isWarp) {
CellStyle style = workbook.createCellStyle();
style.setAlignment(CellStyle.ALIGN_CENTER);
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
style.setDataFormat(STRING_FORMAT);
if (isWarp) {
style.setWrapText(true);
}
return style;
}
}導(dǎo)出工具類:
package com.volvo.admin.charging.provider.utils;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import com.volvo.admin.charging.provider.service.impl.ExcelExportMyStylerImpl;
import org.apache.poi.ss.usermodel.Workbook;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
/**
* @Version 1.0
**/
public class MyExcelExportUtil {
/**
* Excel文件導(dǎo)出,導(dǎo)出的文件名默認(rèn)為:headTitle+當(dāng)前系統(tǒng)時(shí)間
* @param listData 要導(dǎo)出的list數(shù)據(jù)
* @param pojoClass 定義excel屬性信息
* @param headTitle Excel文件頭信息
* @param sheetName Excel文件sheet名稱
* @param response
*/
public static void exportExcel(Collection<?> listData,Class<?> pojoClass, String headTitle, String sheetName, HttpServletResponse response) {
ExportParams params = new ExportParams(headTitle, sheetName);
params.setHeight((short) 8);
params.setStyle(ExcelExportMyStylerImpl.class);
try {
Workbook workbook = ExcelExportUtil.exportExcel(params, pojoClass, listData);
String fileName = headTitle + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
fileName = URLEncoder.encode(fileName, "UTF8");
response.setContentType("application/vnd.ms-excel;chartset=utf-8");
response.setHeader("Content-Disposition", "attachment;filename="+fileName + ".xls");
ServletOutputStream out=response.getOutputStream();
workbook.write(out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}service直接導(dǎo)出:
MyExcelExportUtil.exportExcel(orderResult.getRecords(),ChargeOrderBO.class,"充電訂單","充電訂單",response);
3,easyexcel 方式
pom包:
<dependency> <groupId>com.alibaba</groupId> <artifactId>easyexcel</artifactId> <version>3.1.1</version> </dependency>
service方式:
try {
try (ExcelWriter excelWriter = EasyExcelFactory.write(getOutputStream(fileName, response), ChargingPileVO.class).build()) {
WriteSheet writeSheet = EasyExcel.writerSheet("家充樁安裝記錄").build();
excelWriter.write(result, writeSheet);
}
} catch (Exception e) {
log.info("家充樁安裝導(dǎo)出excle數(shù)據(jù)異常:{}", e.getMessage());
}
/**
* 構(gòu)建輸出流
*
* @param fileName:文件名稱
* @param response:
* @return
* @throws Exception
*/
private OutputStream getOutputStream(String fileName, HttpServletResponse response) throws Exception {
fileName = URLEncoder.encode(fileName, "UTF-8");
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
return response.getOutputStream();
}實(shí)體注解:
import com.alibaba.excel.annotation.ExcelProperty;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.util.Date;
@Data
public class ChargingPileVO {
/**
* 訂單號
*/
@ExcelProperty(value = "訂單編號",index = 0)
private String orderCode;
/**
* 聯(lián)系人
*/
@ExcelProperty(value = "聯(lián)系人",index = 1)
private String userName;
/**
* 聯(lián)系號碼
*/
@ExcelProperty(value = "聯(lián)系電話",index = 2)
private String phone;
/**
* 省份
*/
@ExcelProperty(value = "省份",index = 3)
private String province;
/**
* 城市
*/
@ExcelProperty(value = "城市",index = 4)
private String city;
/**
* 地區(qū)
*/
@ExcelProperty(value = "地區(qū)",index = 5)
private String district;
/**
* 地區(qū)
*/
@ExcelProperty(value = "安裝詳細(xì)地址",index = 6)
private String contactAddress;
/**
* 地區(qū)
*/
@ExcelProperty(value = "派單供應(yīng)商",index = 7)
private String operatorId;
/**
* 地區(qū)
*/
@ExcelProperty(value = "訂單創(chuàng)建時(shí)間",index = 8)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTimes;
/**
* 地區(qū)
*/
@ExcelProperty(value = "安裝完成時(shí)間",index = 9)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date installEndTime;
/**
* 地區(qū)
*/
@ExcelProperty(value = "樁類型",index = 10)
private String pileType;
/**
* 地區(qū)
*/
@ExcelProperty(value = "狀態(tài)",index = 11)
private String orderStatus;
}4,前端導(dǎo)出
bootstrap導(dǎo)出
showExport: true,開啟 自動(dòng)可以支持多種格式導(dǎo)出
showExport: true,
exportDataType: 'all',
exportTypes:[ 'csv', 'txt', 'sql', 'doc', 'excel'], //導(dǎo)出文件類型
exportOptions:{
ignoreColumn: [0],
fileName: '工人借支',
},function load() {
$('#exampleTable')
.bootstrapTable(
{
method: 'get', // 服務(wù)器數(shù)據(jù)的請求方式 get or post
url: prefix + "/list", // 服務(wù)器數(shù)據(jù)的加載地址
showRefresh : true,
showToggle : true,
showColumns : true,
iconSize: 'outline',
toolbar: '#exampleToolbar',
striped: true, // 設(shè)置為true會(huì)有隔行變色效果
dataType: "json", // 服務(wù)器返回的數(shù)據(jù)類型
pagination: true,
// queryParamsType : "limit",
// //設(shè)置為limit則會(huì)發(fā)送符合RESTFull格式的參數(shù)
singleSelect: false, // 設(shè)置為true將禁止多選
// contentType : "application/x-www-form-urlencoded",
// //發(fā)送到服務(wù)器的數(shù)據(jù)編碼類型
pageSize: 10, // 如果設(shè)置了分頁,每頁數(shù)據(jù)條數(shù)
pageNumber: 1, // 如果設(shè)置了分布,首頁頁碼
// search : true, // 是否顯示搜索框
sidePagination: "server", // 設(shè)置在哪里進(jìn)行分頁,可選值為"client" 或者
// showFooter: true, //開啟底部
showExport: true,
//showFooter: true, //開啟底部
/* showExport: true,
exportDataType: 'all',
exportTypes:[ 'csv', 'txt', 'sql', 'doc', 'excel'], //導(dǎo)出文件類型
exportOptions:{
ignoreColumn: [0],
fileName: '工人借支',
},*/
queryParams: function (params) {
return {
// 說明:傳入后臺(tái)的參數(shù)包括offset開始索引,limit步長,sort排序列,order:desc或者,以及所有列的鍵值對
limit: params.limit,
offset: params.offset,
davacename: $('#searchName').val().replace(/(^\s*)|(\s*$)/g, ""),
years: years,
proparentId: proparentId,
};
},
// //請求服務(wù)器數(shù)據(jù)時(shí),你可以通過重寫參數(shù)的方式添加一些額外的參數(shù),例如 toolbar 中的參數(shù) 如果
// queryParamsType = 'limit' ,返回參數(shù)必須包含
// limit, offset, search, sort, order 否則, 需要包含:
// pageSize, pageNumber, searchText, sortName,
// sortOrder.
// 返回false將會(huì)終止請求
columns: [
{
field: 'id1',
checkbox: true,
align: 'left'/*,
footerFormatter: function (value) {
return "合計(jì)";
}*/
},
{
field: 'id',
title: '編號',
align: 'center',
formatter:function(value,row,index){
//return index+1; //序號正序排序從1開始
var pageSize=$('#exampleTable').bootstrapTable('getOptions').pageSize;//通過表的#id 可以得到每頁多少條
var pageNumber=$('#exampleTable').bootstrapTable('getOptions').pageNumber;//通過表的#id 可以得到當(dāng)前第幾頁
return pageSize * (pageNumber - 1) + index + 1; //返回每條的序號: 每頁條數(shù) * (當(dāng)前頁 - 1 )+ 序號
},
},
{
field: 'davacename',
title: '借支名稱',
align: 'center',
},
{
field: 'years',
title: '年份',
align: 'center',
},
{
field: 'advacedate',
title: '添加時(shí)間',
align: 'center',
},
{
field: 'sumadvance',
title: '借支總金額',
align: 'left',
formatter: function (value, row, index) {
if (row.davaceprice != undefined && row.davaceprice != "") {
return '<span class="label label-success' + '">' + row.davaceprice + ' </span>';
}
}/*,
footerFormatter: function (value) {
var count = 0;
for (var i in value) {
if (value[i].davaceprice != null) {
count += value[i].davaceprice;
}
}
return '<span class="label label-danger' + '">' + count.toFixed(2) + ' </span>';
}*/
},
{
field: 'worknote',
title: '備注',
align: 'center',
},
{
field: 'typename',
title: '分類',
align: 'center',
formatter: function (value, row, index) {
return '<span class="label label-danger' + '">' + row.typename + ' </span>';
}
},
{
field: 'id2',
title: '操作',
align: 'center',
formatter: function (value, row, index) {
var e = '<a class="btn btn-primary btn-sm ' + s_edit_h + '" href="#" mce_href="#" title="編輯" onclick="edit(\''
+ row.id
+ '\')"><i class="fa fa-edit"></i></a> ';
var d = '<a class="btn btn-warning btn-sm ' + s_remove_h + '" href="#" title="刪除" mce_href="#" onclick="remove(\''
+ row.id
+ '\')"><i class="fa fa-remove"></i></a> ';
return e + d;
},
}],
onLoadSuccess: function (data) { //加載成功時(shí)執(zhí)行
var sum_1 = 0;
for (var o in data.rows) {
var money1=(data.rows[o].davaceprice==null ||data.rows[o].davaceprice==undefined)? 0:data.rows[o].davaceprice;
sum_1 = parseFloat(sum_1) + parseFloat(money1);
}
//設(shè)計(jì)我自己的統(tǒng)計(jì)html代碼,改成gird形式!不怕寬度不夠帶來麻煩!
var myfooter = "<div id='total'> <div class='col-12 text-center ' >" +
"合計(jì):" + sum_1.toFixed(2)+
"" +
"</div></div>";
if (!$("div.fixed-table-footer").text()) //判斷是不是給隱藏了,在手機(jī)模式下style是style="display: none;"同時(shí)text是空
{
$("div.fixed-table-footer").removeAttr("style"); //取消隱藏
$("div.fixed-table-footer").attr("style", "word-break:break-all;height: auto");
}
//把自己的html寫到div.fixed-table-footer里面
$("div.fixed-table-footer").html(myfooter);
},
onLoadError: function () { //加載失敗時(shí)執(zhí)行
layer.msg("加載數(shù)據(jù)失敗", {time: 1500, icon: 2});
}
});
}采用easyexcel 方式導(dǎo)出方式比較簡單,直接用,通過注解方式實(shí)現(xiàn)導(dǎo)出。
至于導(dǎo)出特別大的數(shù)據(jù)量其實(shí)程序本身都是有性能瓶頸的,因?yàn)閹装偃f的數(shù)據(jù)直接內(nèi)存溢出了,所以對于大數(shù)據(jù)量的導(dǎo)出,可以采用異步下載,異步上傳,通過下載中心去導(dǎo)出是最好的。
一件事不管做的怎么樣,好與壞至少你都在做,把事情做到精細(xì)化那么你就是專家。
總結(jié)
到此這篇關(guān)于java導(dǎo)出到excel常用的幾種方式總結(jié)的文章就介紹到這了,更多相關(guān)java導(dǎo)出到excel內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
RestTemplate設(shè)置超時(shí)時(shí)間及返回狀態(tài)碼非200處理
這篇文章主要為大家介紹了RestTemplate設(shè)置超時(shí)時(shí)間及返回狀態(tài)碼非200處理,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-06-06
java集合類遍歷的同時(shí)如何進(jìn)行刪除操作
這篇文章主要介紹了java集合類遍歷的同時(shí)如何進(jìn)行刪除操作,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-09-09
詳解SpringMVC組件之HandlerMapping(二)
這篇文章主要介紹了詳解SpringMVC組件之HandlerMapping(二),HandlerMapping組件是Spring?MVC核心組件,用來根據(jù)請求的request查找對應(yīng)的Handler,在Spring?MVC中,有各式各樣的Web請求,每個(gè)請求都需要一個(gè)對應(yīng)的Handler來處理,需要的朋友可以參考下2023-08-08
springboot集成springsecurity 使用OAUTH2做權(quán)限管理的教程
這篇文章主要介紹了springboot集成springsecurity 使用OAUTH2做權(quán)限管理的教程,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-12-12

