<?php



   // Error reporting
   error_reporting(E_ALL);

   $projName=$_GET["p"];
   $data=$_POST["data"];

   $data=str_replace('*plus*','+',$data);
   $data=str_replace('*amp*','&',$data);
   $data=stripslashes($data);

   $fields=explode('__#',"$data");

   $emails = explode(',',$_POST["ids"]);

   define('USER', 'inese.andersone@gatewaypartners.net');
   define('TOKEN', 'Md63=090f2R6y8ebPbf0r5qeU7uaH4G4NajcbdM2');
   require 'Solve360Service.php';
   $solve360Service = new Solve360Service(USER, TOKEN);


   /*
   -----------------------------------------------------------------------------
   -----------------------------------------------------------------------------
   Excel file generation
   -----------------------------------------------------------------------------
   -----------------------------------------------------------------------------
   */

   function _addLogos($objPHPExcel,$cols,$row) {
      $objPHPExcel->getActiveSheet()->getRowDimension("$row")->setRowHeight(45);
      $objDrawing = new PHPExcel_Worksheet_Drawing();
      $objDrawing->setName('Logo');
      $objDrawing->setDescription('Logo');
      $objDrawing->setPath('GBlarge.jpg');
      $objDrawing->setHeight(70);
      $objDrawing->setCoordinates($cols[6].$row);
      $objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
   }

   function _makeHeader($objPHPExcel,$cols,$startRow) {
      $r1=$startRow;
      $r2=$startRow-1;
      $r3=$startRow-2;
      $r4=$startRow-3;
      $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cols[0].$r4,'Final Report');
      $objPHPExcel->setActiveSheetIndex(0)->getStyle($cols[0].$r4)->getFont()->setName('Avenir');
      $objPHPExcel->setActiveSheetIndex(0)->getStyle($cols[0].$r4)->getFont()->setSize(15);
      _addLogos($objPHPExcel,$cols,$r4);
      $objPHPExcel->getActiveSheet()->getStyle($cols[0].$r4.':'.$cols[2].$r4)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
    }

    function basicRow($objPHPExcel,$cols,$value,$label,$row, $desc = false) {
      //$objPHPExcel->getActiveSheet()->mergeCells($cols[1].$row.':'.$cols[2].$row);
      if (!$desc) $objPHPExcel->getActiveSheet()->getRowDimension("$row")->setRowHeight(22);
      $range = $cols[0].$row.':'.$cols[1].$row;
      $objPHPExcel->getActiveSheet()->setCellValue($cols[0].$row,$label);
      $objPHPExcel->getActiveSheet()->setCellValue($cols[1].$row,$value);
      $objPHPExcel->getActiveSheet()->getStyle($range)->getFont()->setName('Avenir');
      $objPHPExcel->getActiveSheet()->getStyle($range)->getFont()->setSize(10);
      $objPHPExcel->getActiveSheet()->getStyle($range)->getFont()->getColor()->setRGB("5C5C5C");
      $objPHPExcel->getActiveSheet()->getStyle($cols[0].$row)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB("F2F2F2");
      $objPHPExcel->getActiveSheet()->getStyle($range)->getAlignment()->setWrapText(true);
    }









   // Include PHPExcel
   require_once '../Classes/PHPExcel.php';

   // Create new PHPExcel object
   $objPHPExcel = new PHPExcel();

   $styleArray = array(
     'borders' => array(
       'allborders' => array(
         'style' => PHPExcel_Style_Border::BORDER_THIN
       )
     )
   );

   // Set document properties
   $objPHPExcel->getProperties() ->setCreator("Gateway Baltic")
                                 ->setLastModifiedBy("Gateway Baltic")
                                 ->setSubject("$projName")
                                 ->setDescription("Final report");

   $objPHPExcel->getDefaultStyle()->getFont()->setName('Avenir');
   $objPHPExcel->getDefaultStyle()->getFont()->setSize(10);
   $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_TOP);
   $objPHPExcel->getActiveSheet()->setShowGridlines(true);

   $objPHPExcel->getActiveSheet()->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE);
   $objPHPExcel->getActiveSheet()->getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4);

   $objPHPExcel->getActiveSheet()->getPageMargins()->setTop(0.4);
   $objPHPExcel->getActiveSheet()->getPageMargins()->setRight(0.2);
   $objPHPExcel->getActiveSheet()->getPageMargins()->setLeft(0.2);
   $objPHPExcel->getActiveSheet()->getPageMargins()->setBottom(0.4);
   $objPHPExcel->getActiveSheet()->getPageMargins()->setHeader(0.2);
   $objPHPExcel->getActiveSheet()->getPageMargins()->setFooter(0.2);

   $startRow=4;
   // set columns
   $cols=array('A','B','C','D','E','F','G','H','I','J','K','L','M','N');

   $decOrder=array('3','0','2','1','9','10');
   $colours=array('839C00','FFFFFF','FFC000','BFBFBF','FFFFFF','FFFFFF');



   //_makeHeader($objPHPExcel,$cols,$startRow);


   $tableRow = 1;

   foreach($cols as $columnID) {
     $objPHPExcel->getActiveSheet()->getColumnDimension($columnID)->setAutoSize(true);
   }
   $objPHPExcel->getActiveSheet()->getColumnDimension($cols[1])->setAutoSize(false);
   $objPHPExcel->getActiveSheet()->getColumnDimension($cols[1])->setWidth(27);

   $objPHPExcel->getActiveSheet()->getColumnDimension($cols[4])->setAutoSize(false);
   $objPHPExcel->getActiveSheet()->getColumnDimension($cols[4])->setWidth(30);

   $objPHPExcel->getActiveSheet()->getColumnDimension($cols[5])->setAutoSize(false);
   $objPHPExcel->getActiveSheet()->getColumnDimension($cols[5])->setWidth(30);

   $objPHPExcel->getActiveSheet()->getColumnDimension($cols[7])->setAutoSize(false);
   $objPHPExcel->getActiveSheet()->getColumnDimension($cols[7])->setWidth(40);

   $objPHPExcel->getActiveSheet()->getColumnDimension($cols[9])->setAutoSize(false);
   $objPHPExcel->getActiveSheet()->getColumnDimension($cols[9])->setWidth(30);

   $objPHPExcel->getActiveSheet()->getColumnDimension($cols[10])->setAutoSize(false);
   $objPHPExcel->getActiveSheet()->getColumnDimension($cols[10])->setWidth(30);

   $objPHPExcel->getActiveSheet()->getColumnDimension($cols[11])->setAutoSize(false);
   $objPHPExcel->getActiveSheet()->getColumnDimension($cols[11])->setWidth(30);

   $objPHPExcel->getActiveSheet()->getColumnDimension($cols[12])->setAutoSize(false);
   $objPHPExcel->getActiveSheet()->getColumnDimension($cols[12])->setWidth(40);

    $objPHPExcel->getActiveSheet()->getRowDimension("$tableRow")->setRowHeight(20);

   $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cols[0].$tableRow,"Company Name");
   $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cols[1].$tableRow,"Company Address");
   $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cols[2].$tableRow,"Country");
   $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cols[3].$tableRow,"Company Phone");
   $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cols[4].$tableRow,"Website");
   $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cols[5].$tableRow,"E-mail");
   $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cols[6].$tableRow,"Turnover");
   $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cols[7].$tableRow,"Background");
   $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cols[8].$tableRow,"Contact Person Name");
   $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cols[9].$tableRow,"Position");
   $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cols[10].$tableRow,"E-mail");
   $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cols[11].$tableRow,"Phone");
   $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cols[12].$tableRow,"Feedback");

   $tableRow++;

   $emailID = 0;
   for($r=0;$r<count($fields);$r+=12) {

     $colours=array('839C00','FFFFFF','FFC000','BFBFBF','FFFFFF','FFFFFF');
     $tt = array('000000', 'FFFFFF');
        if ($fields[$r]=='3') { $fieldColor = $colours[0]; $txtColor = $tt[0]; }
        else if ($fields[$r]=='0') { $fieldColor = $colours[1]; $txtColor = $tt[0]; }
        else if ($fields[$r]=='2') { $fieldColor = $colours[2]; $txtColor = $tt[0]; }
        else if ($fields[$r]=='1') { $fieldColor = $colours[3]; $txtColor = $tt[0]; }
        else if ($fields[$r]=='9') { $fieldColor = $colours[4]; $txtColor = $tt[0]; }
        else if ($fields[$r]=='10') { $fieldColor = $colours[5]; $txtColor = $tt[0]; }

    $therange = $cols[0].$tableRow.':'.$cols[12].$tableRow;
    if ($fieldColor != 'FFFFFF') {
      $objPHPExcel->getActiveSheet()->getStyle($therange)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB($fieldColor);
      $objPHPExcel->getActiveSheet()->getStyle($therange)->getFont()->getColor()->setRGB($txtColor);
    }
    $theemail = $solve360Service->getCompany($emails[$emailID])->item->fields->custom4620793;
    $emailID++;


     $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cols[0].$tableRow,$fields[$r+1]);
     $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cols[1].$tableRow,$fields[$r+2]);
     $objPHPExcel->getActiveSheet()->getStyle($cols[1].$tableRow)->getAlignment()->setWrapText(true);
     //$objPHPExcel->setActiveSheetIndex(0)->setCellValue($cols[2].$tableRow,$fields[$r+2]);
     $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cols[3].$tableRow,$fields[$r+3]);
     $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cols[4].$tableRow,$fields[$r+4]);
     $objPHPExcel->getActiveSheet()->getStyle($cols[4].$tableRow)->getAlignment()->setWrapText(true);
     $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cols[5].$tableRow,$theemail);
     $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cols[6].$tableRow,$fields[$r+5]);
     $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cols[7].$tableRow,$fields[$r+7]);
     $objPHPExcel->getActiveSheet()->getStyle($cols[7].$tableRow)->getAlignment()->setWrapText(true);


     $conCount=(integer) $fields[$r+9];
     $summary=$fields[$r+10];
     if ($conCount>0) {
        $contacts=explode('__*',$fields[$r+11]);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cols[8].$tableRow,$contacts[0]);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cols[9].$tableRow,$contacts[1]);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cols[10].$tableRow,$contacts[3]);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cols[11].$tableRow,$contacts[2]);
     }


     if ($fields[$r+8]!='') {
        $feedback=explode('__*',$fields[$r+8]);
        $dates=array();
        $comments=array();
        for ($a=0;$a<count($feedback);$a++) {
           if ($a%2==0) $dates[]="$feedback[$a]";
           else $comments[]="$feedback[$a]";
        }

        $note_start_row = $tableRow;

        for ($a=0;$a<count($dates);$a++) {
           $objRichText = new PHPExcel_RichText();
           $objBold = $objRichText->createTextRun("$dates[$a]");
           $objBold->getFont()->setBold(true);
           $objRichText->createText("$comments[$a]");
           $objPHPExcel->getActiveSheet()->getCell($cols[12].$tableRow)->setValue($objRichText);
           $objPHPExcel->getActiveSheet()->getStyle($cols[12].$tableRow)->getAlignment()->setWrapText(true);

           if ($fieldColor != 'FFFFFF') {
             $objPHPExcel->getActiveSheet()->getStyle($cols[12].$tableRow)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB($fieldColor);
             $objPHPExcel->getActiveSheet()->getStyle($cols[12].$tableRow)->getFont()->getColor()->setRGB($txtColor);
           }
           $tableRow++;
        }

        $note_end_row = $tableRow-1;

        $objPHPExcel->getActiveSheet()->getStyle($cols[12].$note_start_row.':'.$cols[12].$note_end_row)->applyFromArray(
          array(
              'borders' => array(
                  'outline' => array(
                      'style' => PHPExcel_Style_Border::BORDER_THIN
                  )
              )
          )
        );

        for ($b=0;$b<12;$b++) {
          $objPHPExcel->getActiveSheet()->mergeCells($cols[$b].$note_start_row.':'.$cols[$b].$note_end_row);
          $objPHPExcel->getActiveSheet()->getStyle($cols[$b].$note_start_row.':'.$cols[$b].$note_end_row)->applyFromArray(
            array(
                'borders' => array(
                    'outline' => array(
                        'style' => PHPExcel_Style_Border::BORDER_THIN
                    )
                )
            )
          );
        }
         //$tableRow++;



     }

     /* for ($a=0;$a<count($cols)-1;$a++) {
       $objPHPExcel->getActiveSheet()->mergeCells($cols[$a].$note_start_row.':'.$cols[$a].$note_end_row);
     } */
   }

   $objPHPExcel->getActiveSheet()->removeColumn($cols[2]);

   /* $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cols[0].$tableRow,"Company");
   $objPHPExcel->setActiveSheetIndex(0)->getStyle($cols[0].$tableRow)->getFont()->setBold(true);
   $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cols[1].$tableRow,"Website");
   $objPHPExcel->setActiveSheetIndex(0)->getStyle($cols[1].$tableRow)->getFont()->setBold(true);
   $objPHPExcel->getActiveSheet()->getStyle($cols[0].$tableRow.':'.$cols[1].$tableRow)->applyFromArray($styleArray);
   $objPHPExcel->getActiveSheet()->getRowDimension("$tableRow")->setRowHeight(20);

   $objPHPExcel->getActiveSheet()->getColumnDimension($cols[0])->setWidth(27);
   $objPHPExcel->getActiveSheet()->getColumnDimension($cols[1])->setWidth(50);
   $tableRow++;

   for($r=0;$r<count($fields);$r+=12) {
      $colours=array('839C00','FFFFFF','FFC000','BFBFBF','FFFFFF','FFFFFF');
      $tt = array('000000', 'FFFFFF');
         if ($fields[$r]=='3') { $fieldColor = $colours[0]; $txtColor = $tt[0]; }
         if ($fields[$r]=='0') { $fieldColor = $colours[1]; $txtColor = $tt[0]; }
         if ($fields[$r]=='2') { $fieldColor = $colours[2]; $txtColor = $tt[0]; }
         if ($fields[$r]=='1') { $fieldColor = $colours[3]; $txtColor = $tt[0]; }
         if ($fields[$r]=='9') { $fieldColor = $colours[4]; $txtColor = $tt[0]; }
         if ($fields[$r]=='10') { $fieldColor = $colours[5]; $txtColor = $tt[0]; }
      /* $table->addRow();
      _listCell($table,$fields[$r+1],2900,false,$fieldColor,$txtColor);
      _listCell($table,$fields[$r+4],2900,false,$fieldColor,$txtColor);
      $range = $cols[0].$tableRow.':'.$cols[1].$tableRow;
      $objPHPExcel->getActiveSheet()->getStyle($range)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB($fieldColor);
      $objPHPExcel->getActiveSheet()->getStyle($range)->getFont()->getColor()->setRGB($txtColor);
      $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cols[0].$tableRow,$fields[$r+1]);
      $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cols[1].$tableRow,$fields[$r+4]);
      $objPHPExcel->getActiveSheet()->getStyle($cols[0].$tableRow.':'.$cols[1].$tableRow)->applyFromArray($styleArray);
      $tableRow++;
   }

   $tableRow++;

   $decOrder=array('3','0','2','1','9','10');
   $colours=array('839C00','FFFFFF','FFC000','BFBFBF','FFFFFF','FFFFFF');
   $decText=array('COMPANIES WHICH EXPRESSED WILLINGNESS TO MEET:','COMPANIES WHICH HAVE NOT RESPONDED YET:','COMPANIES WHICH SHOULD BE CONTACTED LATER:','COMPANIES WHICH WERE NOT INTERESTED IN MEETING:','COMPANIES WHICH WERE NOT SUCCESSFULLY CONTACTED:','COMPANIES WHICH WERE NOT CONTACTED:');


   for($r=0;$r<count($fields);$r+=12) {
      //$section->addPageBreak();
      $tableRow++;
      if ($r==0) {
         if ($fields[0]=='3') { $dec=0; $coll = "839C00"; }
         if ($fields[0]=='0') { $dec=1; $coll = "BFBFBF"; }
         if ($fields[0]=='2') { $dec=2; $coll = "FFC000"; }
         if ($fields[0]=='1') { $dec=3; $coll = "BFBFBF"; }
         if ($fields[0]=='9') { $dec=4; $coll = "BFBFBF"; }
         if ($fields[0]=='10') { $dec=5; $coll = "BFBFBF"; }

         //$objPHPExcel->getActiveSheet()->getRowDimension("$tableRow")->setRowHeight(20);
         $objPHPExcel->getActiveSheet()->setCellValue($cols[0].$tableRow,$decText[$dec]);
         $objPHPExcel->getActiveSheet()->getStyle($cols[0].$tableRow)->getFont()->setName('Avenir');
         $objPHPExcel->getActiveSheet()->getStyle($cols[0].$tableRow)->getFont()->setSize(16);
         $objPHPExcel->getActiveSheet()->getStyle($cols[0].$tableRow)->getFont()->getColor()->setRGB($coll);
         $tableRow++;
      } else {
         if ($fields[$r]!=$decOrder[$dec]) {
            while ($fields[$r]!=$decOrder[$dec]) $dec++;
            if ($dec == 0) $coll = "839C00";
            if ($dec == 1) $coll = "BFBFBF";
            if ($dec == 2) $coll = "FFC000";
            if ($dec == 3) $coll = "BFBFBF";
            if ($dec == 4) $coll = "BFBFBF";
            if ($dec == 5) $coll = "BFBFBF";
            //$objPHPExcel->getActiveSheet()->getRowDimension("$tableRow")->setRowHeight(20);
            $objPHPExcel->getActiveSheet()->setCellValue($cols[0].$tableRow,$decText[$dec]);
            $objPHPExcel->getActiveSheet()->getStyle($cols[0].$tableRow)->getFont()->setName('Avenir');
            $objPHPExcel->getActiveSheet()->getStyle($cols[0].$tableRow)->getFont()->setSize(16);
            $objPHPExcel->getActiveSheet()->getStyle($cols[0].$tableRow)->getFont()->getColor()->setRGB($coll);
            $tableRow++;
         }
      }
      $tableRow++;

      $range = $cols[0].$tableRow.':'.$cols[1].$tableRow;
      if ($dec == 1 || $dec == 2) {
        $objPHPExcel->getActiveSheet()->getRowDimension("$tableRow")->setRowHeight(40);
        $objPHPExcel->getActiveSheet()->setCellValue($cols[0].$tableRow,"Company Name");
        $objPHPExcel->getActiveSheet()->setCellValue($cols[1].$tableRow,$fields[$r+1]);
        $objPHPExcel->getActiveSheet()->getStyle($range)->getFont()->setName('Avenir');
        $objPHPExcel->getActiveSheet()->getStyle($range)->getFont()->setSize(10);
        $objPHPExcel->getActiveSheet()->getStyle($range)->getFont()->getColor()->setRGB("000000");
        $objPHPExcel->getActiveSheet()->getStyle($range)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB($coll);
        $objPHPExcel->getActiveSheet()->getStyle($range)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        //_company_row($table,$fields[$r+1],"Company Name",true,true,$coll,"000000");
      } else {
        $objPHPExcel->getActiveSheet()->getRowDimension("$tableRow")->setRowHeight(40);
        $objPHPExcel->getActiveSheet()->setCellValue($cols[0].$tableRow,"Company Name");
        $objPHPExcel->getActiveSheet()->setCellValue($cols[1].$tableRow,$fields[$r+1]);
        $objPHPExcel->getActiveSheet()->getStyle($range)->getFont()->setName('Avenir');
        $objPHPExcel->getActiveSheet()->getStyle($range)->getFont()->setSize(10);
        $objPHPExcel->getActiveSheet()->getStyle($range)->getFont()->getColor()->setRGB("000000");
        $objPHPExcel->getActiveSheet()->getStyle($range)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB($coll);
        $objPHPExcel->getActiveSheet()->getStyle($range)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        //_company_row($table,$fields[$r+1],"Company Name",true,true,$coll,"000000");
      }
      $tableRow++;
      basicRow($objPHPExcel,$cols,$fields[$r+2],"Address",$tableRow);
      $tableRow++;
      basicRow($objPHPExcel,$cols,$fields[$r+3],"Telephone (operator)",$tableRow);
      $tableRow++;
      basicRow($objPHPExcel,$cols,$fields[$r+4],"Website",$tableRow);
      $tableRow++;
      basicRow($objPHPExcel,$cols,$fields[$r+5],"Turnover",$tableRow);
      $tableRow++;
      basicRow($objPHPExcel,$cols,$fields[$r+6],"Employees",$tableRow);
      $tableRow++;

      $conCount=(integer) $fields[$r+9];
      $summary=$fields[$r+10];
      if ($conCount>0) {
         $contacts=explode('__*',$fields[$r+11]);
         basicRow($objPHPExcel,$cols,$contacts[0],"Contact Person",$tableRow);
         $tableRow++;
         basicRow($objPHPExcel,$cols,$contacts[1],"Position",$tableRow);
         $tableRow++;
         basicRow($objPHPExcel,$cols,$contacts[2],"Mobile",$tableRow);
         $tableRow++;
         basicRow($objPHPExcel,$cols,$contacts[3],"Email",$tableRow);
         $tableRow++;
      }
      basicRow($objPHPExcel,$cols,$fields[$r+7],"Description",$tableRow, true);
      $tableRow++;

      if ($fields[$r+8]!='') {
        basicRow($objPHPExcel,$cols,"","",$tableRow);
        $tableRow++;
         $feedback=explode('__*',$fields[$r+8]);
         $dates=array();
         $comments=array();
         for ($a=0;$a<count($feedback);$a++) {
            if ($a%2==0) $dates[]="$feedback[$a]";
            else $comments[]="$feedback[$a]";
         }

         for ($a=0;$a<count($dates);$a++) {
           $objPHPExcel->getActiveSheet()->getStyle($cols[0].$tableRow.':'.$cols[1].$tableRow)->getFont()->getColor()->setRGB("5C5C5C");
            if ($a == 0) {
              $objPHPExcel->getActiveSheet()->getCell($cols[0].$tableRow)->setValue("Feedback");
            }
            $objRichText = new PHPExcel_RichText();
            $objBold = $objRichText->createTextRun("$dates[$a]");
            $objBold->getFont()->setBold(true);
            $objRichText->createText("$comments[$a]");
            $objPHPExcel->getActiveSheet()->getCell($cols[1].$tableRow)->setValue($objRichText);
            $objPHPExcel->getActiveSheet()->getStyle($cols[1].$tableRow)->getAlignment()->setWrapText(true);
            $objPHPExcel->getActiveSheet()->getStyle($cols[0].$tableRow)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB("F2F2F2");
            $tableRow++;
         }
      }
    } */


   $objPHPExcel->getActiveSheet()->setTitle('Final Report');
   $objPHPExcel->setActiveSheetIndex(0);

   // Save Excel 2007 file
   $projParts=explode(" ",$projName);
   $fileName=implode("_",$projParts);
   $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
   $objWriter->save($fileName.'_Final_Report.xlsx');


   echo json_encode(["status"=>'OK', "file"=>$fileName.'_Final_Report.xlsx']);
?>
