mirror of
https://github.com/shuchkin/simplexlsxgen.git
synced 2023-08-10 21:12:59 +03:00
Compare commits
38 Commits
Author | SHA1 | Date | |
---|---|---|---|
306aa7dad9 | |||
dc974d2ef9 | |||
c78750ffe7 | |||
9cdb08ee98 | |||
32276c4486 | |||
3646e702ae | |||
81120e6f72 | |||
c449813bb1 | |||
4f4ac11dae | |||
1fa442f667 | |||
1ee4e5eb50 | |||
e02d764d0d | |||
f65e57c735 | |||
4f3d09925c | |||
95da6b5c05 | |||
b3060667f2 | |||
cb19defa37 | |||
5a154b24f9 | |||
b46f63fce7 | |||
bb09c0d38c | |||
91ca3f6fff | |||
59cdc277ee | |||
343e549ca1 | |||
61e55d6277 | |||
9b52ff6ac7 | |||
317fb0982e | |||
765001ae96 | |||
c2f3077812 | |||
af53c754c3 | |||
6d7608f8ca | |||
80091bb9be | |||
21b1d9a4b8 | |||
c1434378bc | |||
75252a4a0c | |||
f9d5480bb3 | |||
aff0fa243d | |||
82b0db1f8e | |||
aef6ee4935 |
30
CHANGELOG.md
30
CHANGELOG.md
@ -1,4 +1,34 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 1.3.15 (2023-04-19)
|
||||||
|
* added meta: setTitle, setSubject, setAuthor, setCompany, setManager, setKeywords, setDescription, setCategory, setApplication, setLastModifiedBy. Thx [Oleg Kosarev](https://github.com/DevOlegKosarev)
|
||||||
|
|
||||||
|
## 1.3.14 (2023-04-18)
|
||||||
|
* fixed "This action doesn't work on multiple selection" error
|
||||||
|
|
||||||
|
## 1.3.13 (2023-04-11)
|
||||||
|
* ```$xlsx->rightToLeft()``` - RTL mode. Column A is on the far right, Column B is one column left of Column A, and so on. Also, information in cells is displayed in the Right to Left format.
|
||||||
|
|
||||||
|
## 1.3.12 (2023-03-31)
|
||||||
|
* ```<style font-size="32">Big Text</style>``` - font size in cells, thx [Andrew Robinson](https://github.com/mrjemson)
|
||||||
|
|
||||||
|
## 1.3.11 (2023-03-28)
|
||||||
|
* freezePanes( corner_cell ) - freezePanes to keep an area of a worksheet visible while you scroll, corner_cell is not included, thx [Javier](https://github.com/xaviermdq)
|
||||||
|
|
||||||
|
## 1.3.10 (2022-12-14)
|
||||||
|
* added borders ```<style border="medium">Black Border</style>``` see colored [examples](https://github.com/shuchkin/simplexlsxgen#formatting)
|
||||||
|
* added formulas ```<f v="100">SUM(B1:B10)</f>``` see [examples](https://github.com/shuchkin/simplexlsxgen#data-types)
|
||||||
|
* added internal links ```<a href="sheet2!A1">Go to page 2</a>```
|
||||||
|
* added custom number formats ```<style nf=""£"#,##0.00">500</style>```
|
||||||
|
* added 3 currencies ```$data = [ ['$100.23', '2000.00 €', '1200.30 ₽'] ];```
|
||||||
|
|
||||||
|
## 1.2.16 (2022-08-12)
|
||||||
|
* added `autoFilter( $range )`
|
||||||
|
```php
|
||||||
|
$xlsx->autoFilter('A2:B10');
|
||||||
|
```
|
||||||
|
* fixed `0%` bug
|
||||||
|
|
||||||
## 1.2.15 (2022-07-05)
|
## 1.2.15 (2022-07-05)
|
||||||
* added wrap words in long strings `<wraptext>long long line</wraptext>`
|
* added wrap words in long strings `<wraptext>long long line</wraptext>`
|
||||||
|
|
||||||
|
101
README.md
101
README.md
@ -6,7 +6,7 @@ Export data to Excel XLSX file. PHP XLSX generator. No external tools and librar
|
|||||||
- XLS reader [here](https://github.com/shuchkin/simplexls)
|
- XLS reader [here](https://github.com/shuchkin/simplexls)
|
||||||
- CSV reader/writer [here](https://github.com/shuchkin/simplecsv)
|
- CSV reader/writer [here](https://github.com/shuchkin/simplecsv)
|
||||||
|
|
||||||
**Sergey Shuchkin** <sergey.shuchkin@gmail.com> 2020-2022<br/>
|
**Sergey Shuchkin** <sergey.shuchkin@gmail.com> 2020-2023<br/>
|
||||||
|
|
||||||
*Hey, bro, please ★ the package for my motivation :) and [donate](https://opencollective.com/simplexlsx) for more motivation!*
|
*Hey, bro, please ★ the package for my motivation :) and [donate](https://opencollective.com/simplexlsx) for more motivation!*
|
||||||
|
|
||||||
@ -33,22 +33,30 @@ $ composer require shuchkin/simplexlsxgen
|
|||||||
or download class [here](https://github.com/shuchkin/simplexlsxgen/blob/master/src/SimpleXLSXGen.php)
|
or download class [here](https://github.com/shuchkin/simplexlsxgen/blob/master/src/SimpleXLSXGen.php)
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
Use UTF-8 encoded strings.
|
||||||
### Data types
|
### Data types
|
||||||
```php
|
```php
|
||||||
$data = [
|
$data = [
|
||||||
['Integer', 123],
|
['Integer', 123],
|
||||||
['Float', 12.35],
|
['Float', 12.35],
|
||||||
['Percent', '12%'],
|
['Percent', '12%'],
|
||||||
|
['Currency $', '$500.67'],
|
||||||
|
['Currency €', '200 €'],
|
||||||
|
['Currency ₽', '1200.30 ₽'],
|
||||||
|
['Currency (other)', '<style nf=""£"#,##0.00">500</style>'],
|
||||||
|
['Currency Float (other)', '<style nf="#,##0.00\ [$£-1];[Red]#,##0.00\ [$£-1]">500.250</style>'],
|
||||||
['Datetime', '2020-05-20 02:38:00'],
|
['Datetime', '2020-05-20 02:38:00'],
|
||||||
['Date','2020-05-20'],
|
['Date', '2020-05-20'],
|
||||||
['Time','02:38:00'],
|
['Time', '02:38:00'],
|
||||||
['Datetime PHP', new DateTime('2021-02-06 21:07:00')],
|
['Datetime PHP', new DateTime('2021-02-06 21:07:00')],
|
||||||
['String', 'Long UTF-8 String in autoresized column'],
|
['String', 'Very long UTF-8 string in autoresized column'],
|
||||||
|
['Formula', '<f v="135.35">SUM(B1:B2)</f>'],
|
||||||
['Hyperlink', 'https://github.com/shuchkin/simplexlsxgen'],
|
['Hyperlink', 'https://github.com/shuchkin/simplexlsxgen'],
|
||||||
['Hyperlink + Anchor', '<a href="https://github.com/shuchkin/simplexlsxgen">SimpleXLSXGen</a>'],
|
['Hyperlink + Anchor', '<a href="https://github.com/shuchkin/simplexlsxgen">SimpleXLSXGen</a>'],
|
||||||
['RAW string', "\0".'2020-10-04 16:02:00']
|
['Internal link', '<a href="sheet2!A1">Go to second page</a>'],
|
||||||
|
['RAW string', "\0" . '2020-10-04 16:02:00']
|
||||||
];
|
];
|
||||||
Shuchkin\SimpleXLSXGen::fromArray( $data )->saveAs('datatypes.xlsx');
|
SimpleXLSXGen::fromArray($data)->saveAs('datatypes.xlsx');
|
||||||
```
|
```
|
||||||

|

|
||||||
|
|
||||||
@ -65,7 +73,11 @@ $data = [
|
|||||||
['Italic + Hyperlink + Anchor', '<i><a href="https://github.com/shuchkin/simplexlsxgen">SimpleXLSXGen</a></i>'],
|
['Italic + Hyperlink + Anchor', '<i><a href="https://github.com/shuchkin/simplexlsxgen">SimpleXLSXGen</a></i>'],
|
||||||
['Green', '<style color="#00FF00">12345.67</style>'],
|
['Green', '<style color="#00FF00">12345.67</style>'],
|
||||||
['Bold Red Text', '<b><style color="#FF0000">12345.67</style></b>'],
|
['Bold Red Text', '<b><style color="#FF0000">12345.67</style></b>'],
|
||||||
|
['Size 32 Font', '<style font-size="32">Big Text</style>'],
|
||||||
['Blue Text and Yellow Fill', '<style bgcolor="#FFFF00" color="#0000FF">12345.67</style>'],
|
['Blue Text and Yellow Fill', '<style bgcolor="#FFFF00" color="#0000FF">12345.67</style>'],
|
||||||
|
['Border color', '<style border="#000000">Black Thin Border</style>'],
|
||||||
|
['<top>Border style</top>','<style border="medium"><wraptext>none, thin, medium, dashed, dotted, thick, double, hair, mediumDashed, dashDot,mediumDashDot, dashDotDot, mediumDashDotDot, slantDashDot</wraptext></style>'],
|
||||||
|
['Border sides', '<style border="none dotted#0000FF medium#FF0000 double">Top No + Right Dotted + Bottom medium + Left double</style>'],
|
||||||
['Left', '<left>12345.67</left>'],
|
['Left', '<left>12345.67</left>'],
|
||||||
['Center', '<center>12345.67</center>'],
|
['Center', '<center>12345.67</center>'],
|
||||||
['Right', '<right>Right Text</right>'],
|
['Right', '<right>Right Text</right>'],
|
||||||
@ -75,17 +87,32 @@ $data = [
|
|||||||
['Middle + Center', '<style height="50"><middle><center>Middle + Center</center></middle></style>'],
|
['Middle + Center', '<style height="50"><middle><center>Middle + Center</center></middle></style>'],
|
||||||
['Bottom + Right', '<style height="50"><bottom><right>Bottom + Right</right></bottom></style>'],
|
['Bottom + Right', '<style height="50"><bottom><right>Bottom + Right</right></bottom></style>'],
|
||||||
['<center>MERGE CELLS MERGE CELLS MERGE CELLS MERGE CELLS MERGE CELLS</center>', null],
|
['<center>MERGE CELLS MERGE CELLS MERGE CELLS MERGE CELLS MERGE CELLS</center>', null],
|
||||||
['<top>Word wrap</top>', "<wraptext>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book</wraptext>"]
|
['<top>Word wrap</top>', "<wraptext>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book</wraptext>"],
|
||||||
];
|
];
|
||||||
SimpleXLSXGen::fromArray( $data )
|
SimpleXLSXGen::fromArray($data)
|
||||||
->setDefaultFont( 'Courier New' )
|
->setDefaultFont('Courier New')
|
||||||
->setDefaultFontSize( 14 )
|
->setDefaultFontSize(14)
|
||||||
->setColWidth(1, 35) // 1 - num column, 35 - size in chars
|
->setColWidth(1, 35)
|
||||||
->mergeCells('A20:B20')
|
->mergeCells('A20:B20')
|
||||||
->saveAs('styles_and_tags.xlsx');
|
->saveAs('styles_and_tags.xlsx');
|
||||||
```
|
```
|
||||||

|

|
||||||
|
|
||||||
|
### RAW Strings
|
||||||
|
Prefix #0 cell value (use double quotes).
|
||||||
|
```php
|
||||||
|
$PushkinDOB = '1799-07-06';
|
||||||
|
$data = [
|
||||||
|
['Datetime as raw string', "\0".'2023-01-09 11:16:34'],
|
||||||
|
['Date as raw string', "\0".$PushkinDOB],
|
||||||
|
['Disable type detection', "\0".'+12345'],
|
||||||
|
['Insert greater/less them simbols', "\0".'20- short term: <6 month'],
|
||||||
|
|
||||||
|
];
|
||||||
|
SimpleXLSXGen::fromArray($data)
|
||||||
|
->saveAs('test_rawstrings.xlsx');
|
||||||
|
```
|
||||||
|
|
||||||
### More examples
|
### More examples
|
||||||
```php
|
```php
|
||||||
// Fluid interface, output to browser for download
|
// Fluid interface, output to browser for download
|
||||||
@ -104,6 +131,30 @@ $xlsx->addSheet( $books, 'Catalog 2021' );
|
|||||||
$xlsx->addSheet( $books2, 'Stephen King catalog');
|
$xlsx->addSheet( $books2, 'Stephen King catalog');
|
||||||
$xlsx->downloadAs('books_2021.xlsx');
|
$xlsx->downloadAs('books_2021.xlsx');
|
||||||
exit();
|
exit();
|
||||||
|
|
||||||
|
// Autofilter
|
||||||
|
$xlsx->autoFilter('A1:B10');
|
||||||
|
|
||||||
|
// Freeze rows and columns from top-left corner up to, but not including,
|
||||||
|
// the row and column of the indicated cell
|
||||||
|
$xlsx->freezePanes('C3');
|
||||||
|
|
||||||
|
// RTL mode
|
||||||
|
// Column A is on the far right, Column B is one column left of Column A, and so on. Also, information in cells is displayed in the Right to Left format.
|
||||||
|
$xlsx->rightToLeft();
|
||||||
|
|
||||||
|
// Set Meta Data Files
|
||||||
|
// this data in propertis Files and Info file in Office
|
||||||
|
$xlsx->setAuthor('Sergey Shuchkin <sergey.shuchkin@gmail.com>')
|
||||||
|
->setCompany('Microsoft <info@microsoft.com>')
|
||||||
|
->setManager('Bill Gates <bill.gates@microsoft.com>')
|
||||||
|
->setLastModifiedBy("Sergey Shuchkin <sergey.shuchkin@gmail.com>")
|
||||||
|
->setTitle('This is Title')
|
||||||
|
->setSubject('This is Subject')
|
||||||
|
->setKeywords('Keywords1, Keywords2, Keywords3, KeywordsN')
|
||||||
|
->setDescription('This is Description')
|
||||||
|
->setCategory('This is Сategory')
|
||||||
|
->setApplication('Shuchkin\SimpleXLSXGen')
|
||||||
```
|
```
|
||||||
### JS array to Excel (AJAX)
|
### JS array to Excel (AJAX)
|
||||||
```php
|
```php
|
||||||
@ -131,17 +182,29 @@ function array2excel() {
|
|||||||
|
|
||||||
var request = new XMLHttpRequest();
|
var request = new XMLHttpRequest();
|
||||||
|
|
||||||
request.onreadystatechange = function () {
|
request.onload = function () {
|
||||||
if (this.readyState === 4) {
|
if (this.status === 200) {
|
||||||
if (this.status === 200) {
|
var file = new Blob([this.response], {type: this.getResponseHeader('Content-Type')});
|
||||||
var file = new Blob([this.response], {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});
|
var fileURL = URL.createObjectURL(file);
|
||||||
var fileURL = URL.createObjectURL(file);
|
var filename = "", m;
|
||||||
window.open(fileURL);
|
var disposition = this.getResponseHeader('Content-Disposition');
|
||||||
} else {
|
if (disposition && (m = /"([^"]+)"/.exec(disposition)) !== null) {
|
||||||
alert("Error: " + this.status + " " + this.statusText);
|
filename = m[1];
|
||||||
}
|
}
|
||||||
|
var a = document.createElement("a");
|
||||||
|
if (typeof a.download === 'undefined') {
|
||||||
|
window.location = fileURL;
|
||||||
|
} else {
|
||||||
|
a.href = fileURL;
|
||||||
|
a.download = filename;
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
alert("Error: " + this.status + " " + this.statusText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
request.open('POST', "array2excel.php");
|
request.open('POST', "array2excel.php");
|
||||||
request.responseType = "blob";
|
request.responseType = "blob";
|
||||||
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "shuchkin/simplexlsxgen",
|
"name": "shuchkin/simplexlsxgen",
|
||||||
"description": "Export data to Excel XLSx file. PHP XLSX generator.",
|
"description": "Export data to Excel XLSx file. PHP XLSX generator.",
|
||||||
"keywords": ["php", "excel", "xlsx", "generator", "creator", "backend"],
|
"keywords": ["php", "excel", "xlsx", "generator", "writer", "creator", "backend"],
|
||||||
"homepage": "https://github.com/shuchkin/simplexlsxgen",
|
"homepage": "https://github.com/shuchkin/simplexlsxgen",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"authors": [
|
"authors": [
|
||||||
|
BIN
datatypes.png
BIN
datatypes.png
Binary file not shown.
Before Width: | Height: | Size: 45 KiB After Width: | Height: | Size: 14 KiB |
File diff suppressed because it is too large
Load Diff
BIN
styles.png
BIN
styles.png
Binary file not shown.
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 190 KiB |
Reference in New Issue
Block a user