JAVA技巧:poi操作excel-中文与单元格样式的方法
来源:优易学  2011-9-22 10:43:17   【优易学:中国教育考试门户网】   资料下载   IT书店

  /*调用方式*/
  /*设置整体excel单元格格式*/
  FileOutputStream fos = null;
  try {
  fos = new FileOutputStream(rptRealPathAndName);
  } catch (FileNotFoundException e) {
  // TODO Auto-generated catch block
  //System.out.println("创建文件失败。。。");
  log.info("In WriteRptByType.writeRptTypeFive(),create file failed!!!");
  log.error(e.getMessage());
  //e.printStackTrace();
  return -1;
  }
  HSSFWorkbook workBook = new HSSFWorkbook();
  HSSFSheet sheet = workBook.createSheet();;
  workBook.setSheetName(0,"移动",HSSFWorkbook.ENCODING_UTF_16);
  HSSFCellStyle cellStyleHdr = FontCellStyle.getAnyCellStyle(workBook,FontCellStyle.getHdrFont(workBook),HSSFCellStyle.ALIGN_CENTER, HSSFCellStyle.VERTICAL_CENTER, (short)-1, true);
  HSSFRow curRow = sheet.createRow(0);
  HSSFCell curCell= curRow.createCell((short)0);
  curCell.setEncoding(HSSFCell.ENCODING_UTF_16);
  curCell.setCellStyle(cellStyleHdr );
  curCell.setCellValue("可以写入汉字,无乱码");
  /*.............写入文件.............*/
  try {
  workBook.write(fos);
  fos.close();
  } catch (IOException e) {
  // TODO Auto-generated catch block
  //System.out.println("写错误。。。");
  succFlag = -1;
  log.error("报表写错误:"+e.getMessage());
  //e.printStackTrace();

上一页  [1] [2] [3] 

责任编辑:小草

文章搜索:
 相关文章
热点资讯
资讯快报
热门课程培训