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

49 Commits

Author SHA1 Message Date
b3060667f2 1.3.12 font size 2023-03-31 17:22:19 +06:00
cb19defa37 1.3.12 font size 2023-03-31 17:16:07 +06:00
5a154b24f9 1.3.12 font size 2023-03-31 17:15:07 +06:00
b46f63fce7 Merge pull request #104 from mrjemson/master
Added Font-Size
2023-03-31 16:28:13 +06:00
bb09c0d38c Updated Readme 2023-03-31 17:05:44 +11:00
91ca3f6fff Added Font-Size Ability 2023-03-31 17:04:03 +11:00
59cdc277ee 1.3.11 2023-03-28 16:25:39 +06:00
343e549ca1 1.3.11 2023-03-28 16:21:08 +06:00
61e55d6277 Merge pull request #101 from xaviermdq/master
Frozen rows/cols support
2023-03-28 13:07:07 +06:00
9b52ff6ac7 Update SimpleXLSXGen.php 2023-03-27 20:18:39 -03:00
317fb0982e Frozen rows/cols support
Added setFrozen method to freeze rows and columns from top-left corner up to, but not including, the row and column of the passed parameter.
For example:
$xlsx->setFrozen('B3');
freezes first column (A) and first and second rows (1 and 2)
2023-03-27 11:17:11 -03:00
765001ae96 1.3.10 2023-02-25 19:09:48 +06:00
c2f3077812 1.3.10 2023-02-25 17:14:53 +06:00
af53c754c3 1.3.10 2023-01-09 11:51:48 +06:00
6d7608f8ca 1.3.10 2022-12-15 00:13:39 +06:00
80091bb9be 1.3.10 2022-12-15 00:04:53 +06:00
21b1d9a4b8 1.3.10 2022-12-14 23:47:14 +06:00
c1434378bc 1.3.10 2022-12-14 21:30:23 +06:00
75252a4a0c Merge pull request #79 from 2advance/patch-1
Update SimpleXLSXGen.php
2022-10-28 22:06:12 +06:00
f9d5480bb3 Update SimpleXLSXGen.php
Fix: Column width not working on Mac
2022-10-28 17:47:54 +02:00
aff0fa243d 1.2.16 2022-08-12 18:57:41 +06:00
82b0db1f8e 1.2.16 2022-08-06 23:13:06 +06:00
aef6ee4935 1.2.15 2022-07-28 18:26:11 +06:00
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
6 changed files with 819 additions and 272 deletions

View File

@ -1,7 +1,47 @@
# Changelog
# 1.1.12 (2022-03-15)
* Added $xlsx->mergeCells('A1:C1')
## 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="&quot;£&quot;#,##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)
* 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

125
README.md
View File

@ -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)
- 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-2023<br/>
*Hey, bro, please ★ the package for my motivation :) and [donate](https://opencollective.com/simplexlsx) for more motivation!*
@ -33,22 +33,29 @@ $ composer require shuchkin/simplexlsxgen
or download class [here](https://github.com/shuchkin/simplexlsxgen/blob/master/src/SimpleXLSXGen.php)
## Examples
Use UTF-8 encoded strings.
### Data types
```php
$data = [
['Integer', 123],
['Float', 12.35],
['Percent', '12%'],
['Currency $', '$500.67'],
['Currency €', '200 €'],
['Currency ₽', '1200.30 ₽'],
['Currency (other)', '<style nf="&quot;£&quot;#,##0.00">500</style>'],
['Datetime', '2020-05-20 02:38:00'],
['Date','2020-05-20'],
['Time','02:38:00'],
['Date', '2020-05-20'],
['Time', '02:38: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 + 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');
```
![XLSX screenshot](datatypes.png)
@ -63,20 +70,48 @@ $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>'],
['Size 32 Font', '<style font-size="32">Big Text</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>'],
['Center', '<center>12345.67</center>'],
['Right', '<right>Right Text</right>'],
['Center + Bold', '<center><b>Name</b></center>'],
['<center>MERGE CELLS</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>"],
];
Shuchkin\SimpleXLSXGen::fromArray( $data )
->setDefaultFont( 'Courier New' )
->setDefaultFontSize( 14 )
->mergeCells('A13:B13')
SimpleXLSXGen::fromArray($data)
->setDefaultFont('Courier New')
->setDefaultFontSize(14)
->setColWidth(1, 35)
->mergeCells('A20:B20')
->saveAs('styles_and_tags.xlsx');
```
![XLSX screenshot](styles.png)
### 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
```php
// Fluid interface, output to browser for download
@ -95,6 +130,74 @@ $xlsx->addSheet( $books, 'Catalog 2021' );
$xlsx->addSheet( $books2, 'Stephen King catalog');
$xlsx->downloadAs('books_2021.xlsx');
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');
```
### 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.onload = function () {
if (this.status === 200) {
var file = new Blob([this.response], {type: this.getResponseHeader('Content-Type')});
var fileURL = URL.createObjectURL(file);
var filename = "", m;
var disposition = this.getResponseHeader('Content-Disposition');
if (disposition && (m = /"([^"]+)"/.exec(disposition)) !== null) {
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.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

View File

@ -1,7 +1,7 @@
{
"name": "shuchkin/simplexlsxgen",
"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",
"license": "MIT",
"authors": [

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 57 KiB

After

Width:  |  Height:  |  Size: 190 KiB