我有一张表格,按item_code
和status
排序。我有3个状态= 0,1和2.我想在每个状态完成时进行一些计算。
基本上,PXPExcel会覆盖每个status
类别的最后一行。根据数据库,有:4行status 0
,1行status 1
和5行status 2
。我已经坚持这部分已经好几天了,所以任何帮助都会受到赞赏。
这是我的代码:
这是导出文件输出:
我已经尝试过做的事情:
/*
* Add +1 to each count so it could count last row as well.
* 1. Start adding +1 to each count outside the main loop.
* 2. $newCountOne = $countZero + ($countOne +1);
* 3. $newCountTwo = $newCountOne + ($countTwo +1);
* 4. if ( $loopCounter == ($countZero +1 ) )
* 5. To raise $key parameter in "total" row.
*
*/
提前谢谢。
答案 0 :(得分:0)
这是你的主要问题。
将值添加到特定单元格时的循环必须是这样的:
修改强>
试试这个:
<?php
$items = 18;
$countZero = 4;
$countOne = 10;
$countTwo = 4;
$newCountOne = $countZero + $countOne;
$newCountTwo = $newCountOne + $countTwo;
echo "Segundo stop: ".$newCountOne."<br>";
echo "Tercer stop: ".$newCountTwo."<br>";
//Starting point.
$loopCounter = 1;
$number = 0;
//Each status has his own background color
// foreach($items AS $key=>$item) {
for ($i=0; $i < $items; $i++) {
echo "A".($number)."ACTUAL DB VALUE<br>";
//Main loop
if($loopCounter == $countZero) {
echo $loopCounter."<br>";
$number++;
//Status0
echo "Status 0 END <br>";
echo "A"." cell number: ".($number)." TOTAL"."<br>";
echo "D"." cell number: ".($number)." VALUE"."<br>";
echo "E"." cell number: ".($number)." QUANTITY"."<br>";
} elseif ($loopCounter == $newCountOne) {
$number++;
//Status1
echo "Status 1 END <br>";
echo "A"." cell number: ".($number)." TOTAL"."<br>";
echo "D"." cell number: ".($number)." VALUE"."<br>";
echo "E"." cell number: ".($number)." QUANTITY"."<br>";
} elseif ($loopCounter == $newCountTwo) {
$number++;
//Status2
echo "Status 2 END <br>";
echo "A"." cell number: ".($number)." TOTAL"."<br>";
echo "D"." cell number: ".($number)." VALUE"."<br>";
echo "E"." cell number: ".($number)." QUANTITY"."<br>";
}
//Remove this ELSE!
/*echo "B".($number + 7)."ACTUAL DB VALUE<br>";
echo "C".($number + 7)."ACTUAL DB VALUE<br>";
echo "D".($number + 7)."ACTUAL DB VALUE<br>";
echo "E".($number + 7)."ACTUAL DB VALUE<br>";
echo "F".($number + 7)."ACTUAL DB VALUE<br>";
echo "G".($number + 7)."ACTUAL DB VALUE<br>";
echo "H".($number + 7)."ACTUAL DB VALUE<br>";
echo "I".($number + 7)."ACTUAL DB VALUE<br>";
echo "J".($number + 7)."ACTUAL DB VALUE<br>";
echo "K".($number + 7)."ACTUAL DB VALUE<br>";
echo "L".($number + 7)."ACTUAL DB VALUE<br>";*/
$number++;
$loopCounter++;
}
?>