0

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>';
 }
trincot
  • 317,000
  • 35
  • 244
  • 286
  • What is wrong with *FFFFFF* or *000000* being returned? Prepend *FF* (which means 100 % opacity) to it and you will get `COLOR_WHITE` and `COLOR_BLACK`, respectfully. – Anton Samsonov Dec 30 '16 at 16:54
  • Welcome to Stack Overflow! I improved the indenting of your code, made some phrases more clear, and removed "PHP" from the title (it is not necessary to repeat what is in the tags already). – trincot Dec 30 '16 at 21:51
  • I need the background color, but just return that value no matter the color. With xls and xlsx files works fine. – Luis San Martín Saavedra Dec 30 '16 at 21:55

0 Answers0