Help with Loops

Topics: Developer Forum, Project Management Forum, User Forum
Jan 2, 2013 at 3:27 PM

Hi there,

I have recently downloaded and installed this PHPExcel package which I have found to be rather amazing for what I needed, more specifically grabbing images from our database.

I was wondering if it would be possible to help me with loops, I currently found a way to do looping straight from Mysql, but the file I am going to use has some layout properties.

E.g. each mysql row would be 5 cells high and 5 cells wide.

So when the first loop is shown e.g. A1 - A5 i'de like the next loop to skip and do A7 - A12 if this makes sense?

This is the basic code for the looping area:

//----------- SECTION THAT WILL BE LOOPED	
while($row = mysql_fetch_array($result))
  {

							 
//Draw Image
// Create new picture object
  $objDrawing = new PHPExcel_Worksheet_Drawing();
  $objDrawing->setName('img');
  $objDrawing->setDescription('test_img');
  $objDrawing->setPath('V23316.jpg');
  $objDrawing->setHeight(150);
  $objDrawing->setOffsetX(30);
  $objDrawing->setOffsetY(10);


// Inserting the picture
  $objDrawing->setCoordinates('A1');
  $objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
  
// Style cell
  $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
  $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
						 
// Border Colour
$styleArray = array(
       'borders' => array(
             'outline' => array(
                    'style' => PHPExcel_Style_Border::BORDER_THICK,
                    'color' => array('argb' => '000000'),
             ),
       ),
);
$objPHPExcel->getActiveSheet()->getStyle('A1:H5')->applyFromArray($styleArray);
$objPHPExcel->getActiveSheet()->getStyle('A1:C5')->applyFromArray($styleArray);

// Add some data
$objPHPExcel->setActiveSheetIndex(0)
        ->mergeCells('A1:C5')
        ->setCellValue('A1', 'Photo Of Product')
			
        ->setCellValue('D1', 'Product Name')
	->setCellValue('E1', $row['name'])
			
        ->setCellValue('D2', 'Brand')
	->setCellValue('E2', 'Adidas')
			
        ->setCellValue('D3', 'Unit Cost')
	->setCellValue('E3', $row['price'])
			
	->setCellValue('D4', 'RRP')
	->setCellValue('E4', '�200')
			
      
	->mergeCells('F1:H5')
	->setCellValue('F1', 'SIZE BREAKDOWN');
			
			
$objPHPExcel->getActiveSheet()->getStyle("A1")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle("A1")->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

$objPHPExcel->getActiveSheet()->getStyle("F1")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle("F1")->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
			
$objPHPExcel->getActiveSheet()->getColumnDimension("D")->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension("E")->setAutoSize(true);

// LOOPING HEIGHT
for ($i=0;$i<200;$i++) {
$objPHPExcel->getActiveSheet()->getRowDimension($i)->setRowHeight(25);
}




// ----------  END PRODUCT ROW LOOPING

 

Note: I am aware some of the cell values arent in the MYSQL format, im only dealing with name and price while I get this working.

Effectively I would like to +6 rows on the colum names.

 

Thank you for reading

Kind Regards

Adam Kernig

Jan 6, 2013 at 11:50 AM

Please end this topic.