diff --git a/CHANGELOG.md b/CHANGELOG.md index 87ebd5d..0ff791a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 1.0.19 (2021-07-28) + +* Fixed sheet names duplicates + ## 1.0.18 (2021-07-28) * Fixed email regex diff --git a/src/SimpleXLSXGen.php b/src/SimpleXLSXGen.php index 95a43c6..67d81b2 100644 --- a/src/SimpleXLSXGen.php +++ b/src/SimpleXLSXGen.php @@ -117,6 +117,14 @@ class SimpleXLSXGen { public function addSheet( array $rows, $name = null ) { $this->curSheet++; + if ( $name !== null ) { + foreach( $this->sheets as $sh ) { + if ( $name === $sh['name'] ) { + $name .= ' ' . mt_rand( 100000, 999999 ); + } + } + } + $this->sheets[$this->curSheet] = ['name' => $name ?: 'Sheet'.($this->curSheet+1), 'hyperlinks' => []]; if ( is_array( $rows ) && isset( $rows[0] ) && is_array($rows[0]) ) {