0

I am using phpexcel library for generate excel file and i want change background color of call How to set specific color to active cell when creating XLS document in PHPExcel? here id my code which i am using

  public function exportCSV() {
    // create file name
    $fileName = 'data-'.time().'.xlsx';  
    // load excel library
    $this->load->library('excel');
    // $listInfo = $this->export->exportList();
    $ordersData = $this->admin_development->getDevelopmentDetails();
    $objPHPExcel = new PHPExcel();
    $objPHPExcel->setActiveSheetIndex(0);
    // set Header
    $objPHPExcel->getActiveSheet()->SetCellValue('A1', 'Lott Number');
    $objPHPExcel->getActiveSheet()->SetCellValue('B1', 'Slot Number');
    $objPHPExcel->getActiveSheet()->SetCellValue('C1', 'Party Name');


    // set Row
    $rowCount = 2;
    foreach ($ordersData as $list) {
        $objPHPExcel->getActiveSheet()->SetCellValue('A' . $rowCount, $list->lott_number);
        $objPHPExcel->getActiveSheet()->SetCellValue('B' . $rowCount, $list->category);
        $objPHPExcel->getActiveSheet()->SetCellValue('C' . $rowCount, $list->party_name);

        $objPHPExcel->getActiveSheet()
        ->getStyle('A' . $rowCount)
        ->getFill()
        ->setFillType(PHPExcel_Style_Fill::FILL_SOLID)
        ->getStartColor()
        ->setRGB('FF0000');

       
        $rowCount++;
    }
    $filename = "tutsmake". date("Y-m-d-H-i-s").".csv";
    header('Content-Type: application/vnd.ms-excel'); 
    header('Content-Disposition: attachment;filename="'.$filename.'"');
    header('Cache-Control: max-age=0'); 
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'CSV');  
    $objWriter->save('php://output'); 

}
Rishikesh Singh
  • 85
  • 2
  • 10
  • 1
    https://stackoverflow.com/questions/6773272/set-background-cell-color-in-phpexcel – KHIMAJI VALUKIYA Dec 20 '21 at 12:36
  • @KHIMAJIVALUKIYA i am tried also this but did not worked – Rishikesh Singh Dec 20 '21 at 12:39
  • Have you tried: $objPHPExcel->getActiveSheet() ->getStyle('A' . $rowCount) ->getFill() ->setFillType(PHPExcel_Style_Fill::FILL_SOLID) ->getStartColor() ->setARGB('FF0000'); – KHIMAJI VALUKIYA Dec 20 '21 at 13:19
  • Or $objPHPExcel->getActiveSheet() ->getStyle('A' . $rowCount)->applyFromArray( array( 'fill' => array( 'type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => 'FF0000') ) ) ); – KHIMAJI VALUKIYA Dec 20 '21 at 13:21
  • Does this answer your question? [Set Background cell color in PHPExcel](https://stackoverflow.com/questions/6773272/set-background-cell-color-in-phpexcel) – bitski Dec 20 '21 at 23:27
  • @KHIMAJIVALUKIYA $objPHPExcel->getActiveSheet()->getStyle('A'. $rowCount)->applyFromArray( array( 'fill' => array( 'type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => 'FF0000') ) ) ); $objPHPExcel->getActiveSheet()->getStyle('A'.$rowCount)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('FF0000'); i am tried both but did not worked...! – Rishikesh Singh Dec 21 '21 at 05:23

0 Answers0