1 | <?php |
||
15 | class Writer extends AbstractMultiSheetsWriter |
||
16 | { |
||
17 | /** Default style font values */ |
||
18 | const DEFAULT_FONT_SIZE = 12; |
||
19 | const DEFAULT_FONT_NAME = 'Calibri'; |
||
20 | |||
21 | /** @var string Content-Type value for the header */ |
||
22 | protected static $headerContentType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; |
||
23 | |||
24 | /** @var string Temporary folder where the files to create the XLSX will be stored */ |
||
25 | protected $tempFolder; |
||
26 | |||
27 | /** @var bool Whether inline or shared strings should be used - inline string is more memory efficient */ |
||
28 | protected $shouldUseInlineStrings = true; |
||
29 | |||
30 | /** @var Internal\Workbook The workbook for the XLSX file */ |
||
31 | protected $book; |
||
32 | |||
33 | /** |
||
34 | * Sets a custom temporary folder for creating intermediate files/folders. |
||
35 | * This must be set before opening the writer. |
||
36 | * |
||
37 | * @api |
||
38 | * @param string $tempFolder Temporary folder where the files to create the XLSX will be stored |
||
39 | * @return Writer |
||
40 | * @throws \Box\Spout\Writer\Exception\WriterAlreadyOpenedException If the writer was already opened |
||
41 | */ |
||
42 | 6 | public function setTempFolder($tempFolder) |
|
43 | { |
||
44 | 6 | $this->throwIfWriterAlreadyOpened('Writer must be configured before opening it.'); |
|
45 | |||
46 | 3 | $this->tempFolder = $tempFolder; |
|
47 | 3 | return $this; |
|
48 | } |
||
49 | |||
50 | /** |
||
51 | * Use inline string to be more memory efficient. If set to false, it will use shared strings. |
||
52 | * This must be set before opening the writer. |
||
53 | * |
||
54 | * @api |
||
55 | * @param bool $shouldUseInlineStrings Whether inline or shared strings should be used |
||
56 | * @return Writer |
||
57 | * @throws \Box\Spout\Writer\Exception\WriterAlreadyOpenedException If the writer was already opened |
||
58 | */ |
||
59 | 78 | public function setShouldUseInlineStrings($shouldUseInlineStrings) |
|
66 | |||
67 | /** |
||
68 | * Configures the write and sets the current sheet pointer to a new sheet. |
||
69 | * |
||
70 | * @return void |
||
71 | * @throws \Box\Spout\Common\Exception\IOException If unable to open the file for writing |
||
72 | */ |
||
73 | 123 | protected function openWriter() |
|
81 | |||
82 | /** |
||
83 | * @return Internal\Workbook The workbook representing the file to be written |
||
84 | */ |
||
85 | 96 | protected function getWorkbook() |
|
89 | |||
90 | /** |
||
91 | * Adds data to the currently opened writer. |
||
92 | * If shouldCreateNewSheetsAutomatically option is set to true, it will handle pagination |
||
93 | * with the creation of new worksheets if one worksheet has reached its maximum capicity. |
||
94 | * |
||
95 | * @param array $dataRow Array containing data to be written. |
||
96 | * Example $dataRow = ['data1', 1234, null, '', 'data5']; |
||
97 | * @param \Box\Spout\Writer\Style\Style $style Style to be applied to the row. |
||
98 | * @return void |
||
99 | * @throws \Box\Spout\Writer\Exception\WriterNotOpenedException If the book is not created yet |
||
100 | * @throws \Box\Spout\Common\Exception\IOException If unable to write data |
||
101 | */ |
||
102 | 87 | protected function addRowToWriter(array $dataRow, $style) |
|
107 | |||
108 | /** |
||
109 | * Returns the default style to be applied to rows. |
||
110 | * |
||
111 | * @return \Box\Spout\Writer\Style\Style |
||
112 | */ |
||
113 | 138 | protected function getDefaultRowStyle() |
|
120 | |||
121 | /** |
||
122 | * Closes the writer, preventing any additional writing. |
||
123 | * |
||
124 | * @return void |
||
125 | */ |
||
126 | 93 | protected function closeWriter() |
|
132 | } |
||
133 |