PHP with JavaBridge:POI设置自定义背景颜色

时间:2013-09-22 15:52:36

标签: apache-poi php-java-bridge poi-hssf hssf

任何人都可以找到代码的错误吗?

  $workbook = new java("org.apache.poi.hssf.usermodel.HSSFWorkbook");
  $cellStyle = $workbook->createCellStyle();

  $palette = $this->workbook->getCustomPalette();
  $palette->setColorAtIndex(0x40, 0, 102, 204);
  $backGroundColor = $palette->getColor(0x40); 

  $cellStyle->setFillForegroundColor($backGroundColor->getIndex());
  ...
  $cell->setCellStyle($cellStyle);

此代码不会更改背景颜色

无论如何

  $cellStyle->setFillForegroundColor(0xc); // 0xc is index of blue
  $cellStyle->setFillBackgroundColor(0xc); 

既不起作用

1 个答案:

答案 0 :(得分:2)

setFillForegroundColor不执行任何操作

$ cellStyle-> setFillPattern(1);

用前景色填充单元格。

http://poi.apache.org/apidocs/org/apache/poi/hssf/usermodel/HSSFCellStyle.html#setFillPattern%28short%29

相关问题