public static function setSheet($sheet=0, $title=NULL, $normalizeTitle=false)
    {
        self::resetSheet();

        if (is_object($sheet)) {
            
            self::$_objSheet = &$sheet;
        } 
        elseif (is_numeric($sheet) && $sheet>=0 && self::$_objSpreadsheet) {

            /* Sheets Check */
            $sheetCount = self::$_objSpreadsheet->getSheetCount();
            if ($sheet >= $sheetCount) {
                for ($i=$sheetCount; $i <= $sheet; $i++) { 
                    self::$_objSpreadsheet->createSheet($i);
                }
            }
            // Select sheet
            self::$_objSheet = self::$_objSpreadsheet->setActiveSheetIndex($sheet);
        }
        elseif (is_null($sheet) && self::$_objSpreadsheet) {
            // Auto create a sheet without index
            self::setSheet(self::getSheetCount());
        }
        else {
            throw new Exception("Invalid or empty PhpSpreadsheet Object for setting sheet", 400);
        }

        // Sheet Title
        if ($title) {
            // Auto-normalize title rule 
            if ($normalizeTitle) {
                /**
                 * @see PhpOffice\PhpSpreadsheet\Worksheet\Worksheet
                 */
                // Some of the printable ASCII characters are invalid:  * : / \ ? [ ]
                $title = str_replace(self::$_invalidCharacters, '', $title);
                // Maximum 31 characters allowed for sheet title
                $title = mb_substr($title, 0, 31);
            }

            self::$_objSheet->setTitle($title);
        }

        return new static();
    }
public static function setSheet($sheet=0, $title=NULL, $normalizeTitle=false)
    {
        self::resetSheet();

        if (is_object($sheet)) {
            
            self::$_objSheet = &$sheet;
        } 
        elseif (is_numeric($sheet) && $sheet>=0 && self::$_objSpreadsheet) {

            /* Sheets Check */
            $sheetCount = self::$_objSpreadsheet->getSheetCount();
            if ($sheet >= $sheetCount) {
                for ($i=$sheetCount; $i <= $sheet; $i++) { 
                    self::$_objSpreadsheet->createSheet($i);
                }
            }
            // Select sheet
            self::$_objSheet = self::$_objSpreadsheet->setActiveSheetIndex($sheet);
        }
        elseif (is_null($sheet) && self::$_objSpreadsheet) {
            // Auto create a sheet without index
            self::setSheet(self::getSheetCount());
        }
        else {
            throw new Exception("Invalid or empty PhpSpreadsheet Object for setting sheet", 400);
        }

        // Sheet Title
        if ($title) {
            // Auto-normalize title rule 
            if ($normalizeTitle) {
                /**
                 * @see PhpOffice\PhpSpreadsheet\Worksheet\Worksheet
                 */
                // Some of the printable ASCII characters are invalid:  * : / \ ? [ ]
                $title = str_replace(self::$_invalidCharacters, '', $title);
                // Maximum 31 characters allowed for sheet title
                $title = mb_substr($title, 0, 31);
            }

            self::$_objSheet->setTitle($title);
        }

        return new static();
    }
public static function setSheet ( $ sheet = 0 , $ title = NULL , $ normalizeTitle = false ) { self :: resetSheet ( ) ; if ( is_object ( $ sheet ) ) { self :: $ _objSheet = & $ sheet ; } elseif ( is_numeric ( $ sheet ) && $ sheet >= 0 && self :: $ _objSpreadsheet ) { /* Sheets Check */ $ sheetCount = self :: $ _objSpreadsheet -> getSheetCount ( ) ; if ( $ sheet >= $ sheetCount ) { for ( $ i = $ sheetCount ; $ i <= $ sheet ; $ i ++ ) { self :: $ _objSpreadsheet -> createSheet ( $ i ) ; } } // Select sheet self :: $ _objSheet = self :: $ _objSpreadsheet -> setActiveSheetIndex ( $ sheet ) ; } elseif ( is_null ( $ sheet ) && self :: $ _objSpreadsheet ) { // Auto create a sheet without index self :: setSheet ( self :: getSheetCount ( ) ) ; } else { throw new Exception ( "Invalid or empty PhpSpreadsheet Object for setting sheet" , 400 ) ; } // Sheet Title if ( $ title ) { // Auto-normalize title rule  if ( $ normalizeTitle ) { /**
                 * @see PhpOffice\PhpSpreadsheet\Worksheet\Worksheet
                 */ // Some of the printable ASCII characters are invalid:  * : / \ ? [ ] $ title = str_replace ( self :: $ _invalidCharacters , '' , $ title ) ; // Maximum 31 characters allowed for sheet title $ title = mb_substr ( $ title , 0 , 31 ) ; } self :: $ _objSheet -> setTitle ( $ title ) ; } return new static ( ) ; }
Set an active PhpSpreadsheet Sheet

@param object|int $sheet PhpSpreadsheet sheet object or index number
@param string $title Sheet title
@param bool $normalizeTitle Auto-normalize title rule
@return self
Set an active PhpSpreadsheet Sheet