Get cell style with phpExcel from ods file

305 views Asked by At

I'm using the PHPExcel lib to read spread sheets. With xlsx and xls files it works fine, but not with ods and ots.

I'm trying to get the background color of the cell but with ods files I always get FFFFF instead of the actual cell color.

Here is the code I'm working on:

$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>';
 }
0

There are 0 answers