EXCEL导出

    public void downSatisfactionsExcel() throws IOException {
        var loginUser = getLoginUser();
        var response = ServletActionContext.getResponse();
        if (StringUtils.containsIgnoreCase(loginUser.getRoles(), "mailManager")) {
            var searchStr = getRequest().getParameter("searchStr");
            var beginDate = getRequest().getParameter("beginDate");
            var endDate = getRequest().getParameter("endDate");
            var region = getRequest().getParameter("region");
            var emailSubjectType = getRequest().getParameter("emailSubjectType");
            //var emailSubTitle = getRequest().getParameter("emailSubTitle");
            var bs = customerStatisticalService.findStatisticalsForExcel(beginDate, endDate, searchStr, region, emailSubjectType);
            if (bs != null) {
                response.addHeader("Content-Disposition", "attachment;filename=StatisticalEmailExcel.xlsx");
                response.setContentType("application/vnd.ms-excel;charset=UTF-8");
                response.setContentLength(bs.length);
                response.getOutputStream().write(bs);
            } else {
                response.setStatus(404);
            }
        }
    }
public byte[] findStatisticalsForExcel(String beginDate, String endDate, String searchStr, String region, String emailSubjectType) {
        var statisticals = customerStatisticalMapper.findStatisticalsForExcel(beginDate, endDate, searchStr, region, emailSubjectType);
        if (statisticals != null && statisticals.size() > 0) {
            try {
                File temp = File.createTempFile("statisticalsTempFile", ".xlsx");
                FileOutputStream os = new FileOutputStream(temp);
                XSSFWorkbook xssfWorkbook = new XSSFWorkbook();
                Sheet sheet1 = xssfWorkbook.createSheet();

                XSSFColor ssheet2TitleColor = new XSSFColor(new Color(101,72,139));
                XSSFColor sheet2ProColor = new XSSFColor(new Color(255,255,255));
                XSSFColor proBorderColor = new XSSFColor(new Color(216,216,216));
                //XSSFColor sheet2ProColor_1_2 = new XSSFColor(new Color(242,237,249));

                XSSFFont sheet2FontLable = xssfWorkbook.createFont();
                sheet2FontLable.setFontHeightInPoints((short)11);
                sheet2FontLable.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
                sheet2FontLable.setColor(HSSFColor.WHITE.index);
                sheet2FontLable.setFontName("Arial");

                XSSFFont sheet2FontPro = xssfWorkbook.createFont();
                sheet2FontPro.setFontHeightInPoints((short) 9);
                sheet2FontPro.setFontName("Arial");

                XSSFCellStyle styleLable1Sheet2 = xssfWorkbook.createCellStyle();
                styleLable1Sheet2.setFillForegroundColor(ssheet2TitleColor);
                styleLable1Sheet2.setBorderTop(CellStyle.BORDER_THIN);
                styleLable1Sheet2.setBorderLeft(CellStyle.BORDER_THIN);
                styleLable1Sheet2.setBorderRight(CellStyle.BORDER_THIN);
                styleLable1Sheet2.setBorderBottom(CellStyle.BORDER_THIN);
                styleLable1Sheet2.setLeftBorderColor(sheet2ProColor);
                styleLable1Sheet2.setRightBorderColor(sheet2ProColor);
                styleLable1Sheet2.setAlignment(XSSFCellStyle.ALIGN_LEFT);
                styleLable1Sheet2.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
                styleLable1Sheet2.setFillPattern(CellStyle.SOLID_FOREGROUND);
                styleLable1Sheet2.setFont(sheet2FontLable);


                XSSFCellStyle styleProSheet212 = xssfWorkbook.createCellStyle();
                styleProSheet212.setBorderTop((short) 1);
                styleProSheet212.setBorderLeft((short) 1);
                styleProSheet212.setBorderRight((short) 1);
                styleProSheet212.setBorderBottom((short) 1);
                styleProSheet212.setBottomBorderColor(proBorderColor);
                styleProSheet212.setTopBorderColor(proBorderColor);
                styleProSheet212.setLeftBorderColor(proBorderColor);
                styleProSheet212.setRightBorderColor(proBorderColor);
                styleProSheet212.setAlignment(XSSFCellStyle.ALIGN_LEFT);  //ALIGN_CENTER
                styleProSheet212.setFillForegroundColor(sheet2ProColor); //sheet2ProColor_1_2
                styleProSheet212.setFillPattern(CellStyle.SOLID_FOREGROUND);
                styleProSheet212.setFont(sheet2FontPro);

                Row rowTitle = sheet1.createRow(0);
                rowTitle.createCell(0).setCellValue("cus_email");
                rowTitle.createCell(1).setCellValue("load_date");
                rowTitle.createCell(2).setCellValue("country");
                rowTitle.createCell(3).setCellValue("catalog_no");
                rowTitle.createCell(4).setCellValue("web_url_site");
                rowTitle.createCell(5).setCellValue("load_event");
                rowTitle.createCell(6).setCellValue("click_event");
                rowTitle.createCell(7).setCellValue("dropdown_event");
                rowTitle.createCell(8).setCellValue("close_event");
                rowTitle.createCell(9).setCellValue("statistical_duration");
                rowTitle.setHeight((short) 400);

                for (int i = 0; i < 10; i++) {
                    Cell cell = rowTitle.getCell(i);
                    cell.setCellStyle(styleLable1Sheet2);
                    if (i == 0 || i == 4) {
                        sheet1.setColumnWidth(cell.getColumnIndex(), 255 * 40 + 500);
                    } else if (i == 8) {
                        sheet1.setColumnWidth(cell.getColumnIndex(), 255 * 100 + 500);
                    } else {
                        sheet1.setColumnWidth(cell.getColumnIndex(), 255 * 20 + 256);
                    }
                }

                for (int j = 1; j <= statisticals.size(); j++) {
                    StatisticalInfo sf = statisticals.get(j - 1);
                    Row rowInfo = sheet1.createRow(j);
                    rowInfo.createCell(0).setCellValue(sf.getCusEmail());
                    rowInfo.createCell(1).setCellValue(sf.getLoadDate());
                    rowInfo.createCell(2).setCellValue(sf.getCountryType());
                    rowInfo.createCell(3).setCellValue(sf.getCatalogNo());
                    rowInfo.createCell(4).setCellValue(sf.getWebUrlSite());
                    rowInfo.createCell(5).setCellValue(sf.getLoadEvent());
                    rowInfo.createCell(6).setCellValue(sf.getClickEvent());
                    rowInfo.createCell(7).setCellValue(sf.getDropdownEvent());
                    rowInfo.createCell(8).setCellValue(sf.getCloseEvent());
                    rowInfo.createCell(9).setCellValue(sf.getStatisticalDuration());

                    for (int i = 0; i < 10; i++) {
                        Cell cell = rowInfo.getCell(i);
                        cell.setCellStyle(styleProSheet212);
                    }
                }

                xssfWorkbook.write(os);
                os.flush();
                os.close();
                FileInputStream intstream = new FileInputStream(temp);
                ByteArrayOutputStream output = new ByteArrayOutputStream();
                byte[] buffer = new byte[4096];
                int i = 0;
                while ((i = intstream.read(buffer)) > 0) {
                    output.write(buffer, 0, i);
                }
                return output.toByteArray();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return null;
    }

TS:

    downStatisticalEmailExcel = () => {
        let that = this as any;
        that.loading = true;
        let a = document.createElement('a');
        a.href =  "/pro-seo-statiscal/down-seo-Statistical-excel.html?"
            + "beginDate=" + this.beginDate()
            + "&endDate=" + this.endDate()
            + "&searchStr=" + this.searchStr()
            + "&sourceType=" + this.sourceType();
        document.body.appendChild(a);
        a.click();
        document.body.removeChild(a);
        setTimeout(async () => {
            that.loading = false;
        }, 4000);
    }

html

 <a href="#" data-bind="click: $root.downStatisticalEmailExcel"><b>[Exporting Statistics]</b></a>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值