poi excel 设置边框字体行高行宽

 
 

     final HSSFSheet sheet = wb.createSheet(sheetName + "_" + n);   

     System.out.println("sheetName" + sheetName + "_" + n);    

    sheet.setDefaultColumnWidth(12);

 
 

   // 第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制    

    HSSFRow row;


final
HSSFCellStyle headerStyle = wb.createCellStyle(); headerStyle.setAlignment(CellStyle.ALIGN_CENTER); // 水平居中 headerStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);// 垂直居中 final Font fontStyle = wb.createFont(); // 字体样式 fontStyle.setBoldweight(Font.BOLDWEIGHT_BOLD); // 加粗 fontStyle.setFontName("黑体"); // 字体 fontStyle.setFontHeightInPoints((short) 11); // 大小 // 将字体样式添加到单元格样式中 headerStyle.setFont(fontStyle); // 边框 headerStyle.setBorderBottom(CellStyle.BORDER_THIN); headerStyle.setBorderLeft(CellStyle.BORDER_THIN); headerStyle.setBorderRight(CellStyle.BORDER_THIN); headerStyle.setBorderTop(CellStyle.BORDER_THIN); // 普通单元格样式,边框,水平居中 final HSSFCellStyle cellStyle = wb.createCellStyle(); cellStyle.setAlignment(CellStyle.ALIGN_CENTER); // 水平居中 cellStyle.setBorderBottom(CellStyle.BORDER_THIN); cellStyle.setBorderLeft(CellStyle.BORDER_THIN); cellStyle.setBorderRight(CellStyle.BORDER_THIN); // cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); final HSSFDataFormat df = wb.createDataFormat(); // 此处设置数据格式 cellStyle.setDataFormat(df.getFormat("#,#0.0")); // 小数点后保留两位,可以写contentStyle.setDataFormat(df.getFormat("#,#0.00")); // 声明列对象
      HSSFCell cell = null;
      cell = row.createCell(1);
      cell.setCellStyle(headerStyle);
       // cell.setCellStyle(cellStyle);

猜你喜欢

转载自www.cnblogs.com/pu20065226/p/9808993.html
今日推荐