PHPExcel设置列值和列数量
PHPExcel set column value and column quantity
我有一个 select 语句,其结果值如下:
79927
79927
79927
79927
79928
79928
79928
79928
79928
然后当我导出到 excel 时,我有以下屏幕:enter image description here
但我真正想要的是这个结果:enter image description here
我想设置最大列为D,也就是说每次结果达到D列,下一个就会移到下一行。
如果成绩达到D1,则下一个进入A2,依此类推
这是我的代码:
$rowCount=1;
while ( $row1 = mysql_fetch_array ($itens_spec_comb)) {
$objPHPExcel->getActiveSheet()->SetCellValue ('A'.$rowCount, $row1 ['id']);
$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++;
}
相关:PHPExcel setCellValueByColumnAndRow not writing data to spreadsheet
如果我理解正确,请使用我的示例:
$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++;
}
}
我有一个 select 语句,其结果值如下:
79927
79927
79927
79927
79928
79928
79928
79928
79928
然后当我导出到 excel 时,我有以下屏幕:enter image description here
但我真正想要的是这个结果:enter image description here
我想设置最大列为D,也就是说每次结果达到D列,下一个就会移到下一行。
如果成绩达到D1,则下一个进入A2,依此类推
这是我的代码:
$rowCount=1;
while ( $row1 = mysql_fetch_array ($itens_spec_comb)) {
$objPHPExcel->getActiveSheet()->SetCellValue ('A'.$rowCount, $row1 ['id']);
$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++;
}
相关:PHPExcel setCellValueByColumnAndRow not writing data to spreadsheet
如果我理解正确,请使用我的示例:
$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++;
}
}