PHPExcel会覆盖行

时间:2014-09-04 14:08:01

标签: php phpexcel

我有一张表格,按item_codestatus排序。我有3个状态= 0,1和2.我想在每个状态完成时进行一些计算。

基本上,PXPExcel会覆盖每个status类别的最后一行。根据数据库,有:4行status 0,1行status 1和5行status 2。我已经坚持这部分已经好几天了,所以任何帮助都会受到赞赏。

这是我的代码:

http://pastebin.com/4FZjZmt4

这是导出文件输出:

http://imgur.com/xR5nP3Q

我已经尝试过做的事情:

   /*
    *   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.
    *
    */

提前谢谢。

1 个答案:

答案 0 :(得分:0)

这是你的主要问题。

将值添加到特定单元格时的循环必须是这样的:

enter image description here

修改

试试这个:

<?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++;
    }
?>