欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

java導出到excel常用的幾種方式總結(jié)

 更新時間:2023年05月17日 14:28:02   作者:無名之輩之碼谷娃  
導出excel是咱Java開發(fā)的必備技能啦,之前項目有這個功能,現(xiàn)在將其獨立出來,分享一下,下面這篇文章主要給大家介紹了關(guān)于java導出到excel常用的幾種方式,需要的朋友可以參考下

java導出excel常用的方式使用poi apache開源方式導入導出,很多公司自己研發(fā)導出組件對于常用的導入導出其實都使用開源組件。

介紹常用的excel導出方式:

1,poi 方式

上圖一個我之前寫的很老的導出,代碼比較麻煩,但是也是比較穩(wěn)定的一個版本:

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>

定義一個下載抽象接口:

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;
}

定義一個抽象接口實現(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 {
    }
}

定義實現(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";
    /**
     * 公司生活費
     */
    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();
        }
    }
}

工具類導出:

 /**
     * 下載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)建一個輸出流
        // 創(chuàng)建一個輸出流
        OutputStream out = response.getOutputStream();
        // 創(chuàng)建一個excel工作簿,將輸出流給我們的workbook
        WritableWorkbook wb = Workbook.createWorkbook(out);
        // 創(chuàng)建一個sheet(sheet名,位置)
        WritableSheet sheet = wb.createSheet(title, 200);
        // 設(shè)置樣式
        //  sheet.
        sheet.getSettings().setDefaultColumnWidth(15);// 設(shè)置列寬
        sheet.getSettings().setDefaultRowHeight(500);// 設(shè)置行高
        // 設(shè)置字體(字體,大小,粗細)只創(chuàng)建了字體,但是沒有應用這個字體
        WritableFont font = new WritableFont(WritableFont.ARIAL, 12, WritableFont.NO_BOLD);
        // 將字體應用到單元格
        WritableCellFormat format = new WritableCellFormat(font);
        // 設(shè)置邊框
        format.setBorder(Border.ALL, BorderLineStyle.THIN);
        // 設(shè)置對齊方式
        format.setAlignment(Alignment.CENTRE);
        // 如果內(nèi)容超出列寬,自動換行
        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)建一個標簽,存放標題title(存放的同時,將title的位置和格式都存好了)
        Label label = new Label(0, 0, title, format2);
        // 將標題放入到sheet中
        sheet.addCell(label);
        switch (status) {
            case "1":
                // 小標題
                sheet.addCell(new Label(0, 1, "編號" , format));
                sheet.addCell(new Label(1, 1, "工作內(nèi)容" , 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, "工作計劃結(jié)束時間" , 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":
                // 小標題
                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, "合計:" + String.valueOf(companyMoney) + "\n\n\n\n\n" , format3);
                sheet.addCell(label2);
                break;
                WritableCellFormat processFormat = new WritableCellFormat(font2);
                // 追加最后一行
                Label processLabel = new Label(0, node, "合計:" + 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, "合計:" + String.valueOf(money), format3);
            sheet.addCell(label2);
        }
        // 關(guān)閉資源
        wb.write();
        wb.close();
        out.flush();
        out.close();
    }

 這種方式代碼其實是比較冗余的,這也是比較老的一種方式,當然代碼肯定還有優(yōu)化的程度,封裝公共的列名導出。

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: 自定義報表導出樣式,可以修改表頭顏色,高度等
 **/
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;
    }
}

導出工具類: 

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文件導出,導出的文件名默認為:headTitle+當前系統(tǒng)時間
     * @param listData 要導出的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直接導出:

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("家充樁安裝導出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();
    }

