Jump to content

PHPExcel Help


thomasw_lrd

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/266361-phpexcel-help/
Share on other sites

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.  

Link to comment
https://forums.phpfreaks.com/topic/266361-phpexcel-help/#findComment-1365501
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.