Download app/Services/Chatbot/ParserExcelService.php from pnacorp/magicai: direct link, hf CLI and curl.
- Browser
- Download file 1.18 kB
-
https://huggingface.co/pnacorp/magicai/resolve/main/app/Services/Chatbot/ParserExcelService.php
- Command line
-
hf download hf://pnacorp/magicai/app/Services/Chatbot/ParserExcelService.php
-
curl -L -o ParserExcelService.php https://huggingface.co/pnacorp/magicai/resolve/main/app/Services/Chatbot/ParserExcelService.php
1.18 kB
| namespace App\Services\Chatbot; | |
| use Illuminate\Support\Arr; | |
| use Illuminate\Validation\ValidationException; | |
| class ParserExcelService | |
| { | |
| public string $text; | |
| public string $path; | |
| public function parse(): string | |
| { | |
| $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load( | |
| $this->path | |
| ); | |
| $data = $spreadsheet->getActiveSheet()->toArray(); | |
| if (empty($data)) { | |
| throw ValidationException::withMessages([ | |
| 'file' => trans('File format is not correct.'), | |
| ]); | |
| } | |
| $data = Arr::flatten($data); | |
| $data = array_filter($data, function ($value) { | |
| return ! empty($value); | |
| }); | |
| $this->setText(implode(' ', $data)); | |
| return $this->getText(); | |
| } | |
| public function setPath(string $path): ParserExcelService | |
| { | |
| $this->path = $path; | |
| return $this; | |
| } | |
| public function getPath(): string | |
| { | |
| return $this->path; | |
| } | |
| public function getText(): string | |
| { | |
| return $this->text; | |
| } | |
| public function setText(string $text): void | |
| { | |
| $this->text = $text; | |
| } | |
| } | |