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 |
|
|
|
38 |
protected function createWorkbookManager(): WorkbookManager
|
|
|
39 |
{
|
|
|
40 |
$workbook = new Workbook();
|
|
|
41 |
|
|
|
42 |
$fileSystemHelper = new FileSystemHelper(
|
|
|
43 |
$this->options->getTempFolder(),
|
|
|
44 |
new ZipHelper(),
|
|
|
45 |
new XLSX(),
|
|
|
46 |
$this->creator
|
|
|
47 |
);
|
|
|
48 |
$fileSystemHelper->createBaseFilesAndFolders();
|
|
|
49 |
|
|
|
50 |
$xlFolder = $fileSystemHelper->getXlFolder();
|
|
|
51 |
$sharedStringsManager = new SharedStringsManager($xlFolder, new XLSX());
|
|
|
52 |
|
|
|
53 |
$styleMerger = new StyleMerger();
|
|
|
54 |
$styleManager = new StyleManager(new StyleRegistry($this->options->DEFAULT_ROW_STYLE));
|
|
|
55 |
|
|
|
56 |
$commentsManager = new CommentsManager($xlFolder, new XLSX());
|
|
|
57 |
|
|
|
58 |
$worksheetManager = new WorksheetManager(
|
|
|
59 |
$this->options,
|
|
|
60 |
$styleManager,
|
|
|
61 |
$styleMerger,
|
|
|
62 |
$commentsManager,
|
|
|
63 |
$sharedStringsManager,
|
|
|
64 |
new XLSX(),
|
|
|
65 |
StringHelper::factory()
|
|
|
66 |
);
|
|
|
67 |
|
|
|
68 |
return new WorkbookManager(
|
|
|
69 |
$workbook,
|
|
|
70 |
$this->options,
|
|
|
71 |
$worksheetManager,
|
|
|
72 |
$styleManager,
|
|
|
73 |
$styleMerger,
|
|
|
74 |
$fileSystemHelper
|
|
|
75 |
);
|
|
|
76 |
}
|
|
|
77 |
}
|