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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.