Apache POI 设置宽度和行高

 

       FileOutputStream fos = new FileOutputStream("D:\\15.xls");
 
        HSSFWorkbook wb = new HSSFWorkbook();
 
        /**
         * ========================================================
         *                             设置cell宽度
         *  通过sheet 对象,setColumnWidth设置cell的宽度
         * ========================================================
         */
        HSSFSheet sheet = wb.createSheet("sheet1");
        // api 段信息 Set the width (in units of 1/256th of a character width)
        sheet.setColumnWidth(0, 20 * 256);
 
        /**
         * ========================================================
         *                             设置行高度
         *  通过row 对象设置行高
         * ========================================================
         */
        HSSFRow row = sheet.createRow(0);
        //heightInPoints 设置的值永远是height属性值的20倍
        row.setHeightInPoints(20);
 
        HSSFRow row1 = sheet.createRow(5);
        // Set the row's height or set to ff (-1) for undefined/default-height.
        // Set the height in "twips" or
        // 1/20th of a point.
        row1.setHeight((short) (25 * 20));
        
        HSSFCell cell = row.createCell(0);
 
        cell.setCellValue("a1b2c3d4e5f6g7h8i9");
 
        //设置默认宽度、高度值        
        HSSFSheet sheet2 =  wb.createSheet("sheet2");
                
        sheet2.setDefaultColumnWidth(20);
        sheet2.setDefaultRowHeightInPoints(20);
 
                //格式化单元格日期信息
        HSSFDataFormat dataFormat =  wb.createDataFormat();
        short dataformat = dataFormat.getFormat("yyyy-mm-dd HH:MM");
        HSSFCellStyle style = wb.createCellStyle();
        
        
        style.setDataFormat(dataformat);
        
        
        HSSFCell cell2 = sheet2.createRow(0).createCell(0);
        
        cell2.setCellValue(new Date());
        
        cell2.setCellStyle(style);
        
        wb.write(fos);
 
        fos.close();


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值