封装ZIP包下载文件excel

    struts下载文件配置
  <struts>
<package name="yuyue" extends="cic" namespace="/yuyue">
       <action name="download" class="yuYueAction" method="download">
        <result name="export" type="stream">
        <param name="contentType">application/vnd.ms-excel;charset=UTF-8</param>
<param name="inputName">inputStream</param>
  <param name="contentDisposition">attachment;filename=${xlsName}.zip</param>
    <param name="bufferSize">20480</param>
        </result>
        <result name ="reSendUrl" type="redirect">${requestUrl}</result>
        </action>
</package>
 </struts>
 
 
 /**
* 下载文件excel
* @return
*/
public String download(){
QueryRule queryRule  = QueryRule.getInstance();
boolean flag = true;
if(queryModel!=null){
if(StringUtils.isNotEmpty(queryModel.getProductCode())){
queryRule.addEqual("productCode", queryModel.getProductCode());
}else if(StringUtils.isNotEmpty(queryModel.getProductType())){
                if(("card").equals(queryModel.getProductType())){
                    queryRule.addIn("productCode", "trafficjd","trafficzg","trafficzg","children");
                }else{
                    queryRule.addIn("productCode", "chexian","xueping");
                }
            }
if(StringUtils.isNotBlank(queryModel.getBusinessName()) || StringUtils.isNotBlank(queryModel.getBusinessPhone())){
List<String> businessCodeList = yuYueService.getBusinessCode(queryModel.getBusinessName(),queryModel.getBusinessPhone());
if(businessCodeList==null || businessCodeList.size()<1){
flag = false;
}
}
if(queryModel.getDate1()!=null){
queryRule.addGreaterEqual("createDate",queryModel.getDate1());
}
if(queryModel.getDate2()!=null){
queryRule.addLessEqual("createDate", queryModel.getDate2());
}
}
queryRule.addDescOrder("createDate");

List<YzYuyueInfo> reportList = null;
if(flag){
reportList = yuYueService.getAllByQueryRule(queryRule);
}else {
return null;
}

Date sysTime = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("MMddhhmmss");
        xlsName = "预约投保-"+sdf.format(sysTime);
//第一步,创建一个webbook,对应一个Excel文件
        HSSFWorkbook hwk = new HSSFWorkbook();
        //第二步,在webbook中添加一个sheet,对应Excel文件中的sheet
        HSSFSheet sheet = hwk.createSheet(xlsName);
        sheet.setColumnWidth(0, 7*257);
        sheet.setColumnWidth(1, 30*257);
        sheet.setColumnWidth(2, 25*257);
        sheet.setColumnWidth(3, 20*257);
        sheet.setColumnWidth(4, 25*257);
        sheet.setColumnWidth(5, 25*257);
        sheet.setColumnWidth(6, 30*257);
        sheet.setColumnWidth(7, 40*257);
        sheet.setColumnWidth(8, 25*257);
        sheet.setColumnWidth(9, 25*257);
        sheet.setColumnWidth(10, 20*257);
        sheet.setColumnWidth(11, 25*257);
      //第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short
        HSSFRow rowx = sheet.createRow(0);
        HSSFRow row = sheet.createRow(1);
        row.setHeight((short)500);
        rowx.setHeight((short)500);
      //第四步,创建单元格,并设置值表头  设置表头居中
        HSSFCellStyle titleStyle =hwk.createCellStyle();
        HSSFCellStyle style =hwk.createCellStyle();
        HSSFFont hf = hwk.createFont();
        hf.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        hf.setFontHeightInPoints((short)12);
        titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        style.setWrapText(true);
        style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        style.setBorderRight(HSSFCellStyle.BORDER_THIN);
        style.setBorderTop(HSSFCellStyle.BORDER_THIN);
        
        HSSFCell hcl = rowx.createCell(1);
        hcl.setCellValue("预约投保提交日期");
        hcl.setCellStyle(titleStyle);
        
        
        titleStyle.setFont(hf);
        HSSFCell hc = row.createCell(0);
        hc.setCellValue("序号");
        hc.setCellStyle(titleStyle);
        
        hc = row.createCell(1);
        hc.setCellValue("预约编号");
        hc.setCellStyle(titleStyle);
        
        hc = row.createCell(2);
        hc.setCellValue("产品");
        hc.setCellStyle(titleStyle);
        
        hc = row.createCell(3);
        hc.setCellValue("提交日期");
        hc.setCellStyle(titleStyle);
        
        hc = row.createCell(4);
        hc.setCellValue("客户姓名");
        hc.setCellStyle(titleStyle);
        
        hc = row.createCell(5);
        hc.setCellValue("客户联系方式");
        hc.setCellStyle(titleStyle);
        
        hc = row.createCell(6);
        hc.setCellValue("配送地址");
        hc.setCellStyle(titleStyle);
        
        hc = row.createCell(7);
        hc.setCellValue("业务员姓名");
        hc.setCellStyle(titleStyle);
        
        hc = row.createCell(8);
        hc.setCellValue("业务员联系方式");
        hc.setCellStyle(titleStyle);
        
        hc = row.createCell(9);
        hc.setCellValue("备注");
        hc.setCellStyle(titleStyle);
        
        
        //第五步,写入实体数据 实际应用中这些数据从数据库得到
        int rowNum = 1;
        int rownum = 0;
        for(YzYuyueInfo yzYuyueInfo : reportList){
        rowNum++;
        rownum++;
    row = sheet.createRow(rowNum);
    row.setHeight((short)500);
   
    hc = row.createCell(0);
    hc.setCellValue(rownum);
    hc.setCellStyle(style);
   
    hc = row.createCell(1);
    hc.setCellValue(yzYuyueInfo.getSerialno() + "");
    hc.setCellStyle(style);
   
    hc = row.createCell(2);
    hc.setCellValue(yzYuyueInfo.getProductName() + "");
    hc.setCellStyle(style);
   
    hc = row.createCell(3);
    hc.setCellValue(yzYuyueInfo.getCreateDate() + "");
    hc.setCellStyle(style);
   
    String contactName = "";
String contactPhone = "";
String contactAddress = "";
if(yzYuyueInfo.getYuyueInsureList()!=null){
for(YzYuyueInsured insured : yzYuyueInfo.getYuyueInsureList()){
if(("01").equals(insured.getInsuredType())){//联系人
contactName = insured.getName();
contactPhone = insured.getPhone();
contactAddress = insured.getAddress();
}
}
}
   
    hc = row.createCell(4);
    hc.setCellValue(contactName + "");
    hc.setCellStyle(style);
   
    hc = row.createCell(5);
    hc.setCellValue(contactPhone + "");
    hc.setCellStyle(style);
   
    hc = row.createCell(6);
    hc.setCellValue(contactAddress + "");
    hc.setCellStyle(style);
   
    hc = row.createCell(7);
    if (yzYuyueInfo.getYuyueBusiness() != null) {
    hc.setCellValue(yzYuyueInfo.getYuyueBusiness().getBusinessName() + "");
}else {
hc.setCellValue("");
}
    hc.setCellStyle(style);
   
    hc = row.createCell(8);
    if (yzYuyueInfo.getYuyueBusiness() != null) {
    hc.setCellValue(yzYuyueInfo.getYuyueBusiness().getMobile() + "");
}else {
hc.setCellValue("");
}
    hc.setCellStyle(style);
   
    hc = row.createCell(9);
    hc.setCellValue(yzYuyueInfo.getDes() + "");
    hc.setCellStyle(style);
   
        }
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ZipOutputStream zipStream = new ZipOutputStream(baos); // 压缩xls文件的流
        ZipEntry entry = new ZipEntry(xlsName + ".xls");
        byte[] byteArray = null;
        try {
        zipStream.putNextEntry(entry);
       
        ByteArrayOutputStream writeToBytes = new ByteArrayOutputStream();//将HSSFWorkbook读到内存中
            hwk.write(writeToBytes);
            byte[] bytes = writeToBytes.toByteArray();
            writeToBytes.close();
            
            zipStream.write(bytes);
            zipStream.close(); // 关闭压缩流
            
            byteArray = baos.toByteArray();
            baos.close();
            inputStream = new ByteArrayInputStream(byteArray);
            
        } catch (IOException e) {
        e.printStackTrace();
        }
        try {
xlsName= new String(xlsName.getBytes(), "ISO8859-1");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return "export";
}
    
    
零件封装是指实际零件焊接到电路板时所指示的外观和焊点的位置。是纯粹的空间概念.因此不同的元件可共用同一零件封装,同种元件也可有不同的零件封装。像电阻,有传统的针插式,这种元件体积较大,电路板必须钻孔才能安置元件,完成钻孔后,插入元件,再过锡炉或喷锡(也可手焊),成本较高,较新的设计都是采用体积小的表面贴片式元件(SMD)这种元件不必钻孔,用钢膜将半熔状锡膏倒入电路板,再把SMD元件放上,即可焊接在电路板上了。 电阻 AXIAL 无极性电容 RAD 电解电容 RB- 电位器 VR 二极管 DIODE 三极管 TO 电源稳压块78和79系列 TO-126H和TO-126V 场效应管 和三极管一样 整流桥 D-44 D-37 D-46 单排多针插座 CON SIP 双列直插元件 DIP 晶振 XTAL1 电阻:RES1,RES2,RES3,RES4;封装属性为axial系列 无极性电容:cap;封装属性为RAD-0.1到rad-0.4 电解电容:electroi;封装属性为rb.2/.4到rb.5/1.0 电位器:pot1,pot2;封装属性为vr-1到vr-5 二极管:封装属性为diode-0.4(小功率)diode-0.7(大功率) 三极管:常见的封装属性为to-18(普通三极管)to-22(大功率三极管)to-3(大功率达林 顿管) 电源稳压块有78和79系列;78系列如7805,7812,7820等 79系列有7905,7912,7920等 常见的封装属性有to126h和to126v 整流桥:BRIDGE1,BRIDGE2: 封装属性为D系列(D-44,D-37,D-46) 电阻: AXIAL0.3-AXIAL0.7  其中0.4-0.7指电阻的长度,一般用AXIAL0.4 瓷片电容:RAD0.1-RAD0.3。  其中0.1-0.3指电容大小,一般用RAD0.1 电解电容:RB.1/.2-RB.4/.8 其中.1/.2-.4/.8指电容大小。一般470uF用RB.3/.6 二极管: DIODE0.4-DIODE0.7 其中0.4-0.7指二极管长短,一般用DIODE0.4 发光二极管:RB.1/.2 集成块: DIP8-DIP40, 其中8-40指有多少脚,8脚的就是DIP8 贴片电阻 0603表示的是封装尺寸 与具体阻值没有关系 但封装尺寸与功率有关 通常来说 0201 1/20W 0402 1/16W 0603 1/10W 0805 1/8W 1206 1/4W 电容电阻外形尺寸与封装的对应关系是: 0402=1.0x0.5 0603=1.6x0.8 0805=2.0x1.2 1206=3.2x1.6 1210=3.2x2.5 1812=4.5x3.2 2225=5.6x6.5
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值