| 1 |
efrain |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
declare(strict_types=1);
|
|
|
4 |
|
|
|
5 |
namespace OpenSpout\Writer\XLSX;
|
|
|
6 |
|
|
|
7 |
use OpenSpout\Common\Helper\Escaper\XLSX;
|
|
|
8 |
use OpenSpout\Common\Helper\StringHelper;
|
|
|
9 |
use OpenSpout\Writer\AbstractWriterMultiSheets;
|
|
|
10 |
use OpenSpout\Writer\Common\Entity\Workbook;
|
|
|
11 |
use OpenSpout\Writer\Common\Helper\ZipHelper;
|
|
|
12 |
use OpenSpout\Writer\Common\Manager\Style\StyleMerger;
|
|
|
13 |
use OpenSpout\Writer\XLSX\Helper\FileSystemHelper;
|
|
|
14 |
use OpenSpout\Writer\XLSX\Manager\CommentsManager;
|
|
|
15 |
use OpenSpout\Writer\XLSX\Manager\SharedStringsManager;
|
|
|
16 |
use OpenSpout\Writer\XLSX\Manager\Style\StyleManager;
|
|
|
17 |
use OpenSpout\Writer\XLSX\Manager\Style\StyleRegistry;
|
|
|
18 |
use OpenSpout\Writer\XLSX\Manager\WorkbookManager;
|
|
|
19 |
use OpenSpout\Writer\XLSX\Manager\WorksheetManager;
|
|
|
20 |
|
|
|
21 |
final class Writer extends AbstractWriterMultiSheets
|
|
|
22 |
{
|
|
|
23 |
/** @var string Content-Type value for the header */
|
|
|
24 |
protected static string $headerContentType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
|
|
|
25 |
|
|
|
26 |
private readonly Options $options;
|
|
|
27 |
|
|
|
28 |
public function __construct(?Options $options = null)
|
|
|
29 |
{
|
|
|
30 |
$this->options = $options ?? new Options();
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
public function getOptions(): Options
|
|
|
34 |
{
|
|
|
35 |
return $this->options;
|
|
|
36 |
}
|
|
|
37 |
|
| 1441 |
ariadna |
38 |
public function setCreator(string $creator): void
|
|
|
39 |
{
|
|
|
40 |
$props = $this->options->getProperties();
|
|
|
41 |
$this->options->setProperties(new Properties(
|
|
|
42 |
$props->title,
|
|
|
43 |
$props->subject,
|
|
|
44 |
$props->application,
|
|
|
45 |
$creator,
|
|
|
46 |
$props->lastModifiedBy,
|
|
|
47 |
$props->keywords,
|
|
|
48 |
$props->description,
|
|
|
49 |
$props->category,
|
|
|
50 |
$props->language,
|
|
|
51 |
$props->customProperties
|
|
|
52 |
));
|
|
|
53 |
}
|
|
|
54 |
|
| 1 |
efrain |
55 |
protected function createWorkbookManager(): WorkbookManager
|
|
|
56 |
{
|
|
|
57 |
$workbook = new Workbook();
|
|
|
58 |
|
|
|
59 |
$fileSystemHelper = new FileSystemHelper(
|
|
|
60 |
$this->options->getTempFolder(),
|
|
|
61 |
new ZipHelper(),
|
|
|
62 |
new XLSX(),
|
| 1441 |
ariadna |
63 |
$this->options->getProperties()
|
| 1 |
efrain |
64 |
);
|
|
|
65 |
$fileSystemHelper->createBaseFilesAndFolders();
|
|
|
66 |
|
|
|
67 |
$xlFolder = $fileSystemHelper->getXlFolder();
|
|
|
68 |
$sharedStringsManager = new SharedStringsManager($xlFolder, new XLSX());
|
|
|
69 |
|
|
|
70 |
$styleMerger = new StyleMerger();
|
| 1441 |
ariadna |
71 |
$escaper = new XLSX();
|
| 1 |
efrain |
72 |
|
| 1441 |
ariadna |
73 |
$styleManager = new StyleManager(
|
|
|
74 |
new StyleRegistry($this->options->DEFAULT_ROW_STYLE),
|
|
|
75 |
$escaper
|
|
|
76 |
);
|
|
|
77 |
|
| 1 |
efrain |
78 |
$commentsManager = new CommentsManager($xlFolder, new XLSX());
|
|
|
79 |
|
|
|
80 |
$worksheetManager = new WorksheetManager(
|
|
|
81 |
$this->options,
|
|
|
82 |
$styleManager,
|
|
|
83 |
$styleMerger,
|
|
|
84 |
$commentsManager,
|
|
|
85 |
$sharedStringsManager,
|
| 1441 |
ariadna |
86 |
$escaper,
|
| 1 |
efrain |
87 |
StringHelper::factory()
|
|
|
88 |
);
|
|
|
89 |
|
|
|
90 |
return new WorkbookManager(
|
|
|
91 |
$workbook,
|
|
|
92 |
$this->options,
|
|
|
93 |
$worksheetManager,
|
|
|
94 |
$styleManager,
|
|
|
95 |
$styleMerger,
|
|
|
96 |
$fileSystemHelper
|
|
|
97 |
);
|
|
|
98 |
}
|
|
|
99 |
}
|