我无法实现从数组中获取值到B2中的单元格 代码如下:
$row = 2;
$column = 'B';
$head=array('ONE','TWO','THREE');
foreach ($steps as $step) {
$etat = Etat::find_by_step($code, $year);
$objPHPExcel->getActiveSheet()->fromArray($head, null, $column . $row);
$objPHPExcel->getActiveSheet()->getStyle($column . $row)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
$objPHPExcel->getActiveSheet()->getStyle($column . $row)->getFill()->getStartColor()->setRGB('233748');
$objPHPExcel->getActiveSheet()->getStyle($column . $row)->getFont()->getColor()->setRGB('f7f8f9');
$column++;
}
通常我必须得到:
但我明白了:
我认为他只重复一次。
有人有想法吗?
提前致谢
答案 0 :(得分:0)
为什么不按$ head
的大小增加列,而不是每一步只增加一次列您还需要为您正在编写的单元格范围设置样式,而不仅仅是针对头块中的第一个单元格
$row = 2;
$column = 'B';
$head=array('ONE','TWO','THREE');
$stepSize = count($head);
foreach ($steps as $step) {
$etat = Etat::find_by_step($code, $year);
$objPHPExcel->getActiveSheet()->fromArray($head, null, $column . $row);
$rangeColumn = $column;
for($i = 0; $i < $stepSize; $i++)
$rangeColumn++;
$objPHPExcel->getActiveSheet()->getStyle($column . $row . ':' . $rangeColumn . $row)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
$objPHPExcel->getActiveSheet()->getStyle($column . $row . ':' . $rangeColumn . $row)->getFill()->getStartColor()->setRGB('233748');
$objPHPExcel->getActiveSheet()->getStyle($column . $row . ':' . $rangeColumn . $row)->getFont()->getColor()->setRGB('f7f8f9');
$column = $rangeColumn;
$column++;
}