Skip to content

Commit

Permalink
Class methods doc and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Sonichaos360 committed Jun 28, 2021
1 parent 6a630b1 commit 4c9e74e
Showing 1 changed file with 70 additions and 10 deletions.
80 changes: 70 additions & 10 deletions src/PHPSimpleSpreadsheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,44 @@ public function __construct()
);
}

/**
* Set sheet name prop
*
* @return this Current object
*/
public function setName($name = '')
{
$this->name = $name;
return $this;
}

/**
* Set sheet author prop
*
* @return this Current object
*/
public function setAuthor($author = '')
{
$this->author = $author;
return $this;
}

/**
* Set sheet columns range
*
* @return this Current object
*/
public function setRange($range = array())
{
$this->range = $range;
return $this;
}

public function setRowCount($rowCount = array())
{
$this->rowCount = $rowCount;
return $this;
}

/**
* Collect created temp files and zips into unique XLSX file
*
* @return bool ZIP process result
*/
public function doXmlx($destination)
{
$source = $this->tempDir.$this->name;
Expand Down Expand Up @@ -121,6 +135,11 @@ public function doXmlx($destination)
return $zip->close();
}

/**
* Clear all past temp data it is necessary in case there is an old sheet using the same file name
*
* @return bool Delete process result
*/
public function cleanTemp()
{
//Clean
Expand All @@ -135,6 +154,11 @@ public function cleanTemp()
$this->removeDirectory($this->tempDir.$this->name);
}

/**
* Delete main XML temp directory and files
*
* @return bool Delete process result
*/
public function removeDirectory($path)
{
$files = glob($path . '/*');
Expand All @@ -144,15 +168,20 @@ public function removeDirectory($path)
}

if (is_dir($path)) {
rmdir($path);
return rmdir($path);
}

return;
return false;
}


/**
* Create base xml files in order to start sheet creation
*
* @return void
*/
public function startSheet()
{
//Delete files generated after
//Delete old generated file
if (file_exists($this->tempDir.$this->name.".xlsx")) {
unlink($this->tempDir.$this->name.".xlsx");
}
Expand Down Expand Up @@ -182,11 +211,21 @@ public function startSheet()
file_put_contents($this->tempDir.$this->name.'/xl/worksheets/sheet1.xml', str_replace("[[COLUMNS_WIDTH]]", $this->columnsWidth, file_get_contents($this->classPath.DIRECTORY_SEPARATOR."xml".DIRECTORY_SEPARATOR."sheet_start.xml")), FILE_APPEND | LOCK_EX);
}

/**
* Close XML tags in order to finish sheet creation
*
* @return void
*/
public function endSheet()
{
file_put_contents($this->tempDir.$this->name.'/xl/worksheets/sheet1.xml', file_get_contents($this->classPath.DIRECTORY_SEPARATOR."xml".DIRECTORY_SEPARATOR."sheet_end.xml"), FILE_APPEND | LOCK_EX);
}

/**
* Insert new row in workbook and increase row count
*
* @return void
*/
public function insertRow($row, $styles = "")
{
$finalRow = '<row collapsed="false" customFormat="false" customHeight="false" hidden="false" ht="12.1" outlineLevel="0" r="'.$this->rowCount.'">';
Expand All @@ -204,23 +243,39 @@ public function insertRow($row, $styles = "")
$this->rowCount++;
}

/**
* Creates a temp file including data related to the current sheet creation, this is necessary in case of big multiple parts sheet creation
*
* @return bool Process result
*/
public function pauseSheet()
{
return file_put_contents($this->tempDir.$this->name.'.json', json_encode(['range' => $this->range, 'rowcount' => $this->rowCount]), LOCK_EX);
}

/**
* Load current temp paused file and continue sheet creation
*
* @return bool Process result
*/
public function continueSheet($sheetname)
{
if (file_exists($this->tempDir.$sheetname.'.json')) {
$data = json_decode(file_get_contents($this->tempDir.$sheetname.'.json'), true);
$this->range = $data["range"];
$this->rowCount = $data["rowcount"];
$this->name = $sheetname;
return true;
} else {
throw new \Exception('Sheet config file missing..');
}
}

/**
* Parse special chars encoding in row content
*
* @return string Parsed string
*/
public function clean($str)
{
return str_replace(
Expand All @@ -230,6 +285,11 @@ public function clean($str)
);
}

/**
* Set sheet columns width
*
* @return void
*/
public function setColumnWidth($cols)
{
$i = 1;
Expand Down

0 comments on commit 4c9e74e

Please sign in to comment.