I have one select statement which will result values as below:
79927
79927
79927
79927
79928
79928
79928
79928
79928
Then When I export to excel I have the below screen: enter image description here
But what I really want is this result: enter image description here
I want to set the maximum column as D, which means every time the result achieve the column D the next will move to the next row.
If the result achieve the D1, the next will go to A2 and so on.
Here's my code:
$rowCount=1;
while ( $row1 = mysql_fetch_array ($itens_spec_comb)) {
$objPHPExcel->getActiveSheet()->SetCellValue ('A'.$rowCount, $row1 ['id']);
$rowCount++;
}
If I understand you correctly, use my example:
$rowCount=1;
$col = array("A","B","C","D");
$i=0;
while ( $row1 = mysql_fetch_array ($itens_spec_comb)) {
$objPHPExcel->getActiveSheet()->SetCellValue ($col[$i].$rowCount, $row1 ['id']);
$i++;
if($i==3){
$i=0;
$rowCount++;
}
}
$rowCount=1;
while ( $row1 = mysql_fetch_array ($itens_spec_comb)) {
for($col=0; $col<4; $col++){
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow ($col, $rowCount, $row1 ['id']);
}
$rowCount++;
}
Related : PHPExcel setCellValueByColumnAndRow not writing data to spreadsheet
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.