0

I would like someone to help me find a solution to my two problems: I have an excel file with 2 columns (A and B)

Column A contains barcode numbers that I must assign to an order number (in column B). Below an example:

COLUMN A....................COLUMN B
barcode.........................order number

12345678*******************35098
98765432 ******************35433
45454545
66554433
98766334 *******************43221

What I am looking for is the following:

from a given order number (in a variable), I would like to know if it exists in column B, if yes, I would like to recover its bar code.

If it does not exist, I would like to add this order number in one of the empty cells in column B and then retrieve the barcode that has been assigned to it.

All this using PHPExcel ... I tried some, but I'm blocking ... If anyone could help me, I'd be very grateful to him.

Thank you

PS: A small precision, if you have to know the number of non-empty line of column A, we will say that there are 1000 lines

Here what I did. This code only check if the order number exist. But I'm not sure if this is the best way:

with this code, I know if the ordernumber exist in file. My problem now is how to get the bar code number if the ordernumber exist in column B, or if it doesn't exist, how to add the order number in one of the empty cells and retrieve the corresponding barcode

Thanks to everyone for your help

<?php
$orderNumber = 12341;


function searchOrder ($num){

    /** PHPExcel_IOFactory */
    require_once 'Classes/PHPExcel/IOFactory.php';

    $objReader = PHPExcel_IOFactory::createReader('Excel2007');
    $objPHPExcel = $objReader->load("barreCode_ordernumber.xlsx");


    $foundInCells = array();
    $ordernumber = $num;
    foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
        foreach ($worksheet->getRowIterator() as $row) {
            $cellIterator = $row->getCellIterator();
            $cellIterator->setIterateOnlyExistingCells(false);
            foreach ($cellIterator as $cell) {
                    $numligne = $cell->getRow();
                    $numcolonne = $cell->getColumn();
                if ($cell->getValue() == $ordernumber) {
                    return true;
                }
            }
        }
    }
}
?>
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149

0 Answers0