moonlandsoft / yii2-phpexcel

Exporting PHP to Excel
MIT License
135 stars 89 forks source link

Don't read all sheets when $getOnlySheet is set #1

Closed martinkolarik-ext54836 closed 8 years ago

martinkolarik-ext54836 commented 8 years ago

I have raw data in first sheet and some other data with formuals and formating plus some macros in others. If I set $getOnlySheet for first sheet than it will try to read all sheets anyway but outputs just the first one. Which is okay as long as those other sheets don't brake whole process. Also it takes longer time to read it becasue of other sheets.

I fix it with by using this code around line 590

if (isset($this->getOnlySheet) && $this->getOnlySheet != null) {
   if(!$objectPhpExcel->getSheetByName($this->getOnlySheet)) {
      return $sheetDatas;
   }
   $objectPhpExcel->setActiveSheetIndexByName($this->getOnlySheet);
   $indexed = $this->getOnlySheet;
   $sheetDatas[$indexed] = $objectPhpExcel->getActiveSheet()->toArray(null, true, true, true);
   if ($this->setFirstRecordAsKeys) {
      $sheetDatas[$indexed] = $this->executeArrayLabel($sheetDatas[$indexed]);
   }
   if (!empty($this->getOnlyRecordByIndex)) {
      $sheetDatas[$indexed] = $this->executeGetOnlyRecords($sheetDatas[$indexed], $this->getOnlyRecordByIndex);
   }
   if (!empty($this->leaveRecordByIndex)) {
      $sheetDatas[$indexed] = $this->executeLeaveRecords($sheetDatas[$indexed], $this->leaveRecordByIndex);
   }
   return $sheetDatas[$indexed];
}

I gues it could be done more elegant.