<?php


namespace app\controller;
use think\facade\Request;

class Nlp
{
    public function submit(){
        $file =  Request::file('file');
        $url = public_path(). 'text.xlsx';
        file_put_contents($url,file_get_contents($file));
        $objPHPExcel = \PHPExcel_IOFactory::load($url);
        $sheet = $objPHPExcel->getSheet(0);
        $row = $sheet->getHighestRow();
        $column = $sheet->getHighestColumn();
        $line = $row - 1;
        if ($line <= 0){
            return json(['result'=>false]);
        }
        $columnIndex = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N'];
        $tableHeader = [];
        for ($i = 0; $i < $column; $i++){
            $tableHeader[] = $objPHPExcel->getActiveSheet()->getCell($columnIndex[$i].'1')->getValue();
        }
        $data = [];
        for ($j = 2; $j <= $row; $j++){
            $num = 0;
            $columnData = [];
            foreach ($columnIndex as $index){
                if ($num > $column){
                    break;
                }
                $columnData[$tableHeader[$num]] = $objPHPExcel->getActiveSheet()->getCell($index.$j)->getValue();
                $num++;
            }
            $data[] = $columnData;
        }
        return json($data);
    }
}
