Skip to content

Commit

Permalink
adding right to left worksheet support
Browse files Browse the repository at this point in the history
  • Loading branch information
mk-j committed Nov 7, 2019
1 parent 899c711 commit 39101b7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
19 changes: 19 additions & 0 deletions examples/ex11-right-to-left.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
set_include_path( get_include_path().PATH_SEPARATOR."..");
include_once("xlsxwriter.class.php");

$header = array(
'c1-text'=>'string',//text
'c2-text'=>'@',//text
);
$rows = array(
array('abcdefg','hijklmnop'),
);
$writer = new XLSXWriter();
$writer->setRightToLeft(true);

$writer->writeSheetHeader('Sheet1', $header);
foreach($rows as $row)
$writer->writeSheetRow('Sheet1', $row);
$writer->writeToFile('xlsx-right-to-left.xlsx');

5 changes: 4 additions & 1 deletion xlsxwriter.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class XLSXWriter
protected $title;
protected $subject;
protected $author;
protected $isRightToLeft;
protected $company;
protected $description;
protected $keywords = array();
Expand All @@ -41,6 +42,7 @@ public function setCompany($company='') { $this->company=$company; }
public function setKeywords($keywords='') { $this->keywords=$keywords; }
public function setDescription($description='') { $this->description=$description; }
public function setTempDir($tempdir='') { $this->tempdir=$tempdir; }
public function setRightToLeft($isRightToLeft=false){ $this->isRightToLeft=$isRightToLeft; }

public function __destruct()
{
Expand Down Expand Up @@ -135,6 +137,7 @@ protected function initializeSheet($sheet_name, $col_widths=array(), $auto_filte
'freeze_columns' => $freeze_columns,
'finalized' => false,
);
$rightToLeftValue = $this->isRightToLeft ? 'true' : 'false';
$sheet = &$this->sheets[$sheet_name];
$tabselected = count($this->sheets) == 1 ? 'true' : 'false';//only first sheet is selected
$max_cell=XLSXWriter::xlsCell(self::EXCEL_2007_MAX_ROW, self::EXCEL_2007_MAX_COL);//XFE1048577
Expand All @@ -147,7 +150,7 @@ protected function initializeSheet($sheet_name, $col_widths=array(), $auto_filte
$sheet->file_writer->write('<dimension ref="A1:' . $max_cell . '"/>');
$sheet->max_cell_tag_end = $sheet->file_writer->ftell();
$sheet->file_writer->write( '<sheetViews>');
$sheet->file_writer->write( '<sheetView colorId="64" defaultGridColor="true" rightToLeft="false" showFormulas="false" showGridLines="true" showOutlineSymbols="true" showRowColHeaders="true" showZeros="true" tabSelected="' . $tabselected . '" topLeftCell="A1" view="normal" windowProtection="false" workbookViewId="0" zoomScale="100" zoomScaleNormal="100" zoomScalePageLayoutView="100">');
$sheet->file_writer->write( '<sheetView colorId="64" defaultGridColor="true" rightToLeft="'.$rightToLeftValue.'" showFormulas="false" showGridLines="true" showOutlineSymbols="true" showRowColHeaders="true" showZeros="true" tabSelected="' . $tabselected . '" topLeftCell="A1" view="normal" windowProtection="false" workbookViewId="0" zoomScale="100" zoomScaleNormal="100" zoomScalePageLayoutView="100">');
if ($sheet->freeze_rows && $sheet->freeze_columns) {
$sheet->file_writer->write( '<pane ySplit="'.$sheet->freeze_rows.'" xSplit="'.$sheet->freeze_columns.'" topLeftCell="'.self::xlsCell($sheet->freeze_rows, $sheet->freeze_columns).'" activePane="bottomRight" state="frozen"/>');
$sheet->file_writer->write( '<selection activeCell="'.self::xlsCell($sheet->freeze_rows, 0).'" activeCellId="0" pane="topRight" sqref="'.self::xlsCell($sheet->freeze_rows, 0).'"/>');
Expand Down

0 comments on commit 39101b7

Please sign in to comment.