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