Import excel data in cakephp data base

Just write a function that will import a csv with fields you need. Not a cake example but similar and you should get the idea:

    public function incsv()
    {
        $file = 'C:\mydocs\incsv.csv';
        $content = file($file);
        $array = array();

        for ($i = 1; $i < count($content); $i++) {
            $line = explode(',', $content[$i]);
            for ($j = 0; $j < count($line); $j++) {
                $array[$i][$j + 1] = $line[$j];
            }
        }

        $k = count($array) + 1;
        for ($i = 1; $i < $k; $i++) {
            $tdate = new \DateTime($array[$i][2]);
            $ndate = $tdate->format('Y-m-d');
            $descraw = $array[$i][8];
            $descspace = preg_replace('/[^a-z\d ]/i', '', $descraw);
            $desc = preg_replace('/^\s+|\s+$|\s+(?=\s)/', '', $descspace);

            $amt = $array[$i][3];
            $namt = number_format($amt, 2, '.', '');
            if ($namt < 0) {
                $wd = $namt * -1;
                $dep = 0;
                } else {
                $dep = $namt;
            }
            $maxid = $this->Check->getMaxid();
            $checkid = $maxid + 1;

            $data = [
                'checkid' => $checkid,
                'transdate' => $ndate,
                'transdescribe' => $desc,
                'widthdraw' => $wd,
                'deposit' => $dep
            ];
            $this->Check->insertCsv($data);
        }
        $this->Check->checkRecalc();
        Url::redirect('check/index');
    }

I did not need to use all fields, so just got the needed ones.

To achieve something like:

Besides learning cake I would highly advise you to study and learn various PHP methods and functions. Cake is a PHP framework.

And the above is just an example you need to figure out your own routine that works in your case.

1 Like