颜色可以,可以设置style的
字体没试过,估计也可以
我以前写的,参考看看
look

解决方案 »

  1.   

    呵呵 谢谢啦,我就像title设置一个颜色、字体,其他内容设置一个颜色、字体。可能现在是设置一下就是全局的,设置两次的话,前面的会被后面的覆盖。苦恼啊。
      

  2.   

    那就设置两个style嘛,不要用一个 啊
      

  3.   

    以下代码为XSL文件Sheet1页第2行第1列设置特定的填充色、字体和字色 POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(
    fileName));
    HSSFWorkbook resourceFile = new HSSFWorkbook(fs);
    HSSFSheet shOrg = resourceFile.getSheet("Sheet1");
    if (shOrg == null) {
    return;
    }
    HSSFRow curRow = shOrg.getRow(1); //取XSL文件Sheet1页上第2行
    HSSFCell curCell = curRow.getCell(0); //第1列
    HSSFCellStyle cellStyle = resourceFile.createCellStyle();

    cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);  //填充单元格
    cellStyle.setFillForegroundColor(HSSFColor.DARK_RED.index); //填暗红色
        Font font = resourceFile.createFont();
        font.setFontHeightInPoints((short)24); //字体大小
        font.setFontName("楷体");
        font.setBoldweight(Font.BOLDWEIGHT_BOLD); //粗体
        font.setColor(HSSFColor.GREEN.index); //绿字
        cellStyle.setFont(font);
        curCell.setCellStyle(cellStyle);     // 另存文件
    String outputFileName = "resource1.xls";
    FileOutputStream stream;
    stream = new FileOutputStream(new File(outputFileName));
    resourceFile.write(stream);
    stream.close();
      

  4.   

    楼上已经给出了,像 cellStyle, font 等对象只要创建一次就可以了,并不需要每个单元格去创建一个对象,否则话会样式太多,Excel 会报错。
      

  5.   

    像 cellStyle, font 等对象只要创建一次就可以了,并不需要每个单元格去创建一个对象,否则话会样式太多,Excel 会报错。
      

  6.   

    创建一次的cellStyle, font对象就可以了
      

  7.   

                         HSSFWorkbook workbook = new HSSFWorkbook();
                         HSSFCellStyle cellStyle = workbook.createCellStyle(); //设置单元格样式
         //生成新的字体
         HSSFFont fonts = workbook.createFont();
         
         fonts.setFontHeightInPoints(font.getFontHeightInPoints()); //设置字体大小
         fonts.setColor(font.getColor());  //设置字体颜色
         fonts.setFontName(font.getFontName()); //设置子是什么字体(如宋体)
         fonts.setBoldweight(font.getBoldweight()); //设置粗体 
         
         cellStyle.setFont(fonts);//将字体样式设置给单元格