* Read the Data * @param $option * @return array * @throws NotFoundException * @throws \OCP\Files\NotPermittedException * @throws Exception * @throws \PhpOffice\PhpSpreadsheet\Exception */
($option)
| 101 | * @throws \PhpOffice\PhpSpreadsheet\Exception |
| 102 | */ |
| 103 | public function readData($option): array { |
| 104 | $header = $dataClean = $data = array(); |
| 105 | $headerrow = $error = 0; |
| 106 | |
| 107 | $file = $this->rootFolder->getUserFolder($option['user_id'])->get($option['link']); |
| 108 | $cache = $this->getCacheMetadata($option, $file->getMTime()); |
| 109 | if ($cache['notModified'] === true) { |
| 110 | return [ |
| 111 | 'header' => [], |
| 112 | 'dimensions' => [], |
| 113 | 'data' => [], |
| 114 | 'error' => $error, |
| 115 | 'cache' => $cache, |
| 116 | ]; |
| 117 | } |
| 118 | |
| 119 | include_once __DIR__ . '/../../vendor/autoload.php'; |
| 120 | $fileName = $file->getStorage()->getLocalFile($file->getInternalPath()); |
| 121 | |
| 122 | $inputFileType = IOFactory::identify($fileName); |
| 123 | $reader = IOFactory::createReader($inputFileType); |
| 124 | //$reader->setReadDataOnly(true); disabled as idDate is not working otherwise |
| 125 | if (strlen($option['sheet']) > 0) { |
| 126 | $reader->setLoadSheetsOnly([$option['sheet']]); |
| 127 | } |
| 128 | |
| 129 | $rangeError = $this->validateRanges((string)$option['range']); |
| 130 | if ($rangeError !== null) { |
| 131 | return [ |
| 132 | 'header' => [], |
| 133 | 'dimensions' => [], |
| 134 | 'data' => [], |
| 135 | 'error' => $rangeError, |
| 136 | 'cache' => $cache, |
| 137 | ]; |
| 138 | } |
| 139 | |
| 140 | $spreadsheet = $reader->load($fileName); |
| 141 | |
| 142 | // separated columns can be selected via ranges e.g. "A1:B9,C1:C9" |
| 143 | // these ranges are read and linked |
| 144 | $ranges = str_getcsv($option['range']); |
| 145 | foreach ($ranges as $range) { |
| 146 | $values = $spreadsheet->getActiveSheet() |
| 147 | ->rangeToArray($range, // The worksheet range that we want to retrieve |
| 148 | null, // Value that should be returned for empty cells |
| 149 | true, // Should formulas be calculated (the equivalent of getCalculatedValue() for each cell) |
| 150 | true, // Should values be formatted (the equivalent of getFormattedValue() for each cell) |
| 151 | false // Should the array be indexed by cell row and cell column |
| 152 | ); |
| 153 | |
| 154 | $values = $this->convertExcelDate($spreadsheet, $values, $range); |
| 155 | |
| 156 | if (empty($data)) { |
| 157 | // first range will fill the array with all rows |
| 158 | $data = $values; |
| 159 | } else { |
| 160 | // further columns will be attached to the first ones |
nothing calls this directly
no test coverage detected