mirror of
https://github.com/retailcrm/PHPExcel.git
synced 2024-11-22 05:16:06 +03:00
A mass of small changes including
* Implementation of the Excel SUMIFS function * Fixes for Readers to handle various malformed spreadsheet file formats * Better error handling in Iterators * Suppression of Chart formula evaluation on save if formula evaluation is disabled * Changes for PHP7 * Hopefully fixed a memory issue with unsetting PHPExcel object failing to unset the calculation engine
This commit is contained in:
parent
6a8fca703c
commit
ecdb406d4d
@ -364,7 +364,7 @@ class PHPExcel
|
||||
public function __construct()
|
||||
{
|
||||
$this->uniqueID = uniqid();
|
||||
$this->calculationEngine = PHPExcel_Calculation::getInstance($this);
|
||||
$this->calculationEngine = new PHPExcel_Calculation($this);
|
||||
|
||||
// Initialise worksheet collection and add one worksheet
|
||||
$this->workSheetCollection = array();
|
||||
@ -395,7 +395,7 @@ class PHPExcel
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
PHPExcel_Calculation::unsetInstance($this);
|
||||
$this->calculationEngine = null;
|
||||
$this->disconnectWorksheets();
|
||||
}
|
||||
|
||||
|
@ -1497,7 +1497,7 @@ class PHPExcel_Calculation
|
||||
'OFFSET' => array(
|
||||
'category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
|
||||
'functionCall' => 'PHPExcel_Calculation_LookupRef::OFFSET',
|
||||
'argumentCount' => '3,5',
|
||||
'argumentCount' => '3-5',
|
||||
'passCellReference' => true,
|
||||
'passByReference' => array(true)
|
||||
),
|
||||
@ -1814,8 +1814,8 @@ class PHPExcel_Calculation
|
||||
),
|
||||
'SUMIFS' => array(
|
||||
'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
|
||||
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
|
||||
'argumentCount' => '?'
|
||||
'functionCall' => 'PHPExcel_Calculation_MathTrig::SUMIFS',
|
||||
'argumentCount' => '3+'
|
||||
),
|
||||
'SUMPRODUCT' => array(
|
||||
'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
|
||||
@ -2068,14 +2068,10 @@ class PHPExcel_Calculation
|
||||
);
|
||||
|
||||
|
||||
private function __construct(PHPExcel $workbook = null)
|
||||
public function __construct(PHPExcel $workbook = null)
|
||||
{
|
||||
$this->delta = 1 * pow(10, 0 - ini_get('precision'));
|
||||
|
||||
if ($workbook !== null) {
|
||||
self::$workbookSets[$workbook->getID()] = $this;
|
||||
}
|
||||
|
||||
$this->workbook = $workbook;
|
||||
$this->cyclicReferenceStack = new PHPExcel_CalcEngine_CyclicReferenceStack();
|
||||
$this->_debugLog = new PHPExcel_CalcEngine_Logger($this->cyclicReferenceStack);
|
||||
@ -2104,16 +2100,15 @@ class PHPExcel_Calculation
|
||||
public static function getInstance(PHPExcel $workbook = null)
|
||||
{
|
||||
if ($workbook !== null) {
|
||||
if (isset(self::$workbookSets[$workbook->getID()])) {
|
||||
return self::$workbookSets[$workbook->getID()];
|
||||
$instance = $workbook->getCalculationEngine();
|
||||
if (isset($instance)) {
|
||||
return $instance;
|
||||
}
|
||||
return new PHPExcel_Calculation($workbook);
|
||||
}
|
||||
|
||||
if (!isset(self::$instance) || (self::$instance === null)) {
|
||||
self::$instance = new PHPExcel_Calculation();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
@ -2121,15 +2116,10 @@ class PHPExcel_Calculation
|
||||
* Unset an instance of this class
|
||||
*
|
||||
* @access public
|
||||
* @param PHPExcel $workbook Injected workbook identifying the instance to unset
|
||||
*/
|
||||
public static function unsetInstance(PHPExcel $workbook = null)
|
||||
public function __destruct()
|
||||
{
|
||||
if ($workbook !== null) {
|
||||
if (isset(self::$workbookSets[$workbook->getID()])) {
|
||||
unset(self::$workbookSets[$workbook->getID()]);
|
||||
}
|
||||
}
|
||||
$this->workbook = null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2146,9 +2146,9 @@ class PHPExcel_Calculation_Financial
|
||||
if ((!is_array($values)) && (!is_array($dates))) {
|
||||
return PHPExcel_Calculation_Functions::VALUE();
|
||||
}
|
||||
$values = PHPExcel_Calculation_Functions::flattenArray($values);
|
||||
$dates = PHPExcel_Calculation_Functions::flattenArray($dates);
|
||||
$guess = PHPExcel_Calculation_Functions::flattenSingleValue($guess);
|
||||
$values = PHPExcel_Calculation_Functions::flattenArray($values);
|
||||
$dates = PHPExcel_Calculation_Functions::flattenArray($dates);
|
||||
$guess = PHPExcel_Calculation_Functions::flattenSingleValue($guess);
|
||||
if (count($values) != count($dates)) {
|
||||
return PHPExcel_Calculation_Functions::NaN();
|
||||
}
|
||||
|
@ -555,10 +555,8 @@ class PHPExcel_Calculation_Functions
|
||||
case 'float':
|
||||
case 'integer':
|
||||
return $value;
|
||||
break;
|
||||
case 'boolean':
|
||||
return (integer) $value;
|
||||
break;
|
||||
case 'string':
|
||||
// Errors
|
||||
if ((strlen($value) > 0) && ($value{0} == '#')) {
|
||||
|
@ -1220,6 +1220,66 @@ class PHPExcel_Calculation_MathTrig
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* SUMIFS
|
||||
*
|
||||
* Counts the number of cells that contain numbers within the list of arguments
|
||||
*
|
||||
* Excel Function:
|
||||
* SUMIFS(value1[,value2[, ...]],condition)
|
||||
*
|
||||
* @access public
|
||||
* @category Mathematical and Trigonometric Functions
|
||||
* @param mixed $arg,... Data values
|
||||
* @param string $condition The criteria that defines which cells will be summed.
|
||||
* @return float
|
||||
*/
|
||||
public static function SUMIFS() {
|
||||
$arrayList = func_get_args();
|
||||
|
||||
$sumArgs = PHPExcel_Calculation_Functions::flattenArray(array_shift($arrayList));
|
||||
|
||||
while (count($arrayList) > 0) {
|
||||
$aArgsArray[] = PHPExcel_Calculation_Functions::flattenArray(array_shift($arrayList));
|
||||
$conditions[] = PHPExcel_Calculation_Functions::ifCondition(array_shift($arrayList));
|
||||
}
|
||||
|
||||
// Loop through each set of arguments and conditions
|
||||
foreach ($conditions as $index => $condition) {
|
||||
$aArgs = $aArgsArray[$index];
|
||||
$wildcard = false;
|
||||
if ((strpos($condition, '*') !== false) || (strpos($condition, '?') !== false)) {
|
||||
// * and ? are wildcard characters.
|
||||
// Use ~* and ~? for literal star and question mark
|
||||
// Code logic doesn't yet handle escaping
|
||||
$condition = trim(ltrim($condition, '=<>'), '"');
|
||||
$wildcard = true;
|
||||
}
|
||||
// Loop through arguments
|
||||
foreach ($aArgs as $key => $arg) {
|
||||
if ($wildcard) {
|
||||
if (!fnmatch($condition, $arg, FNM_CASEFOLD)) {
|
||||
// Is it a value within our criteria
|
||||
$sumArgs[$key] = 0.0;
|
||||
}
|
||||
} else {
|
||||
if (!is_numeric($arg)) {
|
||||
$arg = PHPExcel_Calculation::wrapResult(strtoupper($arg));
|
||||
}
|
||||
$testCondition = '='.$arg.$condition;
|
||||
if (!PHPExcel_Calculation::getInstance()->_calculateFormulaValue($testCondition)) {
|
||||
// Is it a value within our criteria
|
||||
$sumArgs[$key] = 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Return
|
||||
return array_sum($sumArgs);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* SUMPRODUCT
|
||||
*
|
||||
|
@ -401,11 +401,7 @@ class PHPExcel_Reader_Excel2003XML extends PHPExcel_Reader_Abstract implements P
|
||||
$style_ss = $style->attributes($namespaces['ss']);
|
||||
$styleID = (string) $style_ss['ID'];
|
||||
// echo 'Style ID = '.$styleID.'<br />';
|
||||
if ($styleID == 'Default') {
|
||||
$this->styles['Default'] = array();
|
||||
} else {
|
||||
$this->styles[$styleID] = $this->styles['Default'];
|
||||
}
|
||||
$this->styles[$styleID] = (isset($this->styles['Default'])) ? $this->styles['Default'] : array();
|
||||
foreach ($style as $styleType => $styleData) {
|
||||
$styleAttributes = $styleData->attributes($namespaces['ss']);
|
||||
// echo $styleType.'<br />';
|
||||
|
@ -307,10 +307,17 @@ class PHPExcel_Reader_Excel2007 extends PHPExcel_Reader_Abstract implements PHPE
|
||||
}
|
||||
$fileName = PHPExcel_Shared_File::realpath($fileName);
|
||||
|
||||
// Sadly, some 3rd party xlsx generators don't use consistent case for filenaming
|
||||
// so we need to load case-insensitively from the zip file
|
||||
|
||||
// Apache POI fixes
|
||||
$contents = $archive->getFromName($fileName);
|
||||
$contents = $archive->getFromIndex(
|
||||
$archive->locateName($fileName, ZIPARCHIVE::FL_NOCASE)
|
||||
);
|
||||
if ($contents === false) {
|
||||
$contents = $archive->getFromName(substr($fileName, 1));
|
||||
$contents = $archive->getFromIndex(
|
||||
$archive->locateName(substr($fileName, 1), ZIPARCHIVE::FL_NOCASE)
|
||||
);
|
||||
}
|
||||
|
||||
return $contents;
|
||||
|
@ -351,10 +351,6 @@ class PHPExcel_Reader_Excel2007_Chart
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($seriesVal)) {
|
||||
$seriesVal = null;
|
||||
}
|
||||
|
||||
return array(
|
||||
'formatCode' => $formatCode,
|
||||
'pointCount' => $pointCount,
|
||||
|
@ -1753,7 +1753,7 @@ class PHPExcel_Reader_Excel5 extends PHPExcel_Reader_Abstract implements PHPExce
|
||||
|
||||
// move stream pointer to next record
|
||||
$this->pos += 4 + $length;
|
||||
|
||||
|
||||
if (!$this->verifyPassword('VelvetSweatshop', substr($recordData, 6, 16), substr($recordData, 22, 16), substr($recordData, 38, 16), $this->md5Ctxt)) {
|
||||
throw new PHPExcel_Reader_Exception('Decryption password incorrect');
|
||||
}
|
||||
|
@ -116,18 +116,30 @@ class PHPExcel_Shared_CodePage
|
||||
return 'CP950'; // Macintosh Chinese Traditional
|
||||
case 10003:
|
||||
return 'CP1361'; // Macintosh Korean
|
||||
case 10004:
|
||||
return 'MACARABIC'; // Apple Arabic
|
||||
case 10005:
|
||||
return 'MACHEBREW'; // Apple Hebrew
|
||||
case 10006:
|
||||
return 'MACGREEK'; // Macintosh Greek
|
||||
case 10007:
|
||||
return 'MACCYRILLIC'; // Macintosh Cyrillic
|
||||
case 10008:
|
||||
return 'CP936'; // Macintosh - Simplified Chinese (GB 2312)
|
||||
case 10010:
|
||||
return 'MACROMANIA'; // Macintosh Romania
|
||||
case 10017:
|
||||
return 'MACUKRAINE'; // Macintosh Ukraine
|
||||
case 10021:
|
||||
return 'MACTHAI'; // Macintosh Thai
|
||||
case 10029:
|
||||
return 'MACCENTRALEUROPE'; // Macintosh Central Europe
|
||||
case 10079:
|
||||
return 'MACICELAND'; // Macintosh Icelandic
|
||||
case 10081:
|
||||
return 'MACTURKISH'; // Macintosh Turkish
|
||||
case 10082:
|
||||
return 'MACCROATIAN'; // Macintosh Croatian
|
||||
case 21010:
|
||||
return 'UTF-16LE'; // UTF-16 (BIFF8) This isn't correct, but some Excel writer libraries erroneously use Codepage 21010 for UTF-16LE
|
||||
case 32768:
|
||||
|
@ -107,17 +107,19 @@ class PHPExcel_Shared_ZipArchive
|
||||
*/
|
||||
public function locateName($fileName)
|
||||
{
|
||||
$fileName = strtolower($fileName);
|
||||
|
||||
$list = $this->zip->listContent();
|
||||
$listCount = count($list);
|
||||
$list_index = -1;
|
||||
$index = -1;
|
||||
for ($i = 0; $i < $listCount; ++$i) {
|
||||
if (strtolower($list[$i]["filename"]) == strtolower($fileName) ||
|
||||
strtolower($list[$i]["stored_filename"]) == strtolower($fileName)) {
|
||||
$list_index = $i;
|
||||
if (strtolower($list[$i]["filename"]) == $fileName ||
|
||||
strtolower($list[$i]["stored_filename"]) == $fileName) {
|
||||
$index = $i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ($list_index > -1);
|
||||
return ($index > -1) ? $index : false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -128,32 +130,30 @@ class PHPExcel_Shared_ZipArchive
|
||||
*/
|
||||
public function getFromName($fileName)
|
||||
{
|
||||
$list = $this->zip->listContent();
|
||||
$listCount = count($list);
|
||||
$list_index = -1;
|
||||
for ($i = 0; $i < $listCount; ++$i) {
|
||||
if (strtolower($list[$i]["filename"]) == strtolower($fileName) ||
|
||||
strtolower($list[$i]["stored_filename"]) == strtolower($fileName)) {
|
||||
$list_index = $i;
|
||||
break;
|
||||
$index = $this->locateName($fileName);
|
||||
|
||||
if ($index !== false) {
|
||||
$extracted = $this->getFromIndex($index);
|
||||
} else {
|
||||
$fileName = substr($fileName, 1);
|
||||
$index = $this->locateName($fileName);
|
||||
if ($index === false) {
|
||||
return false;
|
||||
}
|
||||
$extracted = $this->zip->getFromIndex($index);
|
||||
}
|
||||
|
||||
$extracted = "";
|
||||
if ($list_index != -1) {
|
||||
$extracted = $this->zip->extractByIndex($list_index, PCLZIP_OPT_EXTRACT_AS_STRING);
|
||||
} else {
|
||||
$filename = substr($fileName, 1);
|
||||
$list_index = -1;
|
||||
for ($i = 0; $i < $listCount; ++$i) {
|
||||
if (strtolower($list[$i]["filename"]) == strtolower($fileName) ||
|
||||
strtolower($list[$i]["stored_filename"]) == strtolower($fileName)) {
|
||||
$list_index = $i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$extracted = $this->zip->extractByIndex($list_index, PCLZIP_OPT_EXTRACT_AS_STRING);
|
||||
$contents = $extracted;
|
||||
if ((is_array($extracted)) && ($extracted != 0)) {
|
||||
$contents = $extracted[0]["content"];
|
||||
}
|
||||
|
||||
return $contents;
|
||||
}
|
||||
|
||||
public function getFromIndex($index) {
|
||||
$extracted = $this->zip->extractByIndex($index, PCLZIP_OPT_EXTRACT_AS_STRING);
|
||||
$contents = '';
|
||||
if ((is_array($extracted)) && ($extracted != 0)) {
|
||||
$contents = $extracted[0]["content"];
|
||||
}
|
||||
|
@ -861,10 +861,10 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
|
||||
$this->title = $pValue;
|
||||
$this->dirty = true;
|
||||
|
||||
if ($this->parent) {
|
||||
if ($this->parent && $this->parent->getCalculationEngine()) {
|
||||
// New title
|
||||
$newTitle = $this->getTitle();
|
||||
PHPExcel_Calculation::getInstance($this->parent)
|
||||
$this->parent->getCalculationEngine()
|
||||
->renameCalculationCacheForWorksheet($oldTitle, $newTitle);
|
||||
if ($updateFormulaCellReferences) {
|
||||
PHPExcel_ReferenceHelper::getInstance()->updateNamedFormulas($this->parent, $oldTitle, $newTitle);
|
||||
|
@ -85,11 +85,19 @@ class PHPExcel_Worksheet_ColumnIterator implements Iterator
|
||||
*
|
||||
* @param integer $startColumn The column address at which to start iterating
|
||||
* @return PHPExcel_Worksheet_ColumnIterator
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
public function resetStart($startColumn = 'A')
|
||||
{
|
||||
$startColumnIndex = PHPExcel_Cell::columnIndexFromString($startColumn) - 1;
|
||||
if ($startColumnIndex > PHPExcel_Cell::columnIndexFromString($this->subject->getHighestColumn()) - 1) {
|
||||
throw new PHPExcel_Exception("Start column ({$startColumn}) is beyond highest column ({$this->subject->getHighestColumn()})");
|
||||
}
|
||||
|
||||
$this->startColumn = $startColumnIndex;
|
||||
if ($this->endColumn < $this->startColumn) {
|
||||
$this->endColumn = $this->startColumn;
|
||||
}
|
||||
$this->seek($startColumn);
|
||||
|
||||
return $this;
|
||||
|
@ -64,7 +64,7 @@ class PHPExcel_Worksheet_RowIterator implements Iterator
|
||||
* @param integer $startRow The row number at which to start iterating
|
||||
* @param integer $endRow Optionally, the row number at which to stop iterating
|
||||
*/
|
||||
public function __construct(PHPExcel_Worksheet $subject = null, $startRow = 1, $endRow = null)
|
||||
public function __construct(PHPExcel_Worksheet $subject, $startRow = 1, $endRow = null)
|
||||
{
|
||||
// Set subject
|
||||
$this->subject = $subject;
|
||||
@ -85,10 +85,18 @@ class PHPExcel_Worksheet_RowIterator implements Iterator
|
||||
*
|
||||
* @param integer $startRow The row number at which to start iterating
|
||||
* @return PHPExcel_Worksheet_RowIterator
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
public function resetStart($startRow = 1)
|
||||
{
|
||||
if ($startRow > $this->subject->getHighestRow()) {
|
||||
throw new PHPExcel_Exception("Start row ({$startRow}) is beyond highest row ({$this->subject->getHighestRow()})");
|
||||
}
|
||||
|
||||
$this->startRow = $startRow;
|
||||
if ($this->endRow < $this->startRow) {
|
||||
$this->endRow = $this->startRow;
|
||||
}
|
||||
$this->seek($startRow);
|
||||
|
||||
return $this;
|
||||
|
@ -297,7 +297,7 @@ class PHPExcel_Writer_Excel2007 extends PHPExcel_Writer_Abstract implements PHPE
|
||||
$charts = $this->spreadSheet->getSheet($i)->getChartCollection();
|
||||
if (count($charts) > 0) {
|
||||
foreach ($charts as $chart) {
|
||||
$objZip->addFromString('xl/charts/chart' . ($chartCount + 1) . '.xml', $this->getWriterPart('Chart')->writeChart($chart));
|
||||
$objZip->addFromString('xl/charts/chart' . ($chartCount + 1) . '.xml', $this->getWriterPart('Chart')->writeChart($chart, $this->preCalculateFormulas));
|
||||
$chartCount++;
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,8 @@
|
||||
*/
|
||||
class PHPExcel_Writer_Excel2007_Chart extends PHPExcel_Writer_Excel2007_WriterPart
|
||||
{
|
||||
protected $calculateCellValues;
|
||||
|
||||
/**
|
||||
* Write charts to XML format
|
||||
*
|
||||
@ -35,8 +37,10 @@ class PHPExcel_Writer_Excel2007_Chart extends PHPExcel_Writer_Excel2007_WriterPa
|
||||
* @return string XML Output
|
||||
* @throws PHPExcel_Writer_Exception
|
||||
*/
|
||||
public function writeChart(PHPExcel_Chart $pChart = null)
|
||||
public function writeChart(PHPExcel_Chart $pChart = null, $calculateCellValues = true)
|
||||
{
|
||||
$this->calculateCellValues = $calculateCellValues;
|
||||
|
||||
// Create XML writer
|
||||
$objWriter = null;
|
||||
if ($this->getParentWriter()->getUseDiskCaching()) {
|
||||
@ -45,7 +49,9 @@ class PHPExcel_Writer_Excel2007_Chart extends PHPExcel_Writer_Excel2007_WriterPa
|
||||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY);
|
||||
}
|
||||
// Ensure that data series values are up-to-date before we save
|
||||
$pChart->refresh();
|
||||
if ($this->calculateCellValues) {
|
||||
$pChart->refresh();
|
||||
}
|
||||
|
||||
// XML header
|
||||
$objWriter->startDocument('1.0', 'UTF-8', 'yes');
|
||||
|
@ -88,7 +88,7 @@ class PHPExcel_Writer_Excel2007_Rels extends PHPExcel_Writer_Excel2007_WriterPar
|
||||
);
|
||||
// a custom UI in workbook ?
|
||||
if ($pPHPExcel->hasRibbon()) {
|
||||
$this->_writeRelationShip(
|
||||
$this->writeRelationShip(
|
||||
$objWriter,
|
||||
5,
|
||||
'http://schemas.microsoft.com/office/2006/relationships/ui/extensibility',
|
||||
@ -162,7 +162,7 @@ class PHPExcel_Writer_Excel2007_Rels extends PHPExcel_Writer_Excel2007_WriterPar
|
||||
// Relationships for vbaProject if needed
|
||||
// id : just after the last sheet
|
||||
if ($pPHPExcel->hasMacros()) {
|
||||
$this->_writeRelationShip(
|
||||
$this->writeRelationShip(
|
||||
$objWriter,
|
||||
($i + 1 + 3),
|
||||
'http://schemas.microsoft.com/office/2006/relationships/vbaProject',
|
||||
|
6
Examples/.gitignore
vendored
6
Examples/.gitignore
vendored
@ -1,3 +1,5 @@
|
||||
|
||||
*.xls
|
||||
*.xlsx
|
||||
*.xlsx
|
||||
*.csv
|
||||
*.jpg
|
||||
*.pdf
|
||||
|
@ -71,6 +71,14 @@ $objPHPExcel->getActiveSheet()->getRowDimension(8)->setRowHeight(-1);
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A8')->getAlignment()->setWrapText(true);
|
||||
|
||||
|
||||
$value = "-ValueA\n-Value B\n-Value C";
|
||||
$objPHPExcel->getActiveSheet()->setCellValue('A10', $value);
|
||||
$objPHPExcel->getActiveSheet()->getRowDimension(10)->setRowHeight(-1);
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A10')->getAlignment()->setWrapText(true);
|
||||
$objPHPExcel->getActiveSheet()->getStyle('A10')->setQuotePrefix(true);
|
||||
|
||||
|
||||
|
||||
// Rename worksheet
|
||||
echo date('H:i:s') , " Rename worksheet" , EOL;
|
||||
$objPHPExcel->getActiveSheet()->setTitle('Simple');
|
||||
|
@ -38,15 +38,11 @@ date_default_timezone_set('Europe/London');
|
||||
require_once dirname(__FILE__) . '/../Classes/PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
if (!file_exists("05featuredemo.xlsx")) {
|
||||
exit("Please run 05featuredemo.php first." . EOL);
|
||||
}
|
||||
|
||||
echo date('H:i:s') , " Load from Excel2007 file" , EOL;
|
||||
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
|
||||
$objPHPExcel = $objReader->load("05featuredemo.xlsx");
|
||||
$objPHPExcel = $objReader->load("./templates/28iterators.xlsx");
|
||||
|
||||
echo date('H:i:s') , " Iterate worksheets" , EOL;
|
||||
echo date('H:i:s') , " Iterate worksheets by Row" , EOL;
|
||||
foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
|
||||
echo 'Worksheet - ' , $worksheet->getTitle() , EOL;
|
||||
|
||||
@ -64,5 +60,23 @@ foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
|
||||
}
|
||||
|
||||
|
||||
echo date('H:i:s') , " Iterate worksheets by Column" , EOL;
|
||||
foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
|
||||
echo 'Worksheet - ' , $worksheet->getTitle() , EOL;
|
||||
|
||||
foreach ($worksheet->getColumnIterator() as $column) {
|
||||
echo ' Column index - ' , $column->getColumnIndex() , EOL;
|
||||
|
||||
$cellIterator = $column->getCellIterator();
|
||||
$cellIterator->setIterateOnlyExistingCells(true); // Loop all cells, even if it is not set
|
||||
foreach ($cellIterator as $cell) {
|
||||
if (!is_null($cell)) {
|
||||
echo ' Cell - ' , $cell->getCoordinate() , ' - ' , $cell->getCalculatedValue() , EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Echo memory peak usage
|
||||
echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;
|
||||
|
@ -26,8 +26,11 @@
|
||||
Planned for 1.8.2
|
||||
- Bugfix: (MBaker) - Fix to getCell() method when cell reference includes a worksheet reference
|
||||
- Bugfix: (ncrypthic) Work Item GH-570 - Ignore inlineStr type if formula element exists
|
||||
- Bugfix: (hernst42) Work Item GH-709 - Fixed missing renames of writeRelationShip (from _writeRelationShip)
|
||||
- General: (umpirsky) Work Item GH-548 - Optimize vlookup() sort
|
||||
- Bugfix: (MBaker) Work Item GH-554 - Whitespace after toRichTextObject()
|
||||
- Feature: (MBaker) - Initial implementation of SUMIFS() function
|
||||
- Feature: (MBaker) - Additional codepages
|
||||
|
||||
|
||||
2015-04-30 (v1.8.1):
|
||||
@ -68,8 +71,7 @@ Planned for 1.8.2
|
||||
(see http://projects.webappsec.org/w/page/13247002/XML%20Entity%20Expansion for an explanation of XEE injection) attacks
|
||||
Reference CVE-2015-3542 - Identification of problem courtesy of Dawid Golunski (Pentest Ltd.)
|
||||
|
||||
|
||||
2014-03-02 (v1.8.0):
|
||||
2014-03-02 (v1.8.0):
|
||||
- Bugfix: (MBaker) Work item CP19830 - Undefined variable: fileHandle in CSV Reader
|
||||
- Bugfix: (MBaker) Work item CP19968 - Out of memory in style/supervisor.php
|
||||
- Bugfix: (MBaker) - Style error with merged cells in PDF Writer
|
||||
|
@ -22,7 +22,7 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.2.0",
|
||||
"php": "^5.2|^7.0",
|
||||
"ext-mbstring": "*",
|
||||
"ext-xml": "*",
|
||||
"ext-xmlwriter": "*"
|
||||
|
@ -418,6 +418,22 @@ class MathTrigTest extends PHPUnit_Framework_TestCase
|
||||
return new testDataFileIterator('rawTestData/Calculation/MathTrig/SERIESSUM.data');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerSUMIFS
|
||||
*/
|
||||
public function testSUMIFS()
|
||||
{
|
||||
$args = func_get_args();
|
||||
$expectedResult = array_pop($args);
|
||||
$result = call_user_func_array(array('PHPExcel_Calculation_MathTrig','SUMIFS'), $args);
|
||||
$this->assertEquals($expectedResult, $result, null, 1E-12);
|
||||
}
|
||||
|
||||
public function providerSUMIFS()
|
||||
{
|
||||
return new testDataFileIterator('rawTestData/Calculation/MathTrig/SUMIFS.data');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerSUMSQ
|
||||
*/
|
||||
|
@ -68,6 +68,14 @@ class ColumnIteratorTest extends PHPUnit_Framework_TestCase
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PHPExcel_Exception
|
||||
*/
|
||||
public function testStartOutOfRange()
|
||||
{
|
||||
$iterator = new PHPExcel_Worksheet_ColumnIterator($this->mockWorksheet, 'IA', 'IV');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PHPExcel_Exception
|
||||
*/
|
||||
|
@ -56,16 +56,24 @@ class RowIteratorTest extends PHPUnit_Framework_TestCase
|
||||
public function testIteratorSeekAndPrev()
|
||||
{
|
||||
$iterator = new PHPExcel_Worksheet_RowIterator($this->mockWorksheet, 2, 4);
|
||||
$columnIndexResult = 4;
|
||||
$iterator->seek(4);
|
||||
$this->assertEquals($columnIndexResult, $iterator->key());
|
||||
$rowIndexResult = 4;
|
||||
$iterator->seek($rowIndexResult);
|
||||
$this->assertEquals($rowIndexResult, $iterator->key());
|
||||
|
||||
for ($i = 1; $i < $columnIndexResult-1; $i++) {
|
||||
for ($i = 1; $i < $rowIndexResult-1; $i++) {
|
||||
$iterator->prev();
|
||||
$this->assertEquals($columnIndexResult - $i, $iterator->key());
|
||||
$this->assertEquals($rowIndexResult - $i, $iterator->key());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PHPExcel_Exception
|
||||
*/
|
||||
public function testStartOutOfRange()
|
||||
{
|
||||
$iterator = new PHPExcel_Worksheet_RowIterator($this->mockWorksheet, 256, 512);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PHPExcel_Exception
|
||||
*/
|
||||
|
6
unitTests/rawTestData/Calculation/MathTrig/SUMIFS.data
Normal file
6
unitTests/rawTestData/Calculation/MathTrig/SUMIFS.data
Normal file
@ -0,0 +1,6 @@
|
||||
{12.25;10.5;5.1;8.35;13.45;7.95;6;4.55}, {2013;2012;2012;2013;2013;2011;2013;2009}, "=2013", 40.05
|
||||
{12.25;10.5;5.1;8.35;13.45;7.95;6;4.55}, {"Oranges";"Bananas";"Apples";"Bananas";"Oranges";"Apples";"Pears";"Oranges"}, "=Oranges", 30.25
|
||||
{12.25;10.5;5.1;8.35;13.45;7.95;6;4.55}, {2013;2012;2012;2013;2013;2011;2013;2009}, "=2013", {"Oranges";"Bananas";"Apples";"Bananas";"Oranges";"Apples";"Pears";"Oranges"}, "=Oranges", 25.7
|
||||
{12.25;10.5;5.1;8.35;13.45;7.95;6;4.55}, {2013;2012;2012;2013;2013;2011;2013;2009}, ">=2009", {"Oranges";"Bananas";"Apples";"Bananas";"Oranges";"Apples";"Pears";"Oranges"}, "=Oranges", {2013;2012;2012;2013;2013;2011;2013;2009}, "<=2012", 4.55
|
||||
{12.25;10.5;5.1;8.35;13.45;7.95;6;4.55}, {2013;2012;2012;2013;2013;2011;2013;2009}, ">=2009", {"Oranges";"Bananas";"Apples";"Bananas";"Oranges";"Apples";"Pears";"Oranges"}, "=B*", 18.85
|
||||
{12.25;10.5;5.1;8.35;13.45;7.95;6;4.55}, {2013;2012;2012;2013;2013;2011;2013;2009}, ">=2009", {"Oranges";"Bananas";"Apples";"Bananas";"Oranges";"Apples";"Pears";"Oranges"}, "=B?nanas", 18.85
|
Loading…
Reference in New Issue
Block a user