我正在使用PHPExcel lib来阅读电子表格。使用xlsx和xls文件,它可以正常工作,但不能使用ods和ots。
我正在尝试获取单元格的背景颜色但是使用ods文件我总是得到FFFFF
而不是实际的单元格颜色。
以下是我正在处理的代码:
$cantCOL = 5;
try {
//file route
$rutaArchivo = $_FILES["archivo"]["tmp_name"];
//phpExcel Reader
$objReader = PHPExcel_IOFactory::createReaderForFile($rutaArchivo);
//ReadDataOnly false, to get cell color
$objReader->setReadDataOnly(false);
//load spreedsheet from file route
$objLibro = $objReader->load($rutaArchivo);
//set the active sheet
$objLibro->setActiveSheetIndex(0);
//get last row number
$n = $objHoja->getHighestRow();
//Loop through the rows
for ($fila = 1; $fila <= $n; $fila++) {
//Loop through the columns
for($col = 0; $col < $cantCOL+2; $col++){
$columnLetter = PHPExcel_Cell::stringFromColumnIndex($col);
//get the cell color, RGB format
$cellColor = $objLibro->getActiveSheet()->getStyle($columnLetter.$fila)
->getFill()
->getStartColor()
->getRGB();
if($cellColor!='000000' && $cellColor!='FFFFFF' && !$error){
//Show cell color
echo '<script language="javascript">alert("Color: "'.$cellColor.'");</script>';
}else{
echo '<script language="javascript">alert("No Color");</script>';
}
}
}
} catch (Exception $e) {
echo '<script language="javascript">alert("Error:"'.$e.'");</script>';
}