1
0
mirror of https://github.com/shuchkin/simplexlsxgen.git synced 2023-08-10 21:12:59 +03:00

34 Commits

Author SHA1 Message Date
053574d1e1 1.2.15 2022-07-05 11:29:18 +06:00
f74163d311 1.2.15 2022-07-05 11:19:42 +06:00
0bf38275d7 1.2.14 2022-06-10 12:11:00 +06:00
459b1666e9 1.2.13 2022-06-10 12:07:39 +06:00
b63c66f8e9 1.2.13 2022-06-01 12:58:01 +06:00
1b5701a07f 1.2.13 2022-06-01 12:54:28 +06:00
199e5691e7 1.2.12 2022-05-17 12:10:24 +06:00
c54b314328 1.2.12 2022-05-17 12:06:30 +06:00
6db113f753 1.2.11 2022-05-17 12:03:35 +06:00
ff3f016358 1.2.11 2022-04-30 14:08:40 +06:00
bcd3586731 1.2.10 2022-04-30 14:04:13 +06:00
402c6b9417 1.2.10 2022-04-24 14:59:15 +06:00
5840fd5285 Merge pull request #58 from mrjemson/master
Added Font Color and Background Color Capabilities
2022-04-23 13:07:03 +06:00
4543922330 Updated examples 2022-04-23 11:34:13 +10:00
d49f8996df Switched to style tags 2022-04-23 11:33:17 +10:00
5309e6a002 Removed duplicate line 2022-04-22 23:21:40 +10:00
ab28bc319d Added missing line break 2022-04-22 23:19:38 +10:00
e145bd5777 Updated examples to include background fill 2022-04-22 23:16:28 +10:00
2ee7237016 Updated class to include background fill options 2022-04-22 23:15:35 +10:00
a0a932e2f5 Updated Styles Image for Background Fill 2022-04-22 23:14:42 +10:00
fc884044ac Color Code Clean Up 2022-04-22 18:03:17 +10:00
d84c842d38 Corrected const C_NORMAL value 2022-04-22 17:59:30 +10:00
0dafc8bf9e Fixes for color updates 2022-04-22 17:58:25 +10:00
82f19a9f35 Updated styles.png 2022-04-22 17:54:51 +10:00
139602c340 Update README.md 2022-04-22 17:51:35 +10:00
ac34d8f527 Added Font Color 2022-04-22 16:43:26 +10:00
c55d77c63e 1.1.12 2022-03-15 21:49:14 +06:00
c3d10db967 1.1.12 2022-03-15 21:47:33 +06:00
1c206d06bc 1.1.11 2022-02-12 03:25:59 +06:00
f0cbc32af9 1.1.11 2022-02-12 03:04:46 +06:00
121f1222c2 1.1.10 2022-02-05 18:32:10 +06:00
40eb704eb2 1.0.23 2022-02-01 02:50:32 +06:00
4005e8cbd1 Merge pull request #48 from appel/patch-1
added a ; in the Debug section.
2021-11-28 20:43:00 +06:00
9d82a43fe6 added a ; in the Debug section. 2021-11-28 08:48:15 -05:00
7 changed files with 834 additions and 620 deletions

3
.gitignore vendored
View File

@ -1,4 +1,5 @@
vendor*
/vendor*
/books.fw.png
/datatypes.fw.png
/styles.fw.png
/.gitignore

View File

