mirror of
https://github.com/shuchkin/simplexlsxgen.git
synced 2023-08-10 21:12:59 +03:00
Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
5b58103e3b | |||
6d49a90fe7 | |||
c8a94d552a | |||
c9fa7da689 | |||
0d059fdf6e | |||
dcb5f8ad65 | |||
f970452779 | |||
6abd0286bb | |||
8bfbe078db |
33
CHANGELOG.md
33
CHANGELOG.md
@ -1,5 +1,38 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 1.0.19 (2021-07-28)
|
||||||
|
|
||||||
|
* Fixed sheet names duplicates
|
||||||
|
|
||||||
|
## 1.0.18 (2021-07-28)
|
||||||
|
|
||||||
|
* Fixed email regex
|
||||||
|
|
||||||
|
## 1.0.17 (2021-07-28)
|
||||||
|
|
||||||
|
* Fixed " and & in sheets names
|
||||||
|
|
||||||
|
## 1.0.16 (2021-07-01)
|
||||||
|
|
||||||
|
* Fixed "&" in hyperlinks
|
||||||
|
|
||||||
|
## 1.0.15 (2021-06-22)
|
||||||
|
|
||||||
|
* Fixed *mailto* hyperlinks detection
|
||||||
|
|
||||||
|
## 1.0.14 (2021-06-08)
|
||||||
|
|
||||||
|
* Added *mailto* hyperlinks support (thx Howard Martin)
|
||||||
|
```php
|
||||||
|
SimpleXLSXGen::fromArray([
|
||||||
|
['Mailto hyperlink', '<a href="mailto:sergey.shuchkin@gmail.com">Please email me</a>']
|
||||||
|
])->saveAs('test.xlsx');
|
||||||
|
```
|
||||||
|
## 1.0.13 (2021-05-29)
|
||||||
|
|
||||||
|
* Fixed hyperlinks in several sheets
|
||||||
|
* Added [Opencollective donation link](https://opencollective.com/simplexlsx)
|
||||||
|
|
||||||
## 1.0.12 (2021-05-19)
|
## 1.0.12 (2021-05-19)
|
||||||
|
|
||||||
* Fixed hyperlink regex
|
* Fixed hyperlink regex
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
# SimpleXLSXGen class 1.0.11 (Official)
|
# SimpleXLSXGen
|
||||||
[<img src="https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fshieldsio-patreon.herokuapp.com%2Fshuchkin" />](https://www.patreon.com/shuchkin) [<img src="https://img.shields.io/github/license/shuchkin/simplexlsxgen" />](https://github.com/shuchkin/simplexlsxgen/blob/master/license.md) [<img src="https://img.shields.io/github/stars/shuchkin/simplexlsxgen" />](https://github.com/shuchkin/simplexlsxgen/stargazers) [<img src="https://img.shields.io/github/forks/shuchkin/simplexlsxgen" />](https://github.com/shuchkin/simplexlsxgen/network) [<img src="https://img.shields.io/github/issues/shuchkin/simplexlsxgen" />](https://github.com/shuchkin/simplexlsxgen/issues)
|
[<img src="https://img.shields.io/github/license/shuchkin/simplexlsxgen" />](https://github.com/shuchkin/simplexlsxgen/blob/master/license.md) [<img src="https://img.shields.io/github/stars/shuchkin/simplexlsxgen" />](https://github.com/shuchkin/simplexlsxgen/stargazers) [<img src="https://img.shields.io/github/forks/shuchkin/simplexlsxgen" />](https://github.com/shuchkin/simplexlsxgen/network) [<img src="https://img.shields.io/github/issues/shuchkin/simplexlsxgen" />](https://github.com/shuchkin/simplexlsxgen/issues)
|
||||||
|
|
||||||
Export data to Excel XLSX file. PHP XLSX generator. No external tools and libraries.<br/>
|
Export data to Excel XLSX file. PHP XLSX generator. No external tools and libraries.<br/>
|
||||||
(!) XLSX reader [here](https://github.com/shuchkin/simplexlsx).
|
(!) XLSX reader [here](https://github.com/shuchkin/simplexlsx).
|
||||||
|
|
||||||
**Sergey Shuchkin** <sergey.shuchkin@gmail.com> 2020-2021<br/>
|
**Sergey Shuchkin** <sergey.shuchkin@gmail.com> 2020-2021<br/>
|
||||||
|
|
||||||
*Hey, bro, please ★ the package for my motivation :)*
|
*Hey, bro, please ★ the package for my motivation :) and [donate](https://opencollective.com/simplexlsx) for more motivation!*
|
||||||
|
|
||||||
## Basic Usage
|
## Basic Usage
|
||||||
```php
|
```php
|
||||||
|
@ -117,6 +117,14 @@ class SimpleXLSXGen {
|
|||||||
public function addSheet( array $rows, $name = null ) {
|
public function addSheet( array $rows, $name = null ) {
|
||||||
$this->curSheet++;
|
$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' => []];
|
$this->sheets[$this->curSheet] = ['name' => $name ?: 'Sheet'.($this->curSheet+1), 'hyperlinks' => []];
|
||||||
|
|
||||||
if ( is_array( $rows ) && isset( $rows[0] ) && is_array($rows[0]) ) {
|
if ( is_array( $rows ) && isset( $rows[0] ) && is_array($rows[0]) ) {
|
||||||
@ -217,7 +225,7 @@ class SimpleXLSXGen {
|
|||||||
} elseif ( $cfilename === 'xl/workbook.xml' ) {
|
} elseif ( $cfilename === 'xl/workbook.xml' ) {
|
||||||
$s = '';
|
$s = '';
|
||||||
foreach ( $this->sheets as $k => $v ) {
|
foreach ( $this->sheets as $k => $v ) {
|
||||||
$s .= '<sheet name="' . $v['name'] . '" sheetId="' . ( $k + 1) . '" state="visible" r:id="rId' . ( $k + 2) . '"/>';
|
$s .= '<sheet name="' . $this->esc( $v['name'] ) . '" sheetId="' . ( $k + 1) . '" state="visible" r:id="rId' . ( $k + 2) . '"/>';
|
||||||
}
|
}
|
||||||
$template = str_replace('{SHEETS}', $s, $template);
|
$template = str_replace('{SHEETS}', $s, $template);
|
||||||
$this->_writeEntry($fh, $cdrec, $cfilename, $template);
|
$this->_writeEntry($fh, $cdrec, $cfilename, $template);
|
||||||
@ -245,12 +253,12 @@ class SimpleXLSXGen {
|
|||||||
}
|
}
|
||||||
$xml = null;
|
$xml = null;
|
||||||
} elseif ( $cfilename === 'xl/worksheets/_rels/sheet1.xml.rels' ) {
|
} elseif ( $cfilename === 'xl/worksheets/_rels/sheet1.xml.rels' ) {
|
||||||
$RH = [];
|
|
||||||
foreach ( $this->sheets as $k => $v ) {
|
foreach ( $this->sheets as $k => $v ) {
|
||||||
if ( count($v['hyperlinks'])) {
|
if ( count($v['hyperlinks'])) {
|
||||||
|
$RH = [];
|
||||||
$filename = 'xl/worksheets/_rels/sheet' . ( $k + 1 ) . '.xml.rels';
|
$filename = 'xl/worksheets/_rels/sheet' . ( $k + 1 ) . '.xml.rels';
|
||||||
foreach ( $v['hyperlinks'] as $h ) {
|
foreach ( $v['hyperlinks'] as $h ) {
|
||||||
$RH[] = '<Relationship Id="' . $h['ID'] . '" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" Target="' . $h['H'] . '" TargetMode="External"/>';
|
$RH[] = '<Relationship Id="' . $h['ID'] . '" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" Target="' . $this->esc($h['H']) . '" TargetMode="External"/>';
|
||||||
}
|
}
|
||||||
$xml = str_replace( '{HYPERLINKS}', implode( "\r\n", $RH ), $template );
|
$xml = str_replace( '{HYPERLINKS}', implode( "\r\n", $RH ), $template );
|
||||||
$this->_writeEntry( $fh, $cdrec, $filename, $xml );
|
$this->_writeEntry( $fh, $cdrec, $filename, $xml );
|
||||||
@ -460,6 +468,10 @@ class SimpleXLSXGen {
|
|||||||
$this->sheets[ $idx ]['hyperlinks'][] = ['ID' => 'rId' . ( count( $this->sheets[ $idx ]['hyperlinks'] ) + 1 ), 'R' => $cname, 'H' => $h[0], 'L' => isset( $h[1] ) ? $h[1] : ''];
|
$this->sheets[ $idx ]['hyperlinks'][] = ['ID' => 'rId' . ( count( $this->sheets[ $idx ]['hyperlinks'] ) + 1 ), 'R' => $cname, 'H' => $h[0], 'L' => isset( $h[1] ) ? $h[1] : ''];
|
||||||
$F = self::F_HYPERLINK; // Hyperlink
|
$F = self::F_HYPERLINK; // Hyperlink
|
||||||
}
|
}
|
||||||
|
if ( preg_match( '/<a href="(mailto?:[^"]+)">(.*?)<\/a>/i', $v, $m ) ) {
|
||||||
|
$this->sheets[ $idx ]['hyperlinks'][] = ['ID' => 'rId' . ( count( $this->sheets[ $idx ]['hyperlinks'] ) + 1 ), 'R' => $cname, 'H' => $m[1], 'L' => ''];
|
||||||
|
$F = self::F_HYPERLINK; // mailto hyperlink
|
||||||
|
}
|
||||||
$v = strip_tags( $v );
|
$v = strip_tags( $v );
|
||||||
} // tags
|
} // tags
|
||||||
$vl = mb_strlen( $v );
|
$vl = mb_strlen( $v );
|
||||||
@ -500,7 +512,7 @@ class SimpleXLSXGen {
|
|||||||
$h = explode( '#', $v );
|
$h = explode( '#', $v );
|
||||||
$this->sheets[ $idx ]['hyperlinks'][] = ['ID' => 'rId' . ( count( $this->sheets[ $idx ]['hyperlinks'] ) + 1 ), 'R' => $cname, 'H' => $h[0], 'L' => isset( $h[1] ) ? $h[1] : ''];
|
$this->sheets[ $idx ]['hyperlinks'][] = ['ID' => 'rId' . ( count( $this->sheets[ $idx ]['hyperlinks'] ) + 1 ), 'R' => $cname, 'H' => $h[0], 'L' => isset( $h[1] ) ? $h[1] : ''];
|
||||||
$F = self::F_HYPERLINK; // Hyperlink
|
$F = self::F_HYPERLINK; // Hyperlink
|
||||||
} elseif ( preg_match( "/([a-zA-Z0-9_\.\-]+)@([a-zA-Z0-9\-]+)\.([a-zA-Z0-9\-\.]*)/i", $v ) ) {
|
} elseif ( preg_match( "/^[a-zA-Z0-9_\.\-]+@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/", $v ) ) {
|
||||||
$this->sheets[ $idx ]['hyperlinks'][] = ['ID' => 'rId' . ( count( $this->sheets[ $idx ]['hyperlinks'] ) + 1 ), 'R' => $cname, 'H' => 'mailto:' . $v, 'L' => ''];
|
$this->sheets[ $idx ]['hyperlinks'][] = ['ID' => 'rId' . ( count( $this->sheets[ $idx ]['hyperlinks'] ) + 1 ), 'R' => $cname, 'H' => 'mailto:' . $v, 'L' => ''];
|
||||||
$F = self::F_HYPERLINK; // Hyperlink
|
$F = self::F_HYPERLINK; // Hyperlink
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user