zoukankan      html  css  js  c++  java
  • 导出ExcelDemo

    public String exportExcel(){
    		String message=null;
    		SimpleDateFormat  df =new SimpleDateFormat("yyyy-MM-dd");
    		AdvertisementPutInList advertisementPutInList=new AdvertisementPutInList();
    		List<AdvertisementPutInList>  listAdvertisementPutInList =advertisementPutInListService.findAllList(advertisementPutInList);		
    		try {
    			WritableWorkbook wwb = null;
    			// 创建可写入的Excel工作簿
    			String fileName = "D://广告投放单.xls";
    			File file = new File(fileName);
    			if (!file.exists()) {
    				file.createNewFile();
    			}
    			//以fileName为文件名来创建一个Workbook
    			wwb = Workbook.createWorkbook(file);
    			// 创建工作表
                WritableSheet ws = wwb.createSheet("广告投放单", 0);
              //要插入到的Excel表格的行号,默认从0开始
                Label labelId= new Label(0, 0, "编号");
                Label labelAdvertiser= new Label(1, 0, "广告主名称");           
                Label labelPrice= new Label(2, 0, "投放价格(元/CPC/M)");
                Label labelAdsName= new Label(3, 0, "广告名称");
                Label labelPutType= new Label(4, 0, "投放类型(正式投放)");
                Label labelAdsStyle= new Label(5, 0, "广告形式(弹窗/富媒体(flash,JGP,GIF)");           
                Label labelAdsUrl= new Label(6, 0, "广告链接");
                Label labelPutTime= new Label(7, 0, "投放日期");
                Label labelPutTimeSlot= new Label(8, 0, "投放时间段");
                Label labelPutArea= new Label(9, 0, "投放地域");
                Label labelPutTotal= new Label(10, 0, "投放总量");
                Label labelPutAmountStyle= new Label(11, 0, "投放量形式(日/CPC/M)");
                Label labelDomainLimit= new Label(12, 0, "域名限定(客户指定/电信库)");
                Label labelDomainQuota= new Label(13, 0, "域名额度(增量/减量)");
                Label labelPlatformAccountNumber= new Label(14, 0, "平台账号");
                //Label labelPlatformPassword= new Label(15, 0, "平台密码");
                Label labelCnzzAccountNumber= new Label(15, 0, "CNZZ账号");
                //Label labelCnzzPassword= new Label(17, 0, "CNZZ密码");
                Label labelCreateBy= new Label(16, 0, "创建者");
                Label labelCreateDate= new Label(17, 0, "创建时间");
                Label labelUpdateBy= new Label(18, 0, "更新者");
                Label labelUpdateDate= new Label(19, 0, "更新时间");
                Label labelRemarks= new Label(20, 0, "备注");
                ws.addCell(labelId);
                ws.addCell(labelAdvertiser);
                ws.addCell(labelPrice);
                ws.addCell(labelPutType);
                ws.addCell(labelAdsStyle);
                ws.addCell(labelAdsUrl);
                ws.addCell(labelPutTime);
                ws.addCell(labelPutTimeSlot);
                ws.addCell(labelPutArea);
                ws.addCell(labelPutTotal);
                ws.addCell(labelPutAmountStyle);
                ws.addCell(labelDomainLimit);
                ws.addCell(labelDomainQuota);
                ws.addCell(labelPlatformAccountNumber);
                //ws.addCell(labelPlatformPassword);
                ws.addCell(labelCnzzAccountNumber);
                //ws.addCell(labelCnzzPassword);
                ws.addCell(labelCreateBy);
                ws.addCell(labelCreateDate);
                ws.addCell(labelUpdateBy);
                ws.addCell(labelUpdateDate);
                ws.addCell(labelRemarks);
                for (int i = 0; i < listAdvertisementPutInList.size(); i++) {
                	Label labelId_I= new Label(0, i+1, (i+1)+"");
                    Label labelAdvertiser_I= new Label(1, i+1, listAdvertisementPutInList.get(i).getAdvertiser());           
                    Label labelPrice_I= new Label(2, i+1, listAdvertisementPutInList.get(i).getPrice());
                    Label labelAdsName_I= new Label(3, i+1, listAdvertisementPutInList.get(i).getAdsName());
                    Label labelPutType_I= new Label(4, i+1, listAdvertisementPutInList.get(i).getPutType());
                    Label labelAdsStyle_I= new Label(5, i+1, listAdvertisementPutInList.get(i).getAdsStyle());           
                    Label labelAdsUrl_I= new Label(6, i+1, listAdvertisementPutInList.get(i).getAdsUrl());
                    Label labelPutTime_I= new Label(7, i+1, listAdvertisementPutInList.get(i).getPutTime());
                   // Label labelPutTimeSlot_I= new Label(8, i+1, listAdvertisementPutInList.get(i).getPutTimeSlot());
                    Label labelPutArea_I= new Label(9, i+1, listAdvertisementPutInList.get(i).getPutArea());
                    Label labelPutTotal_I= new Label(10, i+1, listAdvertisementPutInList.get(i).getPutTotal());
                    Label labelPutAmountStyle_I= new Label(11, i+1, listAdvertisementPutInList.get(i).getPutAmountStyle());
                    Label labelDomainLimit_I= new Label(12, i+1, listAdvertisementPutInList.get(i).getDomainLimit());
                    Label labelDomainQuota_I= new Label(13, i+1, listAdvertisementPutInList.get(i).getDomainQuota());
                    Label labelPlatformAccountNumber_I= new Label(14, i+1, listAdvertisementPutInList.get(i).getPlatformAccountNumber());
                    //Label labelPlatformPassword_I= new Label(15, i+1, listAdvertisementPutInList.get(i).getPlatformPassword());
                    Label labelCnzzAccountNumber_I= new Label(15, i+1, listAdvertisementPutInList.get(i).getCnzzAccountNumber());
                    //Label labelCnzzPassword_I= new Label(17, i+1, listAdvertisementPutInList.get(i).getCnzzPassword());
                    Label labelCreateBy_I= new Label(16, i+1, "系统管理人员");
                    Label labelCreateDate_I= new Label(17, i+1,  df.format(listAdvertisementPutInList.get(i).getCreateDate()));
                    Label labelUpdateBy_I= new Label(18, i+1, "系统管理人员");
                    Label labelUpdateDate_I= new Label(19, i+1,  df.format(listAdvertisementPutInList.get(i).getUpdateDate()));
                    Label labelRemarks_I= new Label(20, i+1, listAdvertisementPutInList.get(i).getRemarks());
                    ws.addCell(labelId_I);
                    ws.addCell(labelAdvertiser_I);
                    ws.addCell(labelPrice_I);
                    ws.addCell(labelPutType_I);
                    ws.addCell(labelAdsStyle_I);
                    ws.addCell(labelAdsUrl_I);
                    ws.addCell(labelPutTime_I);
                   // ws.addCell(labelPutTimeSlot_I);
                    ws.addCell(labelPutArea_I);
                    ws.addCell(labelPutTotal_I);
                    ws.addCell(labelPutAmountStyle_I);
                    ws.addCell(labelDomainLimit_I);
                    ws.addCell(labelDomainQuota_I);
                    ws.addCell(labelPlatformAccountNumber_I);
                    //ws.addCell(labelPlatformPassword_I);
                    ws.addCell(labelCnzzAccountNumber_I);
                    //ws.addCell(labelCnzzPassword_I);
                    ws.addCell(labelCreateBy_I);
                    ws.addCell(labelCreateDate_I);
                    ws.addCell(labelUpdateBy_I);
                    ws.addCell(labelUpdateDate_I);
                    ws.addCell(labelRemarks_I);
                }
              //写进文档
                wwb.write();
               // 关闭Excel工作簿对象
                wwb.close();
                logger.info("导出成功!");
                message="导出成功,位于 D://广告投放单.xls";                  
    		} catch (Exception e) {
    			e.printStackTrace();
    			logger.info("导出失败!"+e);
    			 message="导出失败!";
    		}
    		return message;		
    }
    

      

  • 相关阅读:
    如何选择合适的开源消息中间件
    使用Rest访问Redis中的数据
    论消息队列在分布式系统的重要性
    grub-install: warning: this GPT partition label contains no BIOS Boot Partition; embedding won’t be possible Ubuntu使用BIOS启动时, GPT分区表下安装grub2报错 的解决办法
    Linux Ubuntu 16.04 启动后 桌面崩溃
    Linux Ubuntu 1604 grub2 rescue mod 启动
    EF自动探测更改
    C# 使用OracleParameter传递参数提示缺少表达式
    Gitlab安装后 500 错误 PostGre数据库无法启动
    DevExpress GridControl GridView多选状态下,代码赋值FocusedRowHandle,样式无变化
  • 原文地址:https://www.cnblogs.com/ipetergo/p/7249539.html
Copyright © 2011-2022 走看看