This repository has been archived by the owner on May 26, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 637
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
799ad93
commit 9276844
Showing
3 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Box\Spout\Writer\XLSX; | ||
|
||
/** | ||
* Class Formula | ||
* | ||
* @package Box\Spout\Reader\XLSX | ||
*/ | ||
class Formula | ||
{ | ||
|
||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $formula; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $value = '0'; | ||
|
||
/** | ||
* Formula constructor. | ||
* @param string $formula | ||
* @param string $value | ||
*/ | ||
public function __construct($formula, $value = '0') | ||
{ | ||
$this->formula = $formula; | ||
$this->value = $value; | ||
} | ||
|
||
public function getXml() | ||
{ | ||
return '><f>' . $this->formula . '</f><v>' . $this->value . '</v></c>'; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace Box\Spout\Writer\XLSX; | ||
|
||
|
||
use Box\Spout\Common\Type; | ||
use Box\Spout\Reader\ReaderFactory; | ||
use Box\Spout\Reader\XLSX\Sheet; | ||
use Box\Spout\TestUsingResource; | ||
use Box\Spout\Writer\WriterFactory; | ||
|
||
class FormulaTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
|
||
use TestUsingResource; | ||
|
||
/** | ||
* @throws \Box\Spout\Common\Exception\IOException | ||
* @throws \Box\Spout\Common\Exception\UnsupportedTypeException | ||
* @throws \Box\Spout\Writer\Exception\WriterNotOpenedException | ||
* @throws \Box\Spout\Common\Exception\InvalidArgumentException | ||
* @throws \Box\Spout\Reader\Exception\ReaderNotOpenedException | ||
*/ | ||
public function testGetXml() | ||
{ | ||
$fileName = 'test_formula.xlsx'; | ||
$this->createGeneratedFolderIfNeeded($fileName); | ||
$resourcePath = $this->getGeneratedResourcePath($fileName); | ||
|
||
$writer = WriterFactory::create(Type::XLSX); | ||
$writer->openToFile($resourcePath); | ||
|
||
$writer->addRows([ | ||
[1], | ||
[1], | ||
[1], | ||
[1], | ||
]); | ||
|
||
$writer->addRow([ | ||
new Formula('SUM(A1:A4)', 4) | ||
]); | ||
$writer->close(); | ||
|
||
|
||
$reader = ReaderFactory::create(Type::XLSX); | ||
$reader->open($resourcePath); | ||
|
||
$i = 0; | ||
/** @var Sheet $sheet */ | ||
foreach ($reader->getSheetIterator() as $sheet) { | ||
foreach ($sheet->getRowIterator() as $item) { | ||
$i++; | ||
if ($i == 5) { | ||
static::assertEquals(4, $item[0]); | ||
} | ||
} | ||
} | ||
} | ||
} |