From e02d764d0df51f1dcf8f812531d996911c2a2cc6 Mon Sep 17 00:00:00 2001 From: Sergey Shuchkin Date: Tue, 11 Apr 2023 03:18:46 +0600 Subject: [PATCH] 1.3.13 RTL --- CHANGELOG.md | 4 ++++ README.md | 4 ++++ src/SimpleXLSXGen.php | 20 +++++++++++++++----- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad56a5f..4d5655a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 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) * `````` - font size in cells, thx [Andrew Robinson](https://github.com/mrjemson) diff --git a/README.md b/README.md index 1a2f303..9ae1f19 100644 --- a/README.md +++ b/README.md @@ -138,6 +138,10 @@ $xlsx->autoFilter('A1:B10'); // 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(); + ``` ### JS array to Excel (AJAX) ```php diff --git a/src/SimpleXLSXGen.php b/src/SimpleXLSXGen.php index af4a8b2..fef8e8a 100644 --- a/src/SimpleXLSXGen.php +++ b/src/SimpleXLSXGen.php @@ -16,6 +16,7 @@ class SimpleXLSXGen public $curSheet; protected $defaultFont; protected $defaultFontSize; + protected $rtl; protected $sheets; protected $template; protected $NF; // numFmts @@ -80,6 +81,7 @@ class SimpleXLSXGen $this->curSheet = -1; $this->defaultFont = 'Calibri'; $this->defaultFontSize = 10; + $this->rtl = false; $this->sheets = [['name' => 'Sheet1', 'rows' => [], 'hyperlinks' => [], 'mergecells' => [], 'colwidth' => [], 'autofilter' => '']]; $this->extLinkId = 0; $this->SI = []; // sharedStrings index @@ -583,13 +585,14 @@ class SimpleXLSXGen setlocale(LC_NUMERIC, 'C'); $COLS = []; $ROWS = []; - $SHEETVIEWS = ''; + $SHEETVIEWS = 'rtl ? ' rightToLeft="1"' : '').'>'; + $AC = 'A1'; // Active Cell if (count($this->sheets[$idx]['rows'])) { if ($this->sheets[$idx]['frozen'] !== '' || isset($this->sheets[$idx]['frozen'][0]) || isset($this->sheets[$idx]['frozen'][1])) { $x = $y = 0; if (is_string($this->sheets[$idx]['frozen'])) { - $cell = $this->sheets[$idx]['frozen']; - self::cell2coord($cell, $x, $y); + $AC = $this->sheets[$idx]['frozen']; + self::cell2coord($AC, $x, $y); } else { if (isset($this->sheets[$idx]['frozen'][0])) { $x = $this->sheets[$idx]['frozen'][0]; @@ -597,7 +600,7 @@ class SimpleXLSXGen if (isset($this->sheets[$idx]['frozen'][1])) { $y = $this->sheets[$idx]['frozen'][1]; } - $cell = self::coord2cell($x, $y); + $AC = self::coord2cell($x, $y); } if ($x > 0 || $y > 0) { $split = ''; @@ -614,9 +617,11 @@ class SimpleXLSXGen if ($x === 0 && $y > 0) { $activepane = 'bottomLeft'; } - $SHEETVIEWS = ''; + $SHEETVIEWS .= ''; } } + $SHEETVIEWS .= ''; + $SHEETVIEWS .= ''; $COLS[] = ''; $CUR_ROW = 0; $COL = []; @@ -972,6 +977,10 @@ class SimpleXLSXGen $this->sheets[$this->curSheet]['colwidth'][$col] = $width; return $this; } + public function rightToLeft($value = true) { + $this->rtl = $value; + return $this; + } public function esc($str) { @@ -994,6 +1003,7 @@ class SimpleXLSXGen return $id; } + public static function raw($value) { return "\0" . $value;