1 parent
30366e6a5d
commit
3bb4fd3d48
14 files changed
+252
-112
No files matched your search
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace Box\Spout\Writer\Common\Entity;
|
||||
|
||||
use Box\Spout\Writer\Common\Manager\SheetManager;
|
||||
|
||||
/**
|
||||
* Class Sheet
|
||||
* External representation of a worksheet
|
||||
*
|
||||
* @package Box\Spout\Writer\Common\Entity
|
||||
*/
|
||||
class Sheet
|
||||
{
|
||||
const DEFAULT_SHEET_NAME_PREFIX = 'Sheet';
|
||||
|
||||
/** @var int Index of the sheet, based on order in the workbook (zero-based) */
|
||||
private $index;
|
||||
|
||||
/** @var string ID of the sheet's associated workbook. Used to restrict sheet name uniqueness enforcement to a single workbook */
|
||||
private $associatedWorkbookId;
|
||||
|
||||
/** @var string Name of the sheet */
|
||||
private $name;
|
||||
|
||||
/** @var SheetManager Sheet manager */
|
||||
private $sheetManager;
|
||||
|
||||
/**
|
||||
* @param int $sheetIndex Index of the sheet, based on order in the workbook (zero-based)
|
||||
* @param string $associatedWorkbookId ID of the sheet's associated workbook
|
||||
* @param SheetManager $sheetManager
|
||||
*/
|
||||
public function __construct($sheetIndex, $associatedWorkbookId, SheetManager $sheetManager)
|
||||
{
|
||||
$this->index = $sheetIndex;
|
||||
$this->associatedWorkbookId = $associatedWorkbookId;
|
||||
|
||||
$this->sheetManager = $sheetManager;
|
||||
$this->sheetManager->markWorkbookIdAsUsed($associatedWorkbookId);
|
||||
|
||||
$this->setName(self::DEFAULT_SHEET_NAME_PREFIX . ($sheetIndex + 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* @api
|
||||
* @return int Index of the sheet, based on order in the workbook (zero-based)
|
||||
*/
|
||||
public function getIndex()
|
||||
{
|
||||
return $this->index;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAssociatedWorkbookId()
|
||||
{
|
||||
return $this->associatedWorkbookId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @api
|
||||
* @return string Name of the sheet
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of the sheet. Note that Excel has some restrictions on the name:
|
||||
* - it should not be blank
|
||||
* - it should not exceed 31 characters
|
||||
* - it should not contain these characters: \ / ? * : [ or ]
|
||||
* - it should be unique
|
||||
*
|
||||
* @api
|
||||
* @param string $name Name of the sheet
|
||||
* @return Sheet
|
||||
* @throws \Box\Spout\Writer\Exception\InvalidSheetNameException If the sheet's name is invalid.
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->sheetManager->throwIfNameIsInvalid($name, $this);
|
||||
|
||||
$this->name = $name;
|
||||
|
||||
$this->sheetManager->markSheetNameAsUsed($this);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
namespace Box\Spout\Writer\Common\Entity;
|
||||
|
||||
use Box\Spout\Writer\Common\Sheet;
|
||||
|
||||
/**
|
||||
* Class Worksheet
|
||||
* Entity describing a Worksheet
|
||||
|
||||
Reference in new issue
Block a user