@ -1,4 +1,35 @@
# Changelog
## 1.2.15 (2022-07-05)
* added wrap words in long strings `<wraptext>long long line</wraptext>`
## 1.2.14 (2022-06-10)
* added example [JS array to Excel (AJAX)](https://github.com/shuchkin/simplexlsxgen#js-array-to-excel-ajax)
## 1.2.13 (2022-06-01)
* setColWidth(num_col_started_1, size_in_chars) - set column width
## 1.2.12 (2022-05-17)
* Vertical align (tags top,middle,bottom) `<bottom>12345</bottom>`
## 1.2.11 (2022-05-01)
* Row height `<style height="50">Custom row height 50</style>`
## 1.2.10 (2022-04-24)
* Added colors `<style color="#FFFF00" bgcolor="#00FF00">Yellow text on blue background</style>`, thx [mrjemson](https://github.com/mrjemson)
## 1.1.12 (2022-03-15)
* Added `$xlsx->mergeCells('A1:C1')`
## 1.1.11 (2022-02-05)
* sheet name maximum length is 31 chars, mb_substr used now
* license fixed
## 1.1.10 (2022-02-05)
* namespace added, use Shuchkin\SimpleXLSXGen
## 1.0.23 (2022-02-01)
* fixed dates if year < 1900 and time only cells, thx [fapth](https://github.com/shuchkin/simplexlsxgen/issues/51)
## 1.0.22 (2021-10-29)
* Escape \x00 and \x0B (vertical tab)

View File

@ -1,10 +1,12 @@
# SimpleXLSXGen
[<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/>
(!) XLSX reader [here](https://github.com/shuchkin/simplexlsx).
Export data to Excel XLSX file. PHP XLSX generator. No external tools and libraries.
- XLSX reader [here](https://github.com/shuchkin/simplexlsx)
- XLS reader [here](https://github.com/shuchkin/simplexls)
- CSV reader/writer [here](https://github.com/shuchkin/simplecsv)
**Sergey Shuchkin** <sergey.shuchkin@gmail.com> 2020-2021<br/>
**Sergey Shuchkin** <sergey.shuchkin@gmail.com> 2020-2022<br/>
*Hey, bro, please ★ the package for my motivation :) and [donate](https://opencollective.com/simplexlsx) for more motivation!*
@ -15,7 +17,7 @@ $books = [
[618260307, 'The Hobbit', 'J. R. R. Tolkien', 'Houghton Mifflin', 'USA'],
[908606664, 'Slinky Malinki', 'Lynley Dodd', 'Mallinson Rendel', 'NZ']
];
$xlsx = SimpleXLSXGen::fromArray( $books );
$xlsx = Shuchkin\SimpleXLSXGen::fromArray( $books );
$xlsx->saveAs('books.xlsx'); // or downloadAs('books.xlsx') or $xlsx_content = (string) $xlsx
```
![XLSX screenshot](books.png)
@ -46,7 +48,7 @@ $data = [
['Hyperlink + Anchor', '<a href="https://github.com/shuchkin/simplexlsxgen">SimpleXLSXGen</a>'],
['RAW string', "\0".'2020-10-04 16:02:00']
];
SimpleXLSXGen::fromArray( $data )->saveAs('datatypes.xlsx');
Shuchkin\SimpleXLSXGen::fromArray( $data )->saveAs('datatypes.xlsx');
```
![XLSX screenshot](datatypes.png)
@ -61,14 +63,25 @@ $data = [
['Bold + Italic', '<b><i>12345.67</i></b>'],
['Hyperlink', 'https://github.com/shuchkin/simplexlsxgen'],
['Italic + Hyperlink + Anchor', '<i><a href="https://github.com/shuchkin/simplexlsxgen">SimpleXLSXGen</a></i>'],
['Green', '<style color="#00FF00">12345.67</style>'],
['Bold Red Text', '<b><style color="#FF0000">12345.67</style></b>'],
['Blue Text and Yellow Fill', '<style bgcolor="#FFFF00" color="#0000FF">12345.67</style>'],
['Left', '<left>12345.67</left>'],
['Center', '<center>12345.67</center>'],
['Right', '<right>Right Text</right>'],
['Center + Bold', '<center><b>Name</b></center>']
['Center + Bold', '<center><b>Name</b></center>'],
['Row height', '<style height="50">Row Height = 50</style>'],
['Top', '<style height="50"><top>Top</top></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>'],
['<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>"]
];
SimpleXLSXGen::fromArray( $data )
->setDefaultFont( 'Courier New' )
->setDefaultFontSize( 14 )
->setColWidth(1, 35) // 1 - num column, 35 - size in chars
->mergeCells('A20:B20')
->saveAs('styles_and_tags.xlsx');
```
![XLSX screenshot](styles.png)
@ -76,21 +89,70 @@ SimpleXLSXGen::fromArray( $data )
### More examples
```php
// Fluid interface, output to browser for download
SimpleXLSXGen::fromArray( $books )->downloadAs('table.xlsx');
Shuchkin\SimpleXLSXGen::fromArray( $books )->downloadAs('table.xlsx');
// Fluid interface, multiple sheets
SimpleXLSXGen::fromArray( $books )->addSheet( $books2 )->download();
Shuchkin\SimpleXLSXGen::fromArray( $books )->addSheet( $books2 )->download();
// Alternative interface, sheet name, get xlsx content
$xlsx_cache = (string) (new SimpleXLSXGen)->addSheet( $books, 'Modern style');
$xlsx_cache = (string) (new Shuchkin\SimpleXLSXGen)->addSheet( $books, 'Modern style');
// Classic interface
use Shuchkin\SimpleXLSXGen
$xlsx = new SimpleXLSXGen();
$xlsx->addSheet( $books, 'Catalog 2021' );
$xlsx->addSheet( $books2, 'Stephen King catalog');
$xlsx->downloadAs('books_2021.xlsx');
exit();
```
### JS array to Excel (AJAX)
```php
<?php // array2excel.php
if (isset($_POST['array2excel'])) {
require __DIR__.'/simplexlsxgen/src/SimpleXLSXGen.php';
$data = json_decode($_POST['array2excel'], false);
\Shuchkin\SimpleXLSXGen::fromArray($data)->downloadAs('file.xlsx');
return;
}
?>
<html lang="en">
<head>
<title>JS array to Excel</title>
</head>
<script>
function array2excel() {
var books = [
["ISBN", "title", "author", "publisher", "ctry"],
[618260307, "The Hobbit", "J. R. R. Tolkien", "Houghton Mifflin", "USA"],
[908606664, "Slinky Malinki", "Lynley Dodd", "Mallinson Rendel", "NZ"]
];
var json = JSON.stringify(books);
var request = new XMLHttpRequest();
request.onreadystatechange = function () {
if (this.readyState === 4) {
if (this.status === 200) {
var file = new Blob([this.response], {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});
var fileURL = URL.createObjectURL(file);
window.open(fileURL);
} else {
alert("Error: " + this.status + " " + this.statusText);
}
}
}
request.open('POST', "array2excel.php");
request.responseType = "blob";
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
request.send("array2excel=" + encodeURIComponent(json));
}
</script>
<body>
<input type="button" onclick="array2excel()" value="array2excel" />
</body>
</html>
```
## Debug
```php
@ -99,6 +161,7 @@ ini_set('display_errors', 1 );
$data = [
['Debug', 123]
]
SimpleXLSXGen::fromArray( $data )->saveAs('debug.xlsx');
```
];
Shuchkin\SimpleXLSXGen::fromArray( $data )->saveAs('debug.xlsx');
```

View File

@ -17,6 +17,7 @@
]
},
"require": {
"php": ">=5.4",
"ext-mbstring": "*",
"ext-zlib": "*"
}

View File

@ -1,6 +1,6 @@
The MIT License (MIT)
Copyright (c) 2014 Lukas Martinelli
Copyright (c) 2020-2022 Sergey Shuchkin sergey.shuchkin@gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 40 KiB