0

I have an Excel file that I want to upload it with Phpoffice, and preview on web application

excellfile

everything works fine and success with this code:

if(isset($_POST['submit'])){
        $err ="";
        $ekstensi="";
        $success="";
        $file_name = $_FILES['filexls']['name'];
        $file_data = $_FILES['filexls']['tmp_name'];

        if (empty($file_name)) {

            $err .="<li>Silahkan masukan file.</li>";
            
        }else{
            $ekstensi = pathinfo($file_name)['extension'];
        }

        $ekstensi_allowed = array("xls","xlsx");
        if (!in_array($ekstensi,$ekstensi_allowed)) {

            $err .= "<li>Silahkan masukan file tipe xls, atau xlsx. File yang sekarang <b>$file_name</b>tipenya<b>$ekstensi</b></li>";
        }
      

<table class="table table-bordered">
              <thead>
                <tr>
                  
                  <th>NO</th>
                 
                  <th>UARAIAN PEKERJAAN</th>
                  <th>VOLUME</th>
                  <th class="tex-wrap">JUMLAH VOLUME</th>
                  <th>SATUAN</th>
                  <th>HARGA SATUAN</th>
                  <th>HARGA STANDARD</th>
                  <th>STATUS</th>
                  <th>JUMLAH</th>
                  <th>TAGUIHAN BULAN</th>
                  
              </tr>
              </thead>
              <tbody>
             <tr>

    <?php
            $no=0;
            if(empty($err)){
                $reader =\PhpOffice\PhpSpreadsheet\IOFactory::createReaderForFile($file_data);
                $spreadsheet = $reader->load($file_data);
                $sheetData = $spreadsheet->getActiveSheet()->toArray();
                
                $jumlahData=1;
                for ($i=1; $i<count($sheetData); $i++) {    
                        
                        $no = $sheetData[$i]['0'];
                        $urai = $sheetData[$i]['1'];
                        $volume = $sheetData[$i]['12'];
                        $jum_vol = $sheetData[$i]['14'];
                        $sat = $sheetData[$i]['15'];
                        $harga = $sheetData[$i]['16'];
                        $jum = $sheetData[$i]['17'];
                        ?>
                         <th><?=$no?></th>
                         <th><?=$urai?></th>
                         <th><?=$volume?></th>
                         <th><?=$jum_vol?></th>
                         <th><?=$sat?></th>
                         <th><?=$harga?></th>
                         <th><?=$jum?></th>
                     </tr>
            <?php
        }
    }?>

and this is the result result view

Now I want summarize the column form row "JUMLAH"($jum) which is the data that I want to sum just like this:

var_dump($jum);


 NULL string(6) "170500" NULL NULL NULL NULL string(5) "60720" string(5) "49784" string(5) "25000" string(5) "25000" string(6) "331004" NULL string(6) "300000" NULL NULL NULL NULL string(5) "14231" string(4) "5001" string(5) "25000" string(5) "25000" string(6) "369232" NULL

pleas give me some clue...thanks

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
  • You're showing us `"JUMLAH"($jum)` as the 8th column but then in the code you're showing us `$jum = $sheetData[$i]['17']` which doesn't match up. You're also showing us a bunch of variables with no references to them, and not showing us enough of the code to make much of a guess regarding what your current code is currently doing. – Kevin Y Feb 01 '22 at 04:58
  • im sorry I'v been cut 11 another colum for photo purpose, wait Ill edit it.. – Muhammad Agus Feb 01 '22 at 09:58

0 Answers0