| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\OpenSpout\Writer\XLSX; |
| 4 |
|
| 5 |
use FluentCart\OpenSpout\Writer\Common\Entity\Options; |
| 6 |
use FluentCart\OpenSpout\Writer\WriterMultiSheetsAbstract; |
| 7 |
/** |
| 8 |
* This class provides base support to write data to XLSX files. |
| 9 |
*/ |
| 10 |
class Writer extends WriterMultiSheetsAbstract |
| 11 |
{ |
| 12 |
/** @var string Content-Type value for the header */ |
| 13 |
protected static $headerContentType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; |
| 14 |
/** |
| 15 |
* Sets a custom temporary folder for creating intermediate files/folders. |
| 16 |
* This must be set before opening the writer. |
| 17 |
* |
| 18 |
* @param string $tempFolder Temporary folder where the files to create the XLSX will be stored |
| 19 |
* |
| 20 |
* @throws \OpenSpout\Writer\Exception\WriterAlreadyOpenedException If the writer was already opened |
| 21 |
* |
| 22 |
* @return Writer |
| 23 |
*/ |
| 24 |
public function setTempFolder($tempFolder) |
| 25 |
{ |
| 26 |
$this->throwIfWriterAlreadyOpened('Writer must be configured before opening it.'); |
| 27 |
$this->optionsManager->setOption(Options::TEMP_FOLDER, $tempFolder); |
| 28 |
return $this; |
| 29 |
} |
| 30 |
/** |
| 31 |
* Use inline string to be more memory efficient. If set to false, it will use shared strings. |
| 32 |
* This must be set before opening the writer. |
| 33 |
* |
| 34 |
* @param bool $shouldUseInlineStrings Whether inline or shared strings should be used |
| 35 |
* |
| 36 |
* @throws \OpenSpout\Writer\Exception\WriterAlreadyOpenedException If the writer was already opened |
| 37 |
* |
| 38 |
* @return Writer |
| 39 |
*/ |
| 40 |
public function setShouldUseInlineStrings($shouldUseInlineStrings) |
| 41 |
{ |
| 42 |
$this->throwIfWriterAlreadyOpened('Writer must be configured before opening it.'); |
| 43 |
$this->optionsManager->setOption(Options::SHOULD_USE_INLINE_STRINGS, $shouldUseInlineStrings); |
| 44 |
return $this; |
| 45 |
} |
| 46 |
/** |
| 47 |
* Merge cells. |
| 48 |
* Row coordinates are indexed from 1, columns from 0 (A = 0), |
| 49 |
* so a merge B2:G2 looks like $writer->mergeCells([1,2], [6, 2]);. |
| 50 |
* |
| 51 |
* You may use CellHelper::getColumnLettersFromColumnIndex() to convert from "B2" to "[1,2]" |
| 52 |
* |
| 53 |
* @param int[] $range1 - top left cell's coordinate [column, row] |
| 54 |
* @param int[] $range2 - bottom right cell's coordinate [column, row] |
| 55 |
* |
| 56 |
* @return $this |
| 57 |
*/ |
| 58 |
public function mergeCells(array $range1, array $range2) |
| 59 |
{ |
| 60 |
$this->optionsManager->addOption(Options::MERGE_CELLS, [$range1, $range2]); |
| 61 |
return $this; |
| 62 |
} |
| 63 |
} |
| 64 |
|