首页 > 代码库 > POI 设置
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();
POI 设置
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。