thomasw_lrd Posted July 27, 2012 Share Posted July 27, 2012 I'm having a problem using PHPExcel. I'm trying to set row colors based on the status of a case in our system This code works, but it's inelegant, and basically sucks. I also need to go all way out to column 35, but anything past column 17 gives me a corrupted excel file that can't be opened. I've tried using a for loop, but the same problem exists. I have roughly 1700 records that I need to export a spreadsheet. I know that I need to go from A* to AJ* where * = row number, but I'm not sure how to do this dynamically. Any ideas? $column++; $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($column, $excel_row, $row['pol_policy_status']); if ($row['pol_policy_status'] == 'Closed') { $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(0, $excel_row)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('FF228B22'); $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(1, $excel_row)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('FF228B22'); $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(2, $excel_row)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('FF228B22'); $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(3, $excel_row)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('FF228B22'); $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(4, $excel_row)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('FF228B22'); $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(5, $excel_row)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('FF228B22'); $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(6, $excel_row)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('FF228B22'); $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(7, $excel_row)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('FF228B22'); $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(8, $excel_row)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('FF228B22'); $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(9, $excel_row)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('FF228B22'); $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(10, $excel_row)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('FF228B22'); $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(11, $excel_row)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('FF228B22'); $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(12, $excel_row)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('FF228B22'); $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(13, $excel_row)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('FF228B22'); $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(14, $excel_row)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('FF228B22'); $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(15, $excel_row)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('FF228B22'); $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(16, $excel_row)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('FF228B22'); $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(17, $excel_row)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('FF228B22'); }//end the if $row = Closed Quote Link to comment https://forums.phpfreaks.com/topic/266361-phpexcel-help/ Share on other sites More sharing options...
thomasw_lrd Posted July 30, 2012 Author Share Posted July 30, 2012 I did figure this out and have posted the solution for everyone's edification. $objPHPExcel->getActiveSheet()->getStyle("A".($excel_row).":AJ".($excel_row))->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('FF228B22'); [\code] I was confused how to use a variable in place of the row number. You have to (duh!!!) use the proper dot notation. Quote Link to comment https://forums.phpfreaks.com/topic/266361-phpexcel-help/#findComment-1365501 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.