27 return PHP_SAPI ===
'cli';
37 return basename(
$_SERVER[
'SCRIPT_FILENAME'],
'.php');
78 $baseDir = realpath(__DIR__ .
'/../../../samples');
81 $regex =
new RegexIterator($iterator,
'/^.+\.php$/', RecursiveRegexIterator::GET_MATCH);
84 foreach ($regex as $file) {
85 $file = str_replace(str_replace(
'\\',
'/',
$baseDir) .
'/',
'', str_replace(
'\\',
'/', $file[0]));
86 $info = pathinfo($file);
87 $category = str_replace(
'_',
' ',
$info[
'dirname']);
88 $name = str_replace(
'_',
' ', preg_replace(
'/(|\.php)/',
'',
$info[
'filename']));
89 if (!in_array($category, [
'.',
'boostrap',
'templates'])) {
90 if (!isset(
$files[$category])) {
118 foreach ($writers as $writerType) {
121 $callStartTime = microtime(
true);
122 $writer->save(
$path);
131 return \is_dir($folder) || \mkdir($folder);
141 $tempFolder = sys_get_temp_dir() .
'/phpspreadsheet';
143 throw new RuntimeException(sprintf(
'Directory "%s" was not created', $tempFolder));
159 $originalExtension = pathinfo(
$filename, PATHINFO_EXTENSION);
174 unlink($temporaryFilename);
176 return $temporaryFilename .
'.' . $extension;
191 $this->
log(
'Peak memory usage: ' . (memory_get_peak_usage(
true) / 1024 / 1024) .
'MB');
202 $callEndTime = microtime(
true);
203 $callTime = $callEndTime - $callStartTime;
205 $format = $reflection->getShortName();
206 $message =
"Write {$format} format to <code>{$path}</code> in " . sprintf(
'%.4f', $callTime) .
' seconds';
220 $callEndTime = microtime(
true);
221 $callTime = $callEndTime - $callStartTime;
222 $message =
"Read {$format} format from <code>{$path}</code> in " . sprintf(
'%.4f', $callTime) .
' seconds';
static static static createWriter(Spreadsheet $spreadsheet, $writerType)
Create Writer.
Helper class to be used in sample code.
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
logRead($format, $path, $callStartTime)
Log a line about the read operation.
getPageHeading()
Return the page heading.
getFilename($filename, $extension='xlsx')
Returns the filename that should be used for sample output.
getTemporaryFolder()
Returns the temporary directory and make sure it exists.
isDirOrMkdir(string $folder)
isCli()
Returns whether we run on CLI or browser.
getScriptFilename()
Return the filename currently being executed.
catch(Exception $e) $message
logWrite(IWriter $writer, $path, $callStartTime)
Log a line about the write operation.
setActiveSheetIndex($pIndex)
Set active sheet index.
write(Spreadsheet $spreadsheet, $filename, array $writers=['Xlsx', 'Xls'])
Write documents.
getPageTitle()
Return the page title.
getSamples()
Returns an array of all known samples.
isIndex()
Whether we are executing the index page.
getTemporaryFilename($extension='xlsx')
Return a random temporary file name.
logEndingNotes()
Log ending notes.