-3

i am trying fetch rate from excel or csv file using php code. so plese help me how to select specific row and columns and fetch rate.

This is a rate chart:

enter image description here

in this image yellow columns is Fat of milk and yellow row is Degree of milk suppose fat is 3.5 and Degree is 7 then rate is:16.75. i am using php then i have auto fetch rate from this excel or csv . how i can do ? pls help me and give me code of this solution. Thank you.

u_mulder
  • 54,101
  • 5
  • 48
  • 64
  • i am fetching all sheet data but i dont have code for fetching row and column data so can you help me to write code – Vaibhav Thombare Dec 14 '16 at 07:38
  • Use [PhpExcel](https://github.com/PHPOffice/PHPExcel) for write and read in excel, word, cv ... > [Row](http://stackoverflow.com/questions/17951067/just-get-one-row-from-phpexcel) > [Col](http://stackoverflow.com/questions/15147110/phpexcel-get-column-name-relative-to-given-column) – Morteza Negahi Dec 14 '16 at 07:21

1 Answers1

0
    <?php
    include 'Classes/PHPExcel.php';
    $tempfname="example.csv";
    $excelReader=PHPExcel_IOFactory::createReaderForFile($tempfname);
    $excelObj=$excelReader->load($tempfname);
    $worksheet= $excelObj->getSheet(0);
    $lastRow= $worksheet->getHighestRow();
    $lastColumn = $worksheet->getHighestColumn();
    $lastColumn++;
    $column='Q';
 /*<!--this code is used to fetch single column of excel sheet-->
   for($row=1;$row<=$lastRow;$row++){
        $value=$worksheet->getCell($column.$row)->getValue();
        if($value==$rate){
            echo $value." is awaylable";
        }
            //echo $value."<br>";
        }
    echo "<br>------------------<br>";
    $row1=12;
<!--this code is used to fetch single Row of excel sheet-->
        for($col='A';$col!= $lastColumn;$col++){
        $value=$worksheet->getCell($col.$row1)->getValue();
        if($value==$rate){
            echo $value." is awaylable";
        }
           // echo $value."<br>";
        }
        //echo $value;

    */
     <!-- compare two value from row and column-->
        $row1=12;
    for($row=1;$row<=$lastRow;$row++){
      for($col='A';$col!= $lastColumn;$col++){
        $value1=$worksheet->getCell($column.$row)->getValue();
        $value2=$worksheet->getCell($col.$row1)->getValue();
        if($value1==$value2)
        { 
          echo $value1."=".$value2."<br>";
        }
      }
    }

    ?>