乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      POI導(dǎo)出EXCEL

       荒野上的狼 2011-01-07
      package com.tkqd.util.poi;
      002   
      003 import java.io.FileNotFoundException;
      004 import java.io.FileOutputStream;
      005 import java.io.IOException;
      006   
      007 import org.apache.log4j.Logger;
      008 import org.apache.poi.hssf.usermodel.HSSFCell;
      009 import org.apache.poi.hssf.usermodel.HSSFRow;
      010 import org.apache.poi.hssf.usermodel.HSSFSheet;
      011 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
      012 import org.apache.poi.hssf.util.HSSFCellUtil;
      013 import org.apache.poi.ss.usermodel.CellStyle;
      014 import org.apache.poi.ss.usermodel.Font;
      015 import org.apache.poi.ss.util.CellRangeAddress;
      016   
      017 /**
      018  * 描述:Excel寫(xiě)操作幫助類(lèi)
      019  * @author  ALEX
      020  * @since   2010-11-24
      021  * @version 1.0v
      022  */
      023 public class ExcelUtil {
      024     private static final Logger log=Logger.getLogger(ExcelUtil.class);
      025     /**
      026      * 功能:將HSSFWorkbook寫(xiě)入Excel文件
      027      * @param   wb      HSSFWorkbook
      028      * @param   absPath 寫(xiě)入文件的相對(duì)路徑
      029      * @param   wbName  文件名
      030      */
      031     public static void writeWorkbook(HSSFWorkbook wb,String fileName){
      032         FileOutputStream fos=null;
      033         try {
      034             fos=new FileOutputStream(fileName);
      035             wb.write(fos);
      036         } catch (FileNotFoundException e) {
      037             log.error(new StringBuffer("[").append(e.getMessage()).append("]").append(e.getCause()));
      038         } catch (IOException e) {
      039             log.error(new StringBuffer("[").append(e.getMessage()).append("]").append(e.getCause()));
      040         } finally{
      041             try {
      042                 if(fos!=null){
      043                     fos.close();
      044                 }
      045             } catch (IOException e) {
      046                 log.error(new StringBuffer("[").append(e.getMessage()).append("]").append(e.getCause()));
      047             }
      048         }
      049     }
      050     /**
      051      * 功能:創(chuàng)建HSSFSheet工作簿
      052      * @param   wb  HSSFWorkbook
      053      * @param   sheetName   String
      054      * @return  HSSFSheet
      055      */
      056     public static HSSFSheet createSheet(HSSFWorkbook wb,String sheetName){
      057         HSSFSheet sheet=wb.createSheet(sheetName);
      058         sheet.setDefaultColumnWidth(12);
      059         sheet.setGridsPrinted(false);
      060         sheet.setDisplayGridlines(false);
      061         return sheet;
      062     }
      063     /**
      064      * 功能:創(chuàng)建HSSFRow
      065      * @param   sheet   HSSFSheet
      066      * @param   rowNum  int
      067      * @param   height  int
      068      * @return  HSSFRow
      069      */
      070     public static HSSFRow createRow(HSSFSheet sheet,int rowNum,int height){
      071         HSSFRow row=sheet.createRow(rowNum);
      072         row.setHeight((short)height);
      073         return row;
      074     }
      075     /**
      076      * 功能:創(chuàng)建CellStyle樣式
      077      * @param   wb              HSSFWorkbook    
      078      * @param   backgroundColor 背景色 
      079      * @param   foregroundColor 前置色
      080      * @param   font            字體
      081      * @return  CellStyle
      082      */
      083     public static CellStyle createCellStyle(HSSFWorkbook wb,short backgroundColor,short foregroundColor,short halign,Font font){
      084         CellStyle cs=wb.createCellStyle();
      085         cs.setAlignment(halign);
      086         cs.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
      087         cs.setFillBackgroundColor(backgroundColor);
      088         cs.setFillForegroundColor(foregroundColor);
      089         cs.setFillPattern(CellStyle.SOLID_FOREGROUND);
      090         cs.setFont(font);
      091         return cs;
      092     }
      093     /**
      094      * 功能:創(chuàng)建帶邊框的CellStyle樣式
      095      * @param   wb              HSSFWorkbook    
      096      * @param   backgroundColor 背景色 
      097      * @param   foregroundColor 前置色
      098      * @param   font            字體
      099      * @return  CellStyle
      100      */
      101     public static CellStyle createBorderCellStyle(HSSFWorkbook wb,short backgroundColor,short foregroundColor,short halign,Font font){
      102         CellStyle cs=wb.createCellStyle();
      103         cs.setAlignment(halign);
      104         cs.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
      105         cs.setFillBackgroundColor(backgroundColor);
      106         cs.setFillForegroundColor(foregroundColor);
      107         cs.setFillPattern(CellStyle.SOLID_FOREGROUND);
      108         cs.setFont(font);
      109         cs.setBorderLeft(CellStyle.BORDER_DASHED);
      110         cs.setBorderRight(CellStyle.BORDER_DASHED);
      111         cs.setBorderTop(CellStyle.BORDER_DASHED);
      112         cs.setBorderBottom(CellStyle.BORDER_DASHED);  
      113         return cs;
      114     }
      115     /**
      116      * 功能:創(chuàng)建CELL
      117      * @param   row     HSSFRow 
      118      * @param   cellNum int
      119      * @param   style   HSSFStyle
      120      * @return  HSSFCell
      121      */
      122     public static HSSFCell createCell(HSSFRow row,int cellNum,CellStyle style){
      123         HSSFCell cell=row.createCell(cellNum);
      124         cell.setCellStyle(style);
      125         return cell;
      126     }
      127     /**
      128      * 功能:合并單元格
      129      * @param   sheet       HSSFSheet
      130      * @param   firstRow    int
      131      * @param   lastRow     int
      132      * @param   firstColumn int
      133      * @param   lastColumn  int
      134      * @return  int         合并區(qū)域號(hào)碼
      135      */
      136     public static int mergeCell(HSSFSheet sheet,int firstRow,int lastRow,int firstColumn,int lastColumn){
      137         return sheet.addMergedRegion(new CellRangeAddress(firstRow,lastRow,firstColumn,lastColumn));    
      138     }
      139     /**
      140      * 功能:創(chuàng)建字體
      141      * @param   wb          HSSFWorkbook    
      142      * @param   boldweight  short
      143      * @param   color       short
      144      * @return  Font    
      145      */
      146     public static Font createFont(HSSFWorkbook wb,short boldweight,short color,short size){
      147         Font font=wb.createFont();
      148         font.setBoldweight(boldweight);
      149         font.setColor(color);
      150         font.setFontHeightInPoints(size);
      151         return font;
      152     }
      153     /**
      154      * 設(shè)置合并單元格的邊框樣式
      155      * @param   sheet   HSSFSheet   
      156      * @param   ca      CellRangAddress
      157      * @param   style   CellStyle
      158      */
      159     public static void setRegionStyle(HSSFSheet sheet, CellRangeAddress ca,CellStyle style) {  
      160         for (int i = ca.getFirstRow(); i <= ca.getLastRow(); i++) {  
      161             HSSFRow row = HSSFCellUtil.getRow(i, sheet);  
      162             for (int j = ca.getFirstColumn(); j <= ca.getLastColumn(); j++) {  
      163                 HSSFCell cell = HSSFCellUtil.getCell(row, j);  
      164                 cell.setCellStyle(style);  
      165             }  
      166         }  
      167     }  
      168 }

      [文件] ExcelUtil.java ~ 5KB    下載(13)

      001 package com.tkqd.util.poi;
      002   
      003 import java.io.FileNotFoundException;
      004 import java.io.FileOutputStream;
      005 import java.io.IOException;
      006   
      007 import org.apache.log4j.Logger;
      008 import org.apache.poi.hssf.usermodel.HSSFCell;
      009 import org.apache.poi.hssf.usermodel.HSSFRow;
      010 import org.apache.poi.hssf.usermodel.HSSFSheet;
      011 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
      012 import org.apache.poi.hssf.util.HSSFCellUtil;
      013 import org.apache.poi.ss.usermodel.CellStyle;
      014 import org.apache.poi.ss.usermodel.Font;
      015 import org.apache.poi.ss.util.CellRangeAddress;
      016   
      017 /**
      018  * 描述:Excel寫(xiě)操作幫助類(lèi)
      019  * @author  ALEX
      020  * @since   2010-11-24
      021  * @version 1.0v
      022  */
      023 public class ExcelUtil {
      024     private static final Logger log=Logger.getLogger(ExcelUtil.class);
      025     /**
      026      * 功能:將HSSFWorkbook寫(xiě)入Excel文件
      027      * @param   wb      HSSFWorkbook
      028      * @param   absPath 寫(xiě)入文件的相對(duì)路徑
      029      * @param   wbName  文件名
      030      */
      031     public static void writeWorkbook(HSSFWorkbook wb,String fileName){
      032         FileOutputStream fos=null;
      033         try {
      034             fos=new FileOutputStream(fileName);
      035             wb.write(fos);
      036         } catch (FileNotFoundException e) {
      037             log.error(new StringBuffer("[").append(e.getMessage()).append("]").append(e.getCause()));
      038         } catch (IOException e) {
      039             log.error(new StringBuffer("[").append(e.getMessage()).append("]").append(e.getCause()));
      040         } finally{
      041             try {
      042                 if(fos!=null){
      043                     fos.close();
      044                 }
      045             } catch (IOException e) {
      046                 log.error(new StringBuffer("[").append(e.getMessage()).append("]").append(e.getCause()));
      047             }
      048         }
      049     }
      050     /**
      051      * 功能:創(chuàng)建HSSFSheet工作簿
      052      * @param   wb  HSSFWorkbook
      053      * @param   sheetName   String
      054      * @return  HSSFSheet
      055      */
      056     public static HSSFSheet createSheet(HSSFWorkbook wb,String sheetName){
      057         HSSFSheet sheet=wb.createSheet(sheetName);
      058         sheet.setDefaultColumnWidth(12);
      059         sheet.setGridsPrinted(false);
      060         sheet.setDisplayGridlines(false);
      061         return sheet;
      062     }
      063     /**
      064      * 功能:創(chuàng)建HSSFRow
      065      * @param   sheet   HSSFSheet
      066      * @param   rowNum  int
      067      * @param   height  int
      068      * @return  HSSFRow
      069      */
      070     public static HSSFRow createRow(HSSFSheet sheet,int rowNum,int height){
      071         HSSFRow row=sheet.createRow(rowNum);
      072         row.setHeight((short)height);
      073         return row;
      074     }
      075     /**
      076      * 功能:創(chuàng)建CellStyle樣式
      077      * @param   wb              HSSFWorkbook    
      078      * @param   backgroundColor 背景色 
      079      * @param   foregroundColor 前置色
      080      * @param   font            字體
      081      * @return  CellStyle
      082      */
      083     public static CellStyle createCellStyle(HSSFWorkbook wb,short backgroundColor,short foregroundColor,short halign,Font font){
      084         CellStyle cs=wb.createCellStyle();
      085         cs.setAlignment(halign);
      086         cs.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
      087         cs.setFillBackgroundColor(backgroundColor);
      088         cs.setFillForegroundColor(foregroundColor);
      089         cs.setFillPattern(CellStyle.SOLID_FOREGROUND);
      090         cs.setFont(font);
      091         return cs;
      092     }
      093     /**
      094      * 功能:創(chuàng)建帶邊框的CellStyle樣式
      095      * @param   wb              HSSFWorkbook    
      096      * @param   backgroundColor 背景色 
      097      * @param   foregroundColor 前置色
      098      * @param   font            字體
      099      * @return  CellStyle
      100      */
      101     public static CellStyle createBorderCellStyle(HSSFWorkbook wb,short backgroundColor,short foregroundColor,short halign,Font font){
      102         CellStyle cs=wb.createCellStyle();
      103         cs.setAlignment(halign);
      104         cs.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
      105         cs.setFillBackgroundColor(backgroundColor);
      106         cs.setFillForegroundColor(foregroundColor);
      107         cs.setFillPattern(CellStyle.SOLID_FOREGROUND);
      108         cs.setFont(font);
      109         cs.setBorderLeft(CellStyle.BORDER_DASHED);
      110         cs.setBorderRight(CellStyle.BORDER_DASHED);
      111         cs.setBorderTop(CellStyle.BORDER_DASHED);
      112         cs.setBorderBottom(CellStyle.BORDER_DASHED);  
      113         return cs;
      114     }
      115     /**
      116      * 功能:創(chuàng)建CELL
      117      * @param   row     HSSFRow 
      118      * @param   cellNum int
      119      * @param   style   HSSFStyle
      120      * @return  HSSFCell
      121      */
      122     public static HSSFCell createCell(HSSFRow row,int cellNum,CellStyle style){
      123         HSSFCell cell=row.createCell(cellNum);
      124         cell.setCellStyle(style);
      125         return cell;
      126     }
      127     /**
      128      * 功能:合并單元格
      129      * @param   sheet       HSSFSheet
      130      * @param   firstRow    int
      131      * @param   lastRow     int
      132      * @param   firstColumn int
      133      * @param   lastColumn  int
      134      * @return  int         合并區(qū)域號(hào)碼
      135      */
      136     public static int mergeCell(HSSFSheet sheet,int firstRow,int lastRow,int firstColumn,int lastColumn){
      137         return sheet.addMergedRegion(new CellRangeAddress(firstRow,lastRow,firstColumn,lastColumn));    
      138     }
      139     /**
      140      * 功能:創(chuàng)建字體
      141      * @param   wb          HSSFWorkbook    
      142      * @param   boldweight  short
      143      * @param   color       short
      144      * @return  Font    
      145      */
      146     public static Font createFont(HSSFWorkbook wb,short boldweight,short color,short size){
      147         Font font=wb.createFont();
      148         font.setBoldweight(boldweight);
      149         font.setColor(color);
      150         font.setFontHeightInPoints(size);
      151         return font;
      152     }
      153     /**
      154      * 設(shè)置合并單元格的邊框樣式
      155      * @param   sheet   HSSFSheet   
      156      * @param   ca      CellRangAddress
      157      * @param   style   CellStyle
      158      */
      159     public static void setRegionStyle(HSSFSheet sheet, CellRangeAddress ca,CellStyle style) {  
      160         for (int i = ca.getFirstRow(); i <= ca.getLastRow(); i++) {  
      161             HSSFRow row = HSSFCellUtil.getRow(i, sheet);  
      162             for (int j = ca.getFirstColumn(); j <= ca.getLastColumn(); j++) {  
      163                 HSSFCell cell = HSSFCellUtil.getCell(row, j);  
      164                 cell.setCellStyle(style);  
      165             }  
      166         }  
      167     }  
      168 }

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶(hù)發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶(hù) 評(píng)論公約

        類(lèi)似文章 更多