Compare commits

...

2 Commits

Author SHA1 Message Date
Sergey Shuchkin 1ee4e5eb50 1.3.13 RTL 2023-04-12 15:24:17 +06:00
Sergey Shuchkin e02d764d0d 1.3.13 RTL 2023-04-11 03:18:46 +06:00
3 changed files with 42 additions and 12 deletions

View File

@ -1,5 +1,9 @@
# Changelog # 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) ## 1.3.12 (2023-03-31)
* ```<style font-size="32">Big Text</style>``` - font size in cells, thx [Andrew Robinson](https://github.com/mrjemson) * ```<style font-size="32">Big Text</style>``` - font size in cells, thx [Andrew Robinson](https://github.com/mrjemson)

View File

@ -138,6 +138,10 @@ $xlsx->autoFilter('A1:B10');
// the row and column of the indicated cell // the row and column of the indicated cell
$xlsx->freezePanes('C3'); $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) ### JS array to Excel (AJAX)
```php ```php

View File

@ -16,6 +16,7 @@ class SimpleXLSXGen
public $curSheet; public $curSheet;
protected $defaultFont; protected $defaultFont;
protected $defaultFontSize; protected $defaultFontSize;
protected $rtl;
protected $sheets; protected $sheets;
protected $template; protected $template;
protected $NF; // numFmts protected $NF; // numFmts
@ -80,6 +81,7 @@ class SimpleXLSXGen
$this->curSheet = -1; $this->curSheet = -1;
$this->defaultFont = 'Calibri'; $this->defaultFont = 'Calibri';
$this->defaultFontSize = 10; $this->defaultFontSize = 10;
$this->rtl = false;
$this->sheets = [['name' => 'Sheet1', 'rows' => [], 'hyperlinks' => [], 'mergecells' => [], 'colwidth' => [], 'autofilter' => '']]; $this->sheets = [['name' => 'Sheet1', 'rows' => [], 'hyperlinks' => [], 'mergecells' => [], 'colwidth' => [], 'autofilter' => '']];
$this->extLinkId = 0; $this->extLinkId = 0;
$this->SI = []; // sharedStrings index $this->SI = []; // sharedStrings index
@ -401,13 +403,25 @@ class SimpleXLSXGen
. ($xf[3] & self::FL_COLOR ? '><fgColor rgb="' . $xf[5] . '"/><bgColor indexed="64"/></patternFill>' : ' />') . ($xf[3] & self::FL_COLOR ? '><fgColor rgb="' . $xf[5] . '"/><bgColor indexed="64"/></patternFill>' : ' />')
. '</fill>'; . '</fill>';
} }
$align = ($xf[1] & self::A_LEFT ? ' horizontal="left"' : '') $align = '';
. ($xf[1] & self::A_RIGHT ? ' horizontal="right"' : '') if ($xf[1] & self::A_LEFT) {
. ($xf[1] & self::A_CENTER ? ' horizontal="center"' : '') $align .= ' horizontal="left"';
. ($xf[1] & self::A_TOP ? ' vertical="top"' : '') } elseif ($xf[1] & self::A_RIGHT) {
. ($xf[1] & self::A_MIDDLE ? ' vertical="center"' : '') $align .= ' horizontal="right"';
. ($xf[1] & self::A_BOTTOM ? ' vertical="bottom"' : '') } elseif ($xf[1] & self::A_CENTER) {
. ($xf[1] & self::A_WRAPTEXT ? ' wrapText="1"' : ''); $align .= ' horizontal="center"';
}
if ($xf[1] & self::A_TOP) {
$align .= ' vertical="top"';
} elseif ($xf[1] & self::A_MIDDLE) {
$align .= ' vertical="center"';
} elseif ($xf[1] & self::A_BOTTOM) {
$align .= ' vertical="bottom"';
}
if ($xf[1] & self::A_WRAPTEXT) {
$align .= ' wrapText="1"';
}
// border // border
$BR_ID = 0; $BR_ID = 0;
if ($xf[6] !== '') { if ($xf[6] !== '') {
@ -583,13 +597,14 @@ class SimpleXLSXGen
setlocale(LC_NUMERIC, 'C'); setlocale(LC_NUMERIC, 'C');
$COLS = []; $COLS = [];
$ROWS = []; $ROWS = [];
$SHEETVIEWS = ''; $SHEETVIEWS = '<sheetViews><sheetView tabSelected="1" workbookViewId="0"'.($this->rtl ? ' rightToLeft="1"' : '').'>';
$AC = 'A1'; // Active Cell
if (count($this->sheets[$idx]['rows'])) { if (count($this->sheets[$idx]['rows'])) {
if ($this->sheets[$idx]['frozen'] !== '' || isset($this->sheets[$idx]['frozen'][0]) || isset($this->sheets[$idx]['frozen'][1])) { if ($this->sheets[$idx]['frozen'] !== '' || isset($this->sheets[$idx]['frozen'][0]) || isset($this->sheets[$idx]['frozen'][1])) {
$x = $y = 0; $x = $y = 0;
if (is_string($this->sheets[$idx]['frozen'])) { if (is_string($this->sheets[$idx]['frozen'])) {
$cell = $this->sheets[$idx]['frozen']; $AC = $this->sheets[$idx]['frozen'];
self::cell2coord($cell, $x, $y); self::cell2coord($AC, $x, $y);
} else { } else {
if (isset($this->sheets[$idx]['frozen'][0])) { if (isset($this->sheets[$idx]['frozen'][0])) {
$x = $this->sheets[$idx]['frozen'][0]; $x = $this->sheets[$idx]['frozen'][0];
@ -597,7 +612,7 @@ class SimpleXLSXGen
if (isset($this->sheets[$idx]['frozen'][1])) { if (isset($this->sheets[$idx]['frozen'][1])) {
$y = $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) { if ($x > 0 || $y > 0) {
$split = ''; $split = '';
@ -614,9 +629,11 @@ class SimpleXLSXGen
if ($x === 0 && $y > 0) { if ($x === 0 && $y > 0) {
$activepane = 'bottomLeft'; $activepane = 'bottomLeft';
} }
$SHEETVIEWS = '<sheetViews><sheetView tabSelected="1" workbookViewId="0"><pane' . $split . ' topLeftCell="' . $cell . '" activePane="' . $activepane . '" state="frozen"/></sheetView></sheetViews>'; $SHEETVIEWS .= '<pane' . $split . ' topLeftCell="' . $AC . '" activePane="' . $activepane . '" state="frozen"/>';
} }
} }
$SHEETVIEWS .= '<selection activeCell="' . $AC . '" sqref="' . $AC . '"/>';
$SHEETVIEWS .= '</sheetView></sheetViews>';
$COLS[] = '<cols>'; $COLS[] = '<cols>';
$CUR_ROW = 0; $CUR_ROW = 0;
$COL = []; $COL = [];
@ -972,6 +989,10 @@ class SimpleXLSXGen
$this->sheets[$this->curSheet]['colwidth'][$col] = $width; $this->sheets[$this->curSheet]['colwidth'][$col] = $width;
return $this; return $this;
} }
public function rightToLeft($value = true) {
$this->rtl = $value;
return $this;
}
public function esc($str) public function esc($str)
{ {
@ -994,6 +1015,7 @@ class SimpleXLSXGen
return $id; return $id;
} }
public static function raw($value) public static function raw($value)
{ {
return "\0" . $value; return "\0" . $value;