|
@@ -1,5 +1,7 @@
|
|
|
-<?php
|
|
|
-
|
|
|
+<?php
|
|
|
+/*
|
|
|
+ * @license MIT License
|
|
|
+ * */
|
|
|
class XLSXWriter
|
|
|
{
|
|
|
//http://www.ecma-international.org/publications/standards/Ecma-376.htm
|
|
@@ -12,6 +14,7 @@ class XLSXWriter
|
|
|
protected $title;
|
|
|
protected $subject;
|
|
|
protected $author;
|
|
|
+ protected $isRightToLeft;
|
|
|
protected $company;
|
|
|
protected $description;
|
|
|
protected $keywords = array();
|
|
@@ -23,14 +26,10 @@ class XLSXWriter
|
|
|
protected $number_formats = array();
|
|
|
public function __construct()
|
|
|
{
|
|
|
- if(!ini_get('date.timezone'))
|
|
|
- {
|
|
|
- //using date functions can kick out warning if this isn't set
|
|
|
- date_default_timezone_set('UTC');
|
|
|
- }
|
|
|
- $this->addCellStyle($number_format='GENERAL', $style_string=null);
|
|
|
- $this->addCellStyle($number_format='GENERAL', $style_string=null);
|
|
|
- $this->addCellStyle($number_format='GENERAL', $style_string=null);
|
|
|
+ defined('ENT_XML1') or define('ENT_XML1',16);//for php 5.3, avoid fatal error
|
|
|
+ date_default_timezone_get() or date_default_timezone_set('UTC');//php.ini missing tz, avoid warning
|
|
|
+ is_writeable($this->tempFilename()) or self::log("Warning: tempdir ".sys_get_temp_dir()." not writeable, use ->setTempDir()");
|
|
|
+ class_exists('ZipArchive') or self::log("Error: ZipArchive class does not exist");
|
|
|
$this->addCellStyle($number_format='GENERAL', $style_string=null);
|
|
|
}
|
|
|
public function setTitle($title='') { $this->title=$title; }
|
|
@@ -40,8 +39,9 @@ class XLSXWriter
|
|
|
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()
|
|
|
- {
|
|
|
+ {
|
|
|
if (!empty($this->temp_files)) {
|
|
|
foreach($this->temp_files as $temp_file) {
|
|
|
@unlink($temp_file);
|
|
@@ -83,17 +83,17 @@ class XLSXWriter
|
|
|
}
|
|
|
$zip = new ZipArchive();
|
|
|
if (empty($this->sheets)) { self::log("Error in ".__CLASS__."::".__FUNCTION__.", no worksheets defined."); return; }
|
|
|
- if (!$zip->open($filename, ZipArchive::CREATE)) { self::log("Error in ".__CLASS__."::".__FUNCTION__.", unable to create zip."); return; }
|
|
|
- $zip->addEmptyDir("docProps/");
|
|
|
- $zip->addFromString("docProps/app.xml" , self::buildAppXML() );
|
|
|
- $zip->addFromString("docProps/core.xml", self::buildCoreXML());
|
|
|
- $zip->addEmptyDir("_rels/");
|
|
|
- $zip->addFromString("_rels/.rels", self::buildRelationshipsXML());
|
|
|
- $zip->addEmptyDir("xl/worksheets/");
|
|
|
- foreach($this->sheets as $sheet) {
|
|
|
- $zip->addFile($sheet->filename, "xl/worksheets/".$sheet->xmlname );
|
|
|
- }
|
|
|
- $zip->addFromString("xl/workbook.xml" , self::buildWorkbookXML() );
|
|
|
+ if (!$zip->open($filename, ZipArchive::CREATE)) { self::log("Error in ".__CLASS__."::".__FUNCTION__.", unable to create zip."); return; }
|
|
|
+ $zip->addEmptyDir("docProps/");
|
|
|
+ $zip->addFromString("docProps/app.xml" , self::buildAppXML() );
|
|
|
+ $zip->addFromString("docProps/core.xml", self::buildCoreXML());
|
|
|
+ $zip->addEmptyDir("_rels/");
|
|
|
+ $zip->addFromString("_rels/.rels", self::buildRelationshipsXML());
|
|
|
+ $zip->addEmptyDir("xl/worksheets/");
|
|
|
+ foreach($this->sheets as $sheet) {
|
|
|
+ $zip->addFile($sheet->filename, "xl/worksheets/".$sheet->xmlname );
|
|
|
+ }
|
|
|
+ $zip->addFromString("xl/workbook.xml" , self::buildWorkbookXML() );
|
|
|
$zip->addFile($this->writeStylesXML(), "xl/styles.xml" ); //$zip->addFromString("xl/styles.xml" , self::buildStylesXML() );
|
|
|
$zip->addFromString("[Content_Types].xml" , self::buildContentTypesXML() );
|
|
|
$zip->addEmptyDir("xl/_rels/");
|
|
@@ -122,6 +122,7 @@ class XLSXWriter
|
|
|
'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
|
|
@@ -134,7 +135,7 @@ class XLSXWriter
|
|
|
$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).'"/>');
|
|
@@ -184,7 +185,7 @@ class XLSXWriter
|
|
|
$column_types[] = array('number_format' => $number_format,//contains excel format like 'YYYY-MM-DD HH:MM:SS'
|
|
|
'number_format_type' => $number_format_type, //contains friendly format like 'datetime'
|
|
|
'default_cell_style' => $cell_style_idx,
|
|
|
- );
|
|
|
+ );
|
|
|
}
|
|
|
return $column_types;
|
|
|
}
|
|
@@ -223,7 +224,7 @@ class XLSXWriter
|
|
|
{
|
|
|
if (empty($sheet_name))
|
|
|
return;
|
|
|
- self::initializeSheet($sheet_name);
|
|
|
+ $this->initializeSheet($sheet_name);
|
|
|
$sheet = &$this->sheets[$sheet_name];
|
|
|
if (count($sheet->columns) < count($row)) {
|
|
|
$default_column_types = $this->initializeColumnTypes( array_fill($from=0, $until=count($row), 'GENERAL') );//will map to n_auto
|
|
@@ -275,7 +276,7 @@ class XLSXWriter
|
|
|
}
|
|
|
$max_cell = self::xlsCell($sheet->row_count - 1, count($sheet->columns) - 1);
|
|
|
if ($sheet->auto_filter) {
|
|
|
- $sheet->file_writer->write( '<autoFilter ref="A1:' . $max_cell . '"/>');
|
|
|
+ $sheet->file_writer->write( '<autoFilter ref="A1:' . $max_cell . '"/>');
|
|
|
}
|
|
|
$sheet->file_writer->write( '<printOptions headings="false" gridLines="false" gridLinesSet="true" horizontalCentered="false" verticalCentered="false"/>');
|
|
|
$sheet->file_writer->write( '<pageMargins left="0.5" right="0.5" top="1.0" bottom="1.0" header="0.5" footer="0.5"/>');
|
|
@@ -302,16 +303,18 @@ class XLSXWriter
|
|
|
$endCell = self::xlsCell($end_cell_row, $end_cell_column);
|
|
|
$sheet->merge_cells[] = $startCell . ":" . $endCell;
|
|
|
}
|
|
|
- public function writeSheet(array $data, $sheet_name='', array $header_types=array(), $style=array())
|
|
|
+ public function writeSheet(array $data, $sheet_name='', array $header_types=array())
|
|
|
{
|
|
|
$sheet_name = empty($sheet_name) ? 'Sheet1' : $sheet_name;
|
|
|
$data = empty($data) ? array(array('')) : $data;
|
|
|
if (!empty($header_types))
|
|
|
- isset($style['header']) ? $this->writeSheetHeader($sheet_name, $header_types, $style['header']) : $this->writeSheetHeader($sheet_name, $header_types);
|
|
|
-
|
|
|
+ {
|
|
|
+ $this->writeSheetHeader($sheet_name, $header_types);
|
|
|
+ }
|
|
|
foreach($data as $i=>$row)
|
|
|
- isset($style['content']) ? $this->writeSheetRow($sheet_name, $row, $style['content']) : $this->writeSheetRow($sheet_name, $row);
|
|
|
-
|
|
|
+ {
|
|
|
+ $this->writeSheetRow($sheet_name, $row);
|
|
|
+ }
|
|
|
$this->finalizeSheet($sheet_name);
|
|
|
}
|
|
|
protected function writeCell(XLSXWriter_BuffererWriter &$file, $row_number, $column_number, $value, $num_format_type, $cell_style_idx)
|
|
@@ -319,7 +322,7 @@ class XLSXWriter
|
|
|
$cell_name = self::xlsCell($row_number, $column_number);
|
|
|
if (!is_scalar($value) || $value==='') { //objects, array, empty
|
|
|
$file->write('<c r="'.$cell_name.'" s="'.$cell_style_idx.'"/>');
|
|
|
- } elseif (is_string($value) && $value{0}=='='){
|
|
|
+ } elseif (is_string($value) && $value[0]=='='){
|
|
|
$file->write('<c r="'.$cell_name.'" s="'.$cell_style_idx.'" t="s"><f>'.self::xmlspecialchars($value).'</f></c>');
|
|
|
} elseif ($num_format_type=='n_date') {
|
|
|
$file->write('<c r="'.$cell_name.'" s="'.$cell_style_idx.'" t="n"><v>'.intval(self::convert_date_time($value)).'</v></c>');
|
|
@@ -333,17 +336,17 @@ class XLSXWriter
|
|
|
if (!is_string($value) || $value=='0' || ($value[0]!='0' && ctype_digit($value)) || preg_match("/^\-?(0|[1-9][0-9]*)(\.[0-9]+)?$/", $value)){
|
|
|
$file->write('<c r="'.$cell_name.'" s="'.$cell_style_idx.'" t="n"><v>'.self::xmlspecialchars($value).'</v></c>');//int,float,currency
|
|
|
} else { //implied: ($cell_format=='string')
|
|
|
- $file->write('<c r="'.$cell_name.'" s="'.$cell_style_idx.'" t="inlineStr"><is><t>'.self::xmlspecialchars($value).'</t></is></c>');
|
|
|
+ $file->write('<c r="'.$cell_name.'" s="'.$cell_style_idx.'" t="inlineStr"><is><t>'.self::xmlspecialchars($value).'</t></is></c>');
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
-protected function styleFontIndexes()
|
|
|
-{
|
|
|
- static $border_allowed = array('left','right','top','bottom');
|
|
|
- static $border_style_allowed = array('thin','medium','thick','dashDot','dashDotDot','dashed','dotted','double','hair','mediumDashDot','mediumDashDotDot','mediumDashed','slantDashDot');
|
|
|
- static $horizontal_allowed = array('general','left','right','justify','center');
|
|
|
- static $vertical_allowed = array('bottom','center','distributed','top');
|
|
|
- $default_font = array('size'=>'10','name'=>'Arial','family'=>'2');
|
|
|
+ protected function styleFontIndexes()
|
|
|
+ {
|
|
|
+ static $border_allowed = array('left','right','top','bottom');
|
|
|
+ static $border_style_allowed = array('thin','medium','thick','dashDot','dashDotDot','dashed','dotted','double','hair','mediumDashDot','mediumDashDotDot','mediumDashed','slantDashDot');
|
|
|
+ static $horizontal_allowed = array('general','left','right','justify','center');
|
|
|
+ static $vertical_allowed = array('bottom','center','distributed','top');
|
|
|
+ $default_font = array('size'=>'10','name'=>'Arial','family'=>'2');
|
|
|
$fills = array('','');//2 placeholders for static xml later
|
|
|
$fonts = array('','','','');//4 placeholders for static xml later
|
|
|
$borders = array('');//1 placeholder for static xml later
|
|
@@ -438,22 +441,22 @@ protected function styleFontIndexes()
|
|
|
foreach($this->number_formats as $i=>$v) {
|
|
|
$file->write('<numFmt numFmtId="'.(164+$i).'" formatCode="'.self::xmlspecialchars($v).'" />');
|
|
|
}
|
|
|
- //$file->write( '<numFmt formatCode="GENERAL" numFmtId="164"/>');
|
|
|
- //$file->write( '<numFmt formatCode="[$$-1009]#,##0.00;[RED]\-[$$-1009]#,##0.00" numFmtId="165"/>');
|
|
|
- //$file->write( '<numFmt formatCode="YYYY-MM-DD\ HH:MM:SS" numFmtId="166"/>');
|
|
|
- //$file->write( '<numFmt formatCode="YYYY-MM-DD" numFmtId="167"/>');
|
|
|
+ //$file->write( '<numFmt formatCode="GENERAL" numFmtId="164"/>');
|
|
|
+ //$file->write( '<numFmt formatCode="[$$-1009]#,##0.00;[RED]\-[$$-1009]#,##0.00" numFmtId="165"/>');
|
|
|
+ //$file->write( '<numFmt formatCode="YYYY-MM-DD\ HH:MM:SS" numFmtId="166"/>');
|
|
|
+ //$file->write( '<numFmt formatCode="YYYY-MM-DD" numFmtId="167"/>');
|
|
|
$file->write('</numFmts>');
|
|
|
$file->write('<fonts count="'.(count($fonts)).'">');
|
|
|
- $file->write( '<font><name val="Arial"/><charset val="1"/><family val="2"/><sz val="10"/></font>');
|
|
|
- $file->write( '<font><name val="Arial"/><family val="0"/><sz val="10"/></font>');
|
|
|
- $file->write( '<font><name val="Arial"/><family val="0"/><sz val="10"/></font>');
|
|
|
- $file->write( '<font><name val="Arial"/><family val="0"/><sz val="10"/></font>');
|
|
|
+ $file->write( '<font><name val="Arial"/><charset val="1"/><family val="2"/><sz val="10"/></font>');
|
|
|
+ $file->write( '<font><name val="Arial"/><family val="0"/><sz val="10"/></font>');
|
|
|
+ $file->write( '<font><name val="Arial"/><family val="0"/><sz val="10"/></font>');
|
|
|
+ $file->write( '<font><name val="Arial"/><family val="0"/><sz val="10"/></font>');
|
|
|
foreach($fonts as $font) {
|
|
|
if (!empty($font)) { //fonts have 4 empty placeholders in array to offset the 4 static xml entries above
|
|
|
$f = json_decode($font,true);
|
|
|
$file->write('<font>');
|
|
|
- $file->write( '<name val="'.htmlspecialchars($f['name']).'"/><charset val="1"/><family val="'.intval($f['family']).'"/>');
|
|
|
- $file->write( '<sz val="'.intval($f['size']).'"/>');
|
|
|
+ $file->write( '<name val="'.htmlspecialchars($f['name']).'"/><charset val="1"/><family val="'.intval($f['family']).'"/>');
|
|
|
+ $file->write( '<sz val="'.intval($f['size']).'"/>');
|
|
|
if (!empty($f['color'])) { $file->write('<color rgb="'.strval($f['color']).'"/>'); }
|
|
|
if (!empty($f['bold'])) { $file->write('<b val="true"/>'); }
|
|
|
if (!empty($f['italic'])) { $file->write('<i val="true"/>'); }
|
|
@@ -464,8 +467,8 @@ protected function styleFontIndexes()
|
|
|
}
|
|
|
$file->write('</fonts>');
|
|
|
$file->write('<fills count="'.(count($fills)).'">');
|
|
|
- $file->write( '<fill><patternFill patternType="none"/></fill>');
|
|
|
- $file->write( '<fill><patternFill patternType="gray125"/></fill>');
|
|
|
+ $file->write( '<fill><patternFill patternType="none"/></fill>');
|
|
|
+ $file->write( '<fill><patternFill patternType="gray125"/></fill>');
|
|
|
foreach($fills as $fill) {
|
|
|
if (!empty($fill)) { //fills have 2 empty placeholders in array to offset the 2 static xml entries above
|
|
|
$file->write('<fill><patternFill patternType="solid"><fgColor rgb="'.strval($fill).'"/><bgColor indexed="64"/></patternFill></fill>');
|
|
@@ -473,7 +476,7 @@ protected function styleFontIndexes()
|
|
|
}
|
|
|
$file->write('</fills>');
|
|
|
$file->write('<borders count="'.(count($borders)).'">');
|
|
|
- $file->write( '<border diagonalDown="false" diagonalUp="false"><left/><right/><top/><bottom/><diagonal/></border>');
|
|
|
+ $file->write( '<border diagonalDown="false" diagonalUp="false"><left/><right/><top/><bottom/><diagonal/></border>');
|
|
|
foreach($borders as $border) {
|
|
|
if (!empty($border)) { //fonts have an empty placeholder in the array to offset the static xml entry above
|
|
|
$pieces = json_decode($border,true);
|
|
@@ -482,7 +485,7 @@ protected function styleFontIndexes()
|
|
|
$file->write('<border diagonalDown="false" diagonalUp="false">');
|
|
|
foreach (array('left', 'right', 'top', 'bottom') as $side)
|
|
|
{
|
|
|
- $show_side = in_array($side,$pieces['side']) ? true : false;
|
|
|
+ $show_side = in_array($side,$pieces['side']) ? true : false;
|
|
|
$file->write($show_side ? "<$side style=\"$border_style\">$border_color</$side>" : "<$side/>");
|
|
|
}
|
|
|
$file->write( '<diagonal/>');
|
|
@@ -491,35 +494,35 @@ protected function styleFontIndexes()
|
|
|
}
|
|
|
$file->write('</borders>');
|
|
|
$file->write('<cellStyleXfs count="20">');
|
|
|
- $file->write( '<xf applyAlignment="true" applyBorder="true" applyFont="true" applyProtection="true" borderId="0" fillId="0" fontId="0" numFmtId="164">');
|
|
|
- $file->write( '<alignment horizontal="general" indent="0" shrinkToFit="false" textRotation="0" vertical="bottom" wrapText="false"/>');
|
|
|
- $file->write( '<protection hidden="false" locked="true"/>');
|
|
|
- $file->write( '</xf>');
|
|
|
- $file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="true" applyProtection="false" borderId="0" fillId="0" fontId="1" numFmtId="0"/>');
|
|
|
- $file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="true" applyProtection="false" borderId="0" fillId="0" fontId="1" numFmtId="0"/>');
|
|
|
- $file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="true" applyProtection="false" borderId="0" fillId="0" fontId="2" numFmtId="0"/>');
|
|
|
- $file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="true" applyProtection="false" borderId="0" fillId="0" fontId="2" numFmtId="0"/>');
|
|
|
- $file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="true" applyProtection="false" borderId="0" fillId="0" fontId="0" numFmtId="0"/>');
|
|
|
- $file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="true" applyProtection="false" borderId="0" fillId="0" fontId="0" numFmtId="0"/>');
|
|
|
- $file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="true" applyProtection="false" borderId="0" fillId="0" fontId="0" numFmtId="0"/>');
|
|
|
- $file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="true" applyProtection="false" borderId="0" fillId="0" fontId="0" numFmtId="0"/>');
|
|
|
- $file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="true" applyProtection="false" borderId="0" fillId="0" fontId="0" numFmtId="0"/>');
|
|
|
- $file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="true" applyProtection="false" borderId="0" fillId="0" fontId="0" numFmtId="0"/>');
|
|
|
- $file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="true" applyProtection="false" borderId="0" fillId="0" fontId="0" numFmtId="0"/>');
|
|
|
- $file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="true" applyProtection="false" borderId="0" fillId="0" fontId="0" numFmtId="0"/>');
|
|
|
- $file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="true" applyProtection="false" borderId="0" fillId="0" fontId="0" numFmtId="0"/>');
|
|
|
- $file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="true" applyProtection="false" borderId="0" fillId="0" fontId="0" numFmtId="0"/>');
|
|
|
- $file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="true" applyProtection="false" borderId="0" fillId="0" fontId="1" numFmtId="43"/>');
|
|
|
- $file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="true" applyProtection="false" borderId="0" fillId="0" fontId="1" numFmtId="41"/>');
|
|
|
- $file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="true" applyProtection="false" borderId="0" fillId="0" fontId="1" numFmtId="44"/>');
|
|
|
- $file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="true" applyProtection="false" borderId="0" fillId="0" fontId="1" numFmtId="42"/>');
|
|
|
- $file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="true" applyProtection="false" borderId="0" fillId="0" fontId="1" numFmtId="9"/>');
|
|
|
+ $file->write( '<xf applyAlignment="true" applyBorder="true" applyFont="true" applyProtection="true" borderId="0" fillId="0" fontId="0" numFmtId="164">');
|
|
|
+ $file->write( '<alignment horizontal="general" indent="0" shrinkToFit="false" textRotation="0" vertical="bottom" wrapText="false"/>');
|
|
|
+ $file->write( '<protection hidden="false" locked="true"/>');
|
|
|
+ $file->write( '</xf>');
|
|
|
+ $file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="true" applyProtection="false" borderId="0" fillId="0" fontId="1" numFmtId="0"/>');
|
|
|
+ $file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="true" applyProtection="false" borderId="0" fillId="0" fontId="1" numFmtId="0"/>');
|
|
|
+ $file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="true" applyProtection="false" borderId="0" fillId="0" fontId="2" numFmtId="0"/>');
|
|
|
+ $file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="true" applyProtection="false" borderId="0" fillId="0" fontId="2" numFmtId="0"/>');
|
|
|
+ $file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="true" applyProtection="false" borderId="0" fillId="0" fontId="0" numFmtId="0"/>');
|
|
|
+ $file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="true" applyProtection="false" borderId="0" fillId="0" fontId="0" numFmtId="0"/>');
|
|
|
+ $file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="true" applyProtection="false" borderId="0" fillId="0" fontId="0" numFmtId="0"/>');
|
|
|
+ $file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="true" applyProtection="false" borderId="0" fillId="0" fontId="0" numFmtId="0"/>');
|
|
|
+ $file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="true" applyProtection="false" borderId="0" fillId="0" fontId="0" numFmtId="0"/>');
|
|
|
+ $file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="true" applyProtection="false" borderId="0" fillId="0" fontId="0" numFmtId="0"/>');
|
|
|
+ $file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="true" applyProtection="false" borderId="0" fillId="0" fontId="0" numFmtId="0"/>');
|
|
|
+ $file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="true" applyProtection="false" borderId="0" fillId="0" fontId="0" numFmtId="0"/>');
|
|
|
+ $file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="true" applyProtection="false" borderId="0" fillId="0" fontId="0" numFmtId="0"/>');
|
|
|
+ $file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="true" applyProtection="false" borderId="0" fillId="0" fontId="0" numFmtId="0"/>');
|
|
|
+ $file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="true" applyProtection="false" borderId="0" fillId="0" fontId="1" numFmtId="43"/>');
|
|
|
+ $file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="true" applyProtection="false" borderId="0" fillId="0" fontId="1" numFmtId="41"/>');
|
|
|
+ $file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="true" applyProtection="false" borderId="0" fillId="0" fontId="1" numFmtId="44"/>');
|
|
|
+ $file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="true" applyProtection="false" borderId="0" fillId="0" fontId="1" numFmtId="42"/>');
|
|
|
+ $file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="true" applyProtection="false" borderId="0" fillId="0" fontId="1" numFmtId="9"/>');
|
|
|
$file->write('</cellStyleXfs>');
|
|
|
$file->write('<cellXfs count="'.(count($style_indexes)).'">');
|
|
|
- //$file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="false" applyProtection="false" borderId="0" fillId="0" fontId="0" numFmtId="164" xfId="0"/>');
|
|
|
- //$file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="false" applyProtection="false" borderId="0" fillId="0" fontId="0" numFmtId="165" xfId="0"/>');
|
|
|
- //$file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="false" applyProtection="false" borderId="0" fillId="0" fontId="0" numFmtId="166" xfId="0"/>');
|
|
|
- //$file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="false" applyProtection="false" borderId="0" fillId="0" fontId="0" numFmtId="167" xfId="0"/>');
|
|
|
+ //$file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="false" applyProtection="false" borderId="0" fillId="0" fontId="0" numFmtId="164" xfId="0"/>');
|
|
|
+ //$file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="false" applyProtection="false" borderId="0" fillId="0" fontId="0" numFmtId="165" xfId="0"/>');
|
|
|
+ //$file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="false" applyProtection="false" borderId="0" fillId="0" fontId="0" numFmtId="166" xfId="0"/>');
|
|
|
+ //$file->write( '<xf applyAlignment="false" applyBorder="false" applyFont="false" applyProtection="false" borderId="0" fillId="0" fontId="0" numFmtId="167" xfId="0"/>');
|
|
|
foreach($style_indexes as $v)
|
|
|
{
|
|
|
$applyAlignment = isset($v['alignment']) ? 'true' : 'false';
|
|
@@ -533,19 +536,19 @@ protected function styleFontIndexes()
|
|
|
$fontIdx = isset($v['font_idx']) ? intval($v['font_idx']) : 0;
|
|
|
//$file->write('<xf applyAlignment="'.$applyAlignment.'" applyBorder="'.$applyBorder.'" applyFont="'.$applyFont.'" applyProtection="false" borderId="'.($borderIdx).'" fillId="'.($fillIdx).'" fontId="'.($fontIdx).'" numFmtId="'.(164+$v['num_fmt_idx']).'" xfId="0"/>');
|
|
|
$file->write('<xf applyAlignment="'.$applyAlignment.'" applyBorder="'.$applyBorder.'" applyFont="'.$applyFont.'" applyProtection="false" borderId="'.($borderIdx).'" fillId="'.($fillIdx).'" fontId="'.($fontIdx).'" numFmtId="'.(164+$v['num_fmt_idx']).'" xfId="0">');
|
|
|
- $file->write(' <alignment horizontal="'.$horizAlignment.'" vertical="'.$vertAlignment.'" textRotation="0" wrapText="'.$wrapText.'" indent="0" shrinkToFit="false"/>');
|
|
|
- $file->write(' <protection locked="true" hidden="false"/>');
|
|
|
+ $file->write(' <alignment horizontal="'.$horizAlignment.'" vertical="'.$vertAlignment.'" textRotation="0" wrapText="'.$wrapText.'" indent="0" shrinkToFit="false"/>');
|
|
|
+ $file->write(' <protection locked="true" hidden="false"/>');
|
|
|
$file->write('</xf>');
|
|
|
}
|
|
|
$file->write('</cellXfs>');
|
|
|
- $file->write( '<cellStyles count="6">');
|
|
|
- $file->write( '<cellStyle builtinId="0" customBuiltin="false" name="Normal" xfId="0"/>');
|
|
|
- $file->write( '<cellStyle builtinId="3" customBuiltin="false" name="Comma" xfId="15"/>');
|
|
|
- $file->write( '<cellStyle builtinId="6" customBuiltin="false" name="Comma [0]" xfId="16"/>');
|
|
|
- $file->write( '<cellStyle builtinId="4" customBuiltin="false" name="Currency" xfId="17"/>');
|
|
|
- $file->write( '<cellStyle builtinId="7" customBuiltin="false" name="Currency [0]" xfId="18"/>');
|
|
|
- $file->write( '<cellStyle builtinId="5" customBuiltin="false" name="Percent" xfId="19"/>');
|
|
|
- $file->write( '</cellStyles>');
|
|
|
+ $file->write( '<cellStyles count="6">');
|
|
|
+ $file->write( '<cellStyle builtinId="0" customBuiltin="false" name="Normal" xfId="0"/>');
|
|
|
+ $file->write( '<cellStyle builtinId="3" customBuiltin="false" name="Comma" xfId="15"/>');
|
|
|
+ $file->write( '<cellStyle builtinId="6" customBuiltin="false" name="Comma [0]" xfId="16"/>');
|
|
|
+ $file->write( '<cellStyle builtinId="4" customBuiltin="false" name="Currency" xfId="17"/>');
|
|
|
+ $file->write( '<cellStyle builtinId="7" customBuiltin="false" name="Currency [0]" xfId="18"/>');
|
|
|
+ $file->write( '<cellStyle builtinId="5" customBuiltin="false" name="Percent" xfId="19"/>');
|
|
|
+ $file->write( '</cellStyles>');
|
|
|
$file->write('</styleSheet>');
|
|
|
$file->close();
|
|
|
return $temporary_filename;
|
|
@@ -571,8 +574,8 @@ protected function styleFontIndexes()
|
|
|
$core_xml.='<dc:creator>'.self::xmlspecialchars($this->author).'</dc:creator>';
|
|
|
if (!empty($this->keywords)) {
|
|
|
$core_xml.='<cp:keywords>'.self::xmlspecialchars(implode (", ", (array)$this->keywords)).'</cp:keywords>';
|
|
|
- }
|
|
|
- $core_xml.='<dc:description>'.self::xmlspecialchars($this->description).'</dc:description>';
|
|
|
+ }
|
|
|
+ $core_xml.='<dc:description>'.self::xmlspecialchars($this->description).'</dc:description>';
|
|
|
$core_xml.='<cp:revision>0</cp:revision>';
|
|
|
$core_xml.='</cp:coreProperties>';
|
|
|
return $core_xml;
|
|
@@ -609,7 +612,7 @@ protected function styleFontIndexes()
|
|
|
if ($sheet->auto_filter) {
|
|
|
$sheetname = self::sanitize_sheetname($sheet->sheetname);
|
|
|
$workbook_xml.='<definedName name="_xlnm._FilterDatabase" localSheetId="0" hidden="1">\''.self::xmlspecialchars($sheetname).'\'!$A$1:' . self::xlsCell($sheet->row_count - 1, count($sheet->columns) - 1, true) . '</definedName>';
|
|
|
- $i++;
|
|
|
+ $i++;
|
|
|
}
|
|
|
}
|
|
|
$workbook_xml.='</definedNames>';
|
|
@@ -663,14 +666,15 @@ protected function styleFontIndexes()
|
|
|
$r = chr($n%26 + 0x41) . $r;
|
|
|
}
|
|
|
if ($absolute) {
|
|
|
- return '$' . $r . '$' . ($row_number+1);
|
|
|
+ return '$' . $r . '$' . ($row_number+1);
|
|
|
}
|
|
|
return $r . ($row_number+1);
|
|
|
}
|
|
|
//------------------------------------------------------------------
|
|
|
public static function log($string)
|
|
|
{
|
|
|
- file_put_contents("php://stderr", date("Y-m-d H:i:s:").rtrim(is_array($string) ? json_encode($string) : $string)."\n");
|
|
|
+ //file_put_contents("php://stderr", date("Y-m-d H:i:s:").rtrim(is_array($string) ? json_encode($string) : $string)."\n");
|
|
|
+ error_log(date("Y-m-d H:i:s:").rtrim(is_array($string) ? json_encode($string) : $string)."\n");
|
|
|
}
|
|
|
//------------------------------------------------------------------
|
|
|
public static function sanitize_filename($filename) //http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29.aspx
|
|
@@ -686,7 +690,7 @@ protected function styleFontIndexes()
|
|
|
static $badchars = '\\/?*:[]';
|
|
|
static $goodchars = ' ';
|
|
|
$sheetname = strtr($sheetname, $badchars, $goodchars);
|
|
|
- $sheetname = substr($sheetname, 0, 31);
|
|
|
+ $sheetname = function_exists('mb_substr') ? mb_substr($sheetname, 0, 31) : substr($sheetname, 0, 31);
|
|
|
$sheetname = trim(trim(trim($sheetname),"'"));//trim before and after trimming single quotes
|
|
|
return !empty($sheetname) ? $sheetname : 'Sheet'.((rand()%900)+100);
|
|
|
}
|
|
@@ -712,57 +716,58 @@ protected function styleFontIndexes()
|
|
|
if ($num_format=='GENERAL') return 'n_auto';
|
|
|
if ($num_format=='@') return 'n_string';
|
|
|
if ($num_format=='0') return 'n_numeric';
|
|
|
- if (preg_match("/[H]{1,2}:[M]{1,2}/i", $num_format)) return 'n_datetime';
|
|
|
- if (preg_match("/[M]{1,2}:[S]{1,2}/i", $num_format)) return 'n_datetime';
|
|
|
- if (preg_match("/[Y]{2,4}/i", $num_format)) return 'n_date';
|
|
|
- if (preg_match("/[D]{1,2}/i", $num_format)) return 'n_date';
|
|
|
- if (preg_match("/[M]{1,2}/i", $num_format)) return 'n_date';
|
|
|
- if (preg_match("/$/", $num_format)) return 'n_numeric';
|
|
|
- if (preg_match("/%/", $num_format)) return 'n_numeric';
|
|
|
- if (preg_match("/0/", $num_format)) return 'n_numeric';
|
|
|
- return 'n_auto';
|
|
|
- }
|
|
|
+ if (preg_match('/[H]{1,2}:[M]{1,2}(?![^"]*+")/i', $num_format)) return 'n_datetime';
|
|
|
+ if (preg_match('/[M]{1,2}:[S]{1,2}(?![^"]*+")/i', $num_format)) return 'n_datetime';
|
|
|
+ if (preg_match('/[Y]{2,4}(?![^"]*+")/i', $num_format)) return 'n_date';
|
|
|
+ if (preg_match('/[D]{1,2}(?![^"]*+")/i', $num_format)) return 'n_date';
|
|
|
+ if (preg_match('/[M]{1,2}(?![^"]*+")/i', $num_format)) return 'n_date';
|
|
|
+ if (preg_match('/$(?![^"]*+")/', $num_format)) return 'n_numeric';
|
|
|
+ if (preg_match('/%(?![^"]*+")/', $num_format)) return 'n_numeric';
|
|
|
+ if (preg_match('/0(?![^"]*+")/', $num_format)) return 'n_numeric';
|
|
|
+ return 'n_auto';
|
|
|
+ }
|
|
|
//------------------------------------------------------------------
|
|
|
- private static function numberFormatStandardized($num_format)
|
|
|
- {
|
|
|
- if ($num_format=='money') { $num_format='dollar'; }
|
|
|
- if ($num_format=='number') { $num_format='integer'; }
|
|
|
- if ($num_format=='string') $num_format='@';
|
|
|
- else if ($num_format=='integer') $num_format='0';
|
|
|
- else if ($num_format=='date') $num_format='YYYY-MM-DD';
|
|
|
- else if ($num_format=='datetime') $num_format='YYYY-MM-DD HH:MM:SS';
|
|
|
- else if ($num_format=='price') $num_format='#,##0.00';
|
|
|
- else if ($num_format=='dollar') $num_format='[$$-1009]#,##0.00;[RED]-[$$-1009]#,##0.00';
|
|
|
- else if ($num_format=='euro') $num_format='#,##0.00 [$€-407];[RED]-#,##0.00 [$€-407]';
|
|
|
- $ignore_until='';
|
|
|
- $escaped = '';
|
|
|
- for($i=0,$ix=strlen($num_format); $i<$ix; $i++)
|
|
|
- {
|
|
|
- $c = $num_format[$i];
|
|
|
- if ($ignore_until=='' && $c=='[')
|
|
|
- $ignore_until=']';
|
|
|
- else if ($ignore_until=='' && $c=='"')
|
|
|
- $ignore_until='"';
|
|
|
- else if ($ignore_until==$c)
|
|
|
- $ignore_until='';
|
|
|
- if ($ignore_until=='' && ($c==' ' || $c=='-' || $c=='(' || $c==')') && ($i==0 || $num_format[$i-1]!='_'))
|
|
|
- $escaped.= "\\".$c;
|
|
|
- else
|
|
|
- $escaped.= $c;
|
|
|
- }
|
|
|
- return $escaped;
|
|
|
- }
|
|
|
+ private static function numberFormatStandardized($num_format)
|
|
|
+ {
|
|
|
+ if ($num_format=='money') { $num_format='dollar'; }
|
|
|
+ if ($num_format=='number') { $num_format='integer'; }
|
|
|
+ if ($num_format=='string') $num_format='@';
|
|
|
+ else if ($num_format=='integer') $num_format='0';
|
|
|
+ else if ($num_format=='date') $num_format='YYYY-MM-DD';
|
|
|
+ else if ($num_format=='datetime') $num_format='YYYY-MM-DD HH:MM:SS';
|
|
|
+ else if ($num_format=='time') $num_format='HH:MM:SS';
|
|
|
+ else if ($num_format=='price') $num_format='#,##0.00';
|
|
|
+ else if ($num_format=='dollar') $num_format='[$$-1009]#,##0.00;[RED]-[$$-1009]#,##0.00';
|
|
|
+ else if ($num_format=='euro') $num_format='#,##0.00 [$€-407];[RED]-#,##0.00 [$€-407]';
|
|
|
+ $ignore_until='';
|
|
|
+ $escaped = '';
|
|
|
+ for($i=0,$ix=strlen($num_format); $i<$ix; $i++)
|
|
|
+ {
|
|
|
+ $c = $num_format[$i];
|
|
|
+ if ($ignore_until=='' && $c=='[')
|
|
|
+ $ignore_until=']';
|
|
|
+ else if ($ignore_until=='' && $c=='"')
|
|
|
+ $ignore_until='"';
|
|
|
+ else if ($ignore_until==$c)
|
|
|
+ $ignore_until='';
|
|
|
+ if ($ignore_until=='' && ($c==' ' || $c=='-' || $c=='(' || $c==')') && ($i==0 || $num_format[$i-1]!='_'))
|
|
|
+ $escaped.= "\\".$c;
|
|
|
+ else
|
|
|
+ $escaped.= $c;
|
|
|
+ }
|
|
|
+ return $escaped;
|
|
|
+ }
|
|
|
//------------------------------------------------------------------
|
|
|
- public static function add_to_list_get_index(&$haystack, $needle)
|
|
|
- {
|
|
|
- $existing_idx = array_search($needle, $haystack, $strict=true);
|
|
|
- if ($existing_idx===false)
|
|
|
- {
|
|
|
- $existing_idx = count($haystack);
|
|
|
- $haystack[] = $needle;
|
|
|
- }
|
|
|
- return $existing_idx;
|
|
|
- }
|
|
|
+ public static function add_to_list_get_index(&$haystack, $needle)
|
|
|
+ {
|
|
|
+ $existing_idx = array_search($needle, $haystack, $strict=true);
|
|
|
+ if ($existing_idx===false)
|
|
|
+ {
|
|
|
+ $existing_idx = count($haystack);
|
|
|
+ $haystack[] = $needle;
|
|
|
+ }
|
|
|
+ return $existing_idx;
|
|
|
+ }
|
|
|
//------------------------------------------------------------------
|
|
|
public static function convert_date_time($date_input) //thanks to Excel::Writer::XLSX::Worksheet.pm (perl)
|
|
|
{
|
|
@@ -776,10 +781,10 @@ protected function styleFontIndexes()
|
|
|
list($junk,$year,$month,$day) = $matches;
|
|
|
}
|
|
|
if (preg_match("/(\d+):(\d{2}):(\d{2})/", $date_time, $matches))
|
|
|
- {
|
|
|
- list($junk,$hour,$min,$sec) = $matches;
|
|
|
- $seconds = ( $hour * 60 * 60 + $min * 60 + $sec ) / ( 24 * 60 * 60 );
|
|
|
- }
|
|
|
+ {
|
|
|
+ list($junk,$hour,$min,$sec) = $matches;
|
|
|
+ $seconds = ( $hour * 60 * 60 + $min * 60 + $sec ) / ( 24 * 60 * 60 );
|
|
|
+ }
|
|
|
//using 1900 as epoch, not 1904, ignoring 1904 special case
|
|
|
# Special cases for Excel.
|
|
|
if ("$year-$month-$day"=='1899-12-31') return $seconds ; # Excel 1900 epoch
|
|
@@ -797,9 +802,12 @@ protected function styleFontIndexes()
|
|
|
$leap = (($year % 400 == 0) || (($year % 4 == 0) && ($year % 100)) ) ? 1 : 0;
|
|
|
$mdays = array( 31, ($leap ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );
|
|
|
# Some boundary checks
|
|
|
- if($year < $epoch || $year > 9999) return 0;
|
|
|
- if($month < 1 || $month > 12) return 0;
|
|
|
- if($day < 1 || $day > $mdays[ $month - 1 ]) return 0;
|
|
|
+ if ($year!=0 || $month !=0 || $day!=0)
|
|
|
+ {
|
|
|
+ if($year < $epoch || $year > 9999) return 0;
|
|
|
+ if($month < 1 || $month > 12) return 0;
|
|
|
+ if($day < 1 || $day > $mdays[ $month - 1 ]) return 0;
|
|
|
+ }
|
|
|
# Accumulate the number of days since the epoch.
|
|
|
$days = $day; # Add days for current month
|
|
|
$days += array_sum( array_slice($mdays, 0, $month-1 ) ); # Add days for past months
|
|
@@ -814,7 +822,6 @@ protected function styleFontIndexes()
|
|
|
}
|
|
|
//------------------------------------------------------------------
|
|
|
}
|
|
|
-
|
|
|
class XLSXWriter_BuffererWriter
|
|
|
{
|
|
|
protected $fd=null;
|