zoukankan      html  css  js  c++  java
  • POI 设置

      

    1.               FileOutputStream fos = new FileOutputStream("D:\15.xls");  
    2.   
    3. HSSFWorkbook wb = new HSSFWorkbook();  
    4.   
    5. /** 
    6.  * ======================================================== 
    7.  *                          设置cell宽度 
    8.  *  通过sheet 对象,setColumnWidth设置cell的宽度 
    9.  * ======================================================== 
    10.  */  
    11. HSSFSheet sheet = wb.createSheet("sheet1");  
    12. // api 段信息 Set the width (in units of 1/256th of a character width)  
    13. sheet.setColumnWidth(0, 20 * 256);  
    14.   
    15. /** 
    16.  * ======================================================== 
    17.  *                          设置行高度 
    18.  *  通过row 对象设置行高 
    19.  * ======================================================== 
    20.  */  
    21. HSSFRow row = sheet.createRow(0);  
    22. //heightInPoints 设置的值永远是height属性值的20倍  
    23. row.setHeightInPoints(20);  
    24.   
    25. HSSFRow row1 = sheet.createRow(5);  
    26. // Set the row's height or set to ff (-1) for undefined/default-height.  
    27. // Set the height in "twips" or  
    28. // 1/20th of a point.  
    29. row1.setHeight((short) (25 * 20));  
    30.   
    31. HSSFCell cell = row.createCell(0);  
    32.   
    33. cell.setCellValue("a1b2c3d4e5f6g7h8i9");  
    34.   
    35. //设置默认宽度、高度值          
    36. HSSFSheet sheet2 =  wb.createSheet("sheet2");  
    37.           
    38. sheet2.setDefaultColumnWidth(20);  
    39. sheet2.setDefaultRowHeightInPoints(20);  
    40.   
    41.               //格式化单元格日期信息  
    42. HSSFDataFormat dataFormat =  wb.createDataFormat();  
    43. short dataformat = dataFormat.getFormat("yyyy-mm-dd HH:MM");  
    44. HSSFCellStyle style = wb.createCellStyle();  
    45.   
    46.   
    47. style.setDataFormat(dataformat);  
    48.   
    49.   
    50. HSSFCell cell2 = sheet2.createRow(0).createCell(0);  
    51.   
    52. cell2.setCellValue(new Date());  
    53.   
    54. cell2.setCellStyle(style);  
    55.   
    56. wb.write(fos);  
    57.   
    58. fos.close();  
  • 相关阅读:
    汇编语言 第三章 寄存器
    汇编语言 第二章
    实验一 查看CPU和内存,用机器指令和汇编指令教程
    nginx的log、upstream和server
    高并发情况下Linux系统及kernel参数优化
    二进制方式安装docker(非root用户启动docker)
    redis
    redis配置文件详解
    Keepalived+LVS实现LNMP网站的高可用部署
    Nginx location相关配置说明
  • 原文地址:https://www.cnblogs.com/PMlog/p/5996078.html
Copyright © 2011-2022 走看看