1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Box\Spout\Writer\Common\Creator; |
4
|
|
|
|
5
|
|
|
use Box\Spout\Common\Entity\Cell; |
6
|
|
|
use Box\Spout\Common\Entity\Row; |
7
|
|
|
use Box\Spout\Common\Entity\Style\Style; |
8
|
|
|
use Box\Spout\Writer\WriterInterface; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class WriterEntityFactory |
12
|
|
|
* Factory to create external entities |
13
|
|
|
*/ |
14
|
|
|
class WriterEntityFactory |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* This creates an instance of the appropriate writer, given the type of the file to be written |
18
|
|
|
* |
19
|
|
|
* @param string $writerType Type of the writer to instantiate |
20
|
|
|
* @throws \Box\Spout\Common\Exception\UnsupportedTypeException |
21
|
|
|
* @return WriterInterface |
22
|
|
|
*/ |
23
|
96 |
|
public static function createWriter($writerType) |
24
|
|
|
{ |
25
|
96 |
|
return WriterFactory::create($writerType); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* This creates an instance of the appropriate writer, given the extension of the file to be written |
30
|
|
|
* |
31
|
|
|
* @param string $path The path to the spreadsheet file. Supported extensions are .csv, .ods and .xlsx |
32
|
|
|
* @throws \Box\Spout\Common\Exception\IOException |
33
|
|
|
* @throws \Box\Spout\Common\Exception\UnsupportedTypeException |
34
|
|
|
* @return WriterInterface |
35
|
|
|
*/ |
36
|
|
|
public static function createWriterFromFile(string $path) |
37
|
|
|
{ |
38
|
|
|
return WriterFactory::createFromFile($path); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param Cell[] $cells |
43
|
|
|
* @param Style|null $rowStyle |
44
|
|
|
* @return Row |
45
|
|
|
*/ |
46
|
2 |
|
public static function createRow(array $cells = [], Style $rowStyle = null) |
47
|
|
|
{ |
48
|
2 |
|
return new Row($cells, $rowStyle); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param array $cellValues |
53
|
|
|
* @param Style|null $rowStyle |
54
|
|
|
* @return Row |
55
|
|
|
*/ |
56
|
78 |
|
public static function createRowFromArray(array $cellValues = [], Style $rowStyle = null) |
57
|
|
|
{ |
58
|
|
|
$cells = array_map(function ($cellValue) { |
59
|
78 |
|
return new Cell($cellValue); |
60
|
78 |
|
}, $cellValues); |
61
|
|
|
|
62
|
78 |
|
return new Row($cells, $rowStyle); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param mixed $cellValue |
67
|
|
|
* @param Style|null $cellStyle |
68
|
|
|
* @return Cell |
69
|
|
|
*/ |
70
|
2 |
|
public static function createCell($cellValue, Style $cellStyle = null) |
71
|
|
|
{ |
72
|
2 |
|
return new Cell($cellValue, $cellStyle); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|