[英]PHPExcel set column value and column quantity
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 然后,当我导出到excel时,出现以下屏幕: 在此处输入图像描述
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. 我想将最大列设置为D,这意味着每当结果达到列D时,下一个将移至下一行。
If the result achieve the D1, the next will go to A2 and so on. 如果结果达到D1,则下一个将到达A2,依此类推。
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 相关: PHPExcel setCellValueByColumnAndRow不将数据写入电子表格
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.