實體注解:

 
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 = "安裝詳細地址",index = 6)
    private String contactAddress;
    /**
     * 地區(qū)
     */
    @ExcelProperty(value = "派單供應商",index = 7)
    private String operatorId;
    /**
     * 地區(qū)
     */
    @ExcelProperty(value = "訂單創(chuàng)建時間",index = 8)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTimes;
    /**
     * 地區(qū)
     */
    @ExcelProperty(value = "安裝完成時間",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,前端導出

bootstrap導出

  showExport: true,開啟 自動可以支持多種格式導出

showExport: true,
 exportDataType: 'all',
 exportTypes:[ 'csv', 'txt', 'sql', 'doc', 'excel'],  //導出文件類型
 exportOptions:{
     ignoreColumn: [0],
     fileName: '工人借支',
 },
function load() {
    $('#exampleTable')
        .bootstrapTable(
            {
                method: 'get', // 服務器數(shù)據(jù)的請求方式 get or post
                url: prefix + "/list", // 服務器數(shù)據(jù)的加載地址
                showRefresh : true,
                 showToggle : true,
                 showColumns : true,
                iconSize: 'outline',
                toolbar: '#exampleToolbar',
                striped: true, // 設(shè)置為true會有隔行變色效果
                dataType: "json", // 服務器返回的數(shù)據(jù)類型
                pagination: true,
                // queryParamsType : "limit",
                // //設(shè)置為limit則會發(fā)送符合RESTFull格式的參數(shù)
                singleSelect: false, // 設(shè)置為true將禁止多選
                // contentType : "application/x-www-form-urlencoded",
                // //發(fā)送到服務器的數(shù)據(jù)編碼類型
                pageSize: 10, // 如果設(shè)置了分頁,每頁數(shù)據(jù)條數(shù)
                pageNumber: 1, // 如果設(shè)置了分布,首頁頁碼
                // search : true, // 是否顯示搜索框
                sidePagination: "server", // 設(shè)置在哪里進行分頁,可選值為"client" 或者
                // showFooter: true,  //開啟底部
                showExport: true,
                //showFooter: true,  //開啟底部
             /*   showExport: true,
                exportDataType: 'all',
                exportTypes:[ 'csv', 'txt', 'sql', 'doc', 'excel'],  //導出文件類型
                exportOptions:{
                    ignoreColumn: [0],
                    fileName: '工人借支',
                },*/
                queryParams: function (params) {
                    return {
                        // 說明:傳入后臺的參數(shù)包括offset開始索引,limit步長,sort排序列,order:desc或者,以及所有列的鍵值對
                        limit: params.limit,
                        offset: params.offset,
                        davacename: $('#searchName').val().replace(/(^\s*)|(\s*$)/g, ""),
                        years: years,
                        proparentId: proparentId,
                    };
                },
                // //請求服務器數(shù)據(jù)時,你可以通過重寫參數(shù)的方式添加一些額外的參數(shù),例如 toolbar 中的參數(shù) 如果
                // queryParamsType = 'limit' ,返回參數(shù)必須包含
                // limit, offset, search, sort, order 否則, 需要包含:
                // pageSize, pageNumber, searchText, sortName,
                // sortOrder.
                // 返回false將會終止請求
                columns: [
                    {
                        field: 'id1',
                        checkbox: true,
                        align: 'left'/*,
                     footerFormatter: function (value) {
                     return "合計";
                     }*/
                    },
                    {
                      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 可以得到當前第幾頁
                            return pageSize * (pageNumber - 1) + index + 1;    //返回每條的序號: 每頁條數(shù) * (當前頁 - 1 )+ 序號
                        },
                    },
                    {
                        field: 'davacename',
                        title: '借支名稱',
                        align: 'center',
                    },
                    {
                        field: 'years',
                        title: '年份',
                        align: 'center',
                    },
                    {
                        field: 'advacedate',
                        title: '添加時間',
                        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) {  //加載成功時執(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è)計我自己的統(tǒng)計html代碼,改成gird形式!不怕寬度不夠帶來麻煩!
                    var myfooter = "<div id='total'> <div class='col-12 text-center ' >" +
                        "合計:" + sum_1.toFixed(2)+
                        "" +
                        "</div></div>";
                    if (!$("div.fixed-table-footer").text()) //判斷是不是給隱藏了,在手機模式下style是style="display: none;"同時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 () {  //加載失敗時執(zhí)行
                    layer.msg("加載數(shù)據(jù)失敗", {time: 1500, icon: 2});
                }
            });
}

采用easyexcel 方式導出方式比較簡單,直接用,通過注解方式實現(xiàn)導出。

至于導出特別大的數(shù)據(jù)量其實程序本身都是有性能瓶頸的,因為幾百萬的數(shù)據(jù)直接內(nèi)存溢出了,所以對于大數(shù)據(jù)量的導出,可以采用異步下載,異步上傳,通過下載中心去導出是最好的。

一件事不管做的怎么樣,好與壞至少你都在做,把事情做到精細化那么你就是專家。 

總結(jié)

到此這篇關(guān)于java導出到excel常用的幾種方式總結(jié)的文章就介紹到這了,更多相關(guān)java導出到excel內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • RestTemplate設(shè)置超時時間及返回狀態(tài)碼非200處理

    RestTemplate設(shè)置超時時間及返回狀態(tài)碼非200處理

    這篇文章主要為大家介紹了RestTemplate設(shè)置超時時間及返回狀態(tài)碼非200處理,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-06-06
  • idea日志亂碼和tomcat日志亂碼問題的解決方法

    idea日志亂碼和tomcat日志亂碼問題的解決方法

    這篇文章主要介紹了idea日志亂碼和tomcat日志亂碼問題的解決方法,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-08-08
  • Java Web用戶登錄實例代碼

    Java Web用戶登錄實例代碼

    這篇文章主要介紹了Java Web用戶登錄實例代碼的相關(guān)資料,非常不錯具有參考借鑒價值,感興趣的朋友一起看看吧
    2016-05-05
  • java集合類遍歷的同時如何進行刪除操作

    java集合類遍歷的同時如何進行刪除操作

    這篇文章主要介紹了java集合類遍歷的同時如何進行刪除操作,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-09-09
  • 詳解SpringMVC組件之HandlerMapping(二)

    詳解SpringMVC組件之HandlerMapping(二)

    這篇文章主要介紹了詳解SpringMVC組件之HandlerMapping(二),HandlerMapping組件是Spring?MVC核心組件,用來根據(jù)請求的request查找對應的Handler,在Spring?MVC中,有各式各樣的Web請求,每個請求都需要一個對應的Handler來處理,需要的朋友可以參考下
    2023-08-08
  • Spring MVC框架配置方法詳解

    Spring MVC框架配置方法詳解

    這篇文章主要為大家詳細介紹了Spring MVC框架的配置方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-04-04
  • java如何實現(xiàn)樹形查詢

    java如何實現(xiàn)樹形查詢

    這篇文章主要介紹了java實現(xiàn)樹形查詢方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-07-07
  • SpringBoot讀取配置的常用方式總結(jié)

    SpringBoot讀取配置的常用方式總結(jié)

    在SpringBoot應用開發(fā)中,配置文件是不可或缺的一部分,它們幫助我們管理應用的運行時參數(shù),使得應用的部署和維護變得更加靈活,本文將介紹六種常用的SpringBoot讀取配置方式,需要的朋友跟著小編一起來看看吧
    2024-07-07
  • springboot集成springsecurity 使用OAUTH2做權(quán)限管理的教程

    springboot集成springsecurity 使用OAUTH2做權(quán)限管理的教程

    這篇文章主要介紹了springboot集成springsecurity 使用OAUTH2做權(quán)限管理的教程,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-12-12
  • mybatis-plus版本不兼容問題的解決

    mybatis-plus版本不兼容問題的解決

    本文主要介紹了mybatis-plus與spring-boot3版本不兼容導致的BeanDefinitionStoreException問題,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2024-12-12

最新評論