ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Ods.php
Go to the documentation of this file.
1 <?php
2 
4 
17 
18 class Ods extends BaseWriter
19 {
25  private $spreadSheet;
26 
31 
35  private $writerPartMeta;
36 
41 
46 
51 
56 
61 
65  public function __construct(Spreadsheet $spreadsheet)
66  {
67  $this->setSpreadsheet($spreadsheet);
68 
69  $this->writerPartContent = new Content($this);
70  $this->writerPartMeta = new Meta($this);
71  $this->writerPartMetaInf = new MetaInf($this);
72  $this->writerPartMimetype = new Mimetype($this);
73  $this->writerPartSettings = new Settings($this);
74  $this->writerPartStyles = new Styles($this);
75  $this->writerPartThumbnails = new Thumbnails($this);
76  }
77 
78  public function getWriterPartContent(): Content
79  {
81  }
82 
83  public function getWriterPartMeta(): Meta
84  {
85  return $this->writerPartMeta;
86  }
87 
88  public function getWriterPartMetaInf(): MetaInf
89  {
91  }
92 
93  public function getWriterPartMimetype(): Mimetype
94  {
96  }
97 
98  public function getWriterPartSettings(): Settings
99  {
101  }
102 
103  public function getWriterPartStyles(): Styles
104  {
106  }
107 
109  {
111  }
112 
118  public function save($pFilename): void
119  {
120  if (!$this->spreadSheet) {
121  throw new WriterException('PhpSpreadsheet object unassigned.');
122  }
123 
124  // garbage collect
125  $this->spreadSheet->garbageCollect();
126 
127  $this->openFileHandle($pFilename);
128 
129  $zip = $this->createZip();
130 
131  $zip->addFile('META-INF/manifest.xml', $this->getWriterPartMetaInf()->write());
132  $zip->addFile('Thumbnails/thumbnail.png', $this->getWriterPartthumbnails()->write());
133  $zip->addFile('content.xml', $this->getWriterPartcontent()->write());
134  $zip->addFile('meta.xml', $this->getWriterPartmeta()->write());
135  $zip->addFile('mimetype', $this->getWriterPartmimetype()->write());
136  $zip->addFile('settings.xml', $this->getWriterPartsettings()->write());
137  $zip->addFile('styles.xml', $this->getWriterPartstyles()->write());
138 
139  // Close file
140  try {
141  $zip->finish();
142  } catch (OverflowException $e) {
143  throw new WriterException('Could not close resource.');
144  }
145 
146  $this->maybeCloseFileHandle();
147  }
148 
154  private function createZip()
155  {
156  // Try opening the ZIP file
157  if (!is_resource($this->fileHandle)) {
158  throw new WriterException('Could not open resource for writing.');
159  }
160 
161  // Create new ZIP stream
162  $options = new Archive();
163  $options->setEnableZip64(false);
164  $options->setOutputStream($this->fileHandle);
165 
166  return new ZipStream(null, $options);
167  }
168 
174  public function getSpreadsheet()
175  {
176  if ($this->spreadSheet !== null) {
177  return $this->spreadSheet;
178  }
179 
180  throw new WriterException('No PhpSpreadsheet assigned.');
181  }
182 
190  public function setSpreadsheet(Spreadsheet $spreadsheet)
191  {
192  $this->spreadSheet = $spreadsheet;
193 
194  return $this;
195  }
196 }
Class Version .
Definition: Bigint.php:4
getSpreadsheet()
Get Spreadsheet object.
Definition: Ods.php:174
createZip()
Create zip object.
Definition: Ods.php:154
save($pFilename)
Save PhpSpreadsheet to file.
Definition: Ods.php:118
setSpreadsheet(Spreadsheet $spreadsheet)
Set Spreadsheet object.
Definition: Ods.php:190
__construct(Spreadsheet $spreadsheet)
Create a new Ods.
Definition: Ods.php:65
openFileHandle($filename)
Open file handle.
Definition: BaseWriter.php:102
maybeCloseFileHandle()
Close file handle only if we opened it ourselves.
Definition: BaseWriter.php:123