提交的内容
This commit is contained in:
0
vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Helper/Dimension.php
vendored
Executable file → Normal file
0
vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Helper/Dimension.php
vendored
Executable file → Normal file
89
vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Helper/Downloader.php
vendored
Normal file
89
vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Helper/Downloader.php
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheet\Helper;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Exception;
|
||||
|
||||
class Downloader
|
||||
{
|
||||
protected string $filepath;
|
||||
|
||||
protected string $filename;
|
||||
|
||||
protected string $filetype;
|
||||
|
||||
protected const CONTENT_TYPES = [
|
||||
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
'xls' => 'application/vnd.ms-excel',
|
||||
'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
|
||||
'csv' => 'text/csv',
|
||||
'html' => 'text/html',
|
||||
'pdf' => 'application/pdf',
|
||||
];
|
||||
|
||||
public function __construct(string $folder, string $filename, ?string $filetype = null)
|
||||
{
|
||||
if ((is_dir($folder) === false) || (is_readable($folder) === false)) {
|
||||
throw new Exception('Folder is not accessible');
|
||||
}
|
||||
$filepath = "{$folder}/{$filename}";
|
||||
$this->filepath = (string) realpath($filepath);
|
||||
$this->filename = basename($filepath);
|
||||
if ((file_exists($this->filepath) === false) || (is_readable($this->filepath) === false)) {
|
||||
throw new Exception('File not found, or cannot be read');
|
||||
}
|
||||
|
||||
$filetype ??= pathinfo($filename, PATHINFO_EXTENSION);
|
||||
if (array_key_exists(strtolower($filetype), self::CONTENT_TYPES) === false) {
|
||||
throw new Exception('Invalid filetype: cannot be downloaded');
|
||||
}
|
||||
$this->filetype = strtolower($filetype);
|
||||
}
|
||||
|
||||
public function download(): void
|
||||
{
|
||||
$this->headers();
|
||||
|
||||
readfile($this->filepath);
|
||||
}
|
||||
|
||||
public function headers(): void
|
||||
{
|
||||
ob_clean();
|
||||
|
||||
$this->contentType();
|
||||
$this->contentDisposition();
|
||||
$this->cacheHeaders();
|
||||
$this->fileSize();
|
||||
|
||||
flush();
|
||||
}
|
||||
|
||||
protected function contentType(): void
|
||||
{
|
||||
header('Content-Type: ' . self::CONTENT_TYPES[$this->filetype]);
|
||||
}
|
||||
|
||||
protected function contentDisposition(): void
|
||||
{
|
||||
header('Content-Disposition: attachment;filename="' . $this->filename . '"');
|
||||
}
|
||||
|
||||
protected function cacheHeaders(): void
|
||||
{
|
||||
header('Cache-Control: max-age=0');
|
||||
// If you're serving to IE 9, then the following may be needed
|
||||
header('Cache-Control: max-age=1');
|
||||
|
||||
// If you're serving to IE over SSL, then the following may be needed
|
||||
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
|
||||
header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
|
||||
header('Pragma: public'); // HTTP/1.0
|
||||
}
|
||||
|
||||
protected function fileSize(): void
|
||||
{
|
||||
header('Content-Length: ' . filesize($this->filepath));
|
||||
}
|
||||
}
|
||||
46
vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Helper/Handler.php
vendored
Normal file
46
vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Helper/Handler.php
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheet\Helper;
|
||||
|
||||
class Handler
|
||||
{
|
||||
/** @var string */
|
||||
private static $invalidHex = 'Y';
|
||||
|
||||
// A bunch of methods to show that we continue
|
||||
// to capture messages even using PhpUnit 10.
|
||||
public static function suppressed(): bool
|
||||
{
|
||||
return @trigger_error('hello');
|
||||
}
|
||||
|
||||
public static function deprecated(): string
|
||||
{
|
||||
return (string) hexdec(self::$invalidHex);
|
||||
}
|
||||
|
||||
public static function notice(string $value): void
|
||||
{
|
||||
date_default_timezone_set($value);
|
||||
}
|
||||
|
||||
public static function warning(): bool
|
||||
{
|
||||
return file_get_contents(__FILE__ . 'noexist') !== false;
|
||||
}
|
||||
|
||||
public static function userDeprecated(): bool
|
||||
{
|
||||
return trigger_error('hello', E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
public static function userNotice(): bool
|
||||
{
|
||||
return trigger_error('userNotice', E_USER_NOTICE);
|
||||
}
|
||||
|
||||
public static function userWarning(): bool
|
||||
{
|
||||
return trigger_error('userWarning', E_USER_WARNING);
|
||||
}
|
||||
}
|
||||
35
vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Helper/Html.php
vendored
Executable file → Normal file
35
vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Helper/Html.php
vendored
Executable file → Normal file
@ -714,7 +714,7 @@ class Html
|
||||
return self::COLOUR_MAP[$colorName] ?? '';
|
||||
}
|
||||
|
||||
private function startFontTag(DOMElement $tag): void
|
||||
protected function startFontTag(DOMElement $tag): void
|
||||
{
|
||||
$attrs = $tag->attributes;
|
||||
if ($attrs !== null) {
|
||||
@ -737,72 +737,72 @@ class Html
|
||||
}
|
||||
}
|
||||
|
||||
private function endFontTag(): void
|
||||
protected function endFontTag(): void
|
||||
{
|
||||
$this->face = $this->size = $this->color = null;
|
||||
}
|
||||
|
||||
private function startBoldTag(): void
|
||||
protected function startBoldTag(): void
|
||||
{
|
||||
$this->bold = true;
|
||||
}
|
||||
|
||||
private function endBoldTag(): void
|
||||
protected function endBoldTag(): void
|
||||
{
|
||||
$this->bold = false;
|
||||
}
|
||||
|
||||
private function startItalicTag(): void
|
||||
protected function startItalicTag(): void
|
||||
{
|
||||
$this->italic = true;
|
||||
}
|
||||
|
||||
private function endItalicTag(): void
|
||||
protected function endItalicTag(): void
|
||||
{
|
||||
$this->italic = false;
|
||||
}
|
||||
|
||||
private function startUnderlineTag(): void
|
||||
protected function startUnderlineTag(): void
|
||||
{
|
||||
$this->underline = true;
|
||||
}
|
||||
|
||||
private function endUnderlineTag(): void
|
||||
protected function endUnderlineTag(): void
|
||||
{
|
||||
$this->underline = false;
|
||||
}
|
||||
|
||||
private function startSubscriptTag(): void
|
||||
protected function startSubscriptTag(): void
|
||||
{
|
||||
$this->subscript = true;
|
||||
}
|
||||
|
||||
private function endSubscriptTag(): void
|
||||
protected function endSubscriptTag(): void
|
||||
{
|
||||
$this->subscript = false;
|
||||
}
|
||||
|
||||
private function startSuperscriptTag(): void
|
||||
protected function startSuperscriptTag(): void
|
||||
{
|
||||
$this->superscript = true;
|
||||
}
|
||||
|
||||
private function endSuperscriptTag(): void
|
||||
protected function endSuperscriptTag(): void
|
||||
{
|
||||
$this->superscript = false;
|
||||
}
|
||||
|
||||
private function startStrikethruTag(): void
|
||||
protected function startStrikethruTag(): void
|
||||
{
|
||||
$this->strikethrough = true;
|
||||
}
|
||||
|
||||
private function endStrikethruTag(): void
|
||||
protected function endStrikethruTag(): void
|
||||
{
|
||||
$this->strikethrough = false;
|
||||
}
|
||||
|
||||
private function breakTag(): void
|
||||
protected function breakTag(): void
|
||||
{
|
||||
$this->stringData .= "\n";
|
||||
}
|
||||
@ -826,8 +826,9 @@ class Html
|
||||
if (isset($callbacks[$callbackTag])) {
|
||||
$elementHandler = $callbacks[$callbackTag];
|
||||
if (method_exists($this, $elementHandler)) {
|
||||
/** @phpstan-ignore-next-line */
|
||||
call_user_func([$this, $elementHandler], $element);
|
||||
/** @var callable */
|
||||
$callable = [$this, $elementHandler];
|
||||
call_user_func($callable, $element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
47
vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Helper/Sample.php
vendored
Executable file → Normal file
47
vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Helper/Sample.php
vendored
Executable file → Normal file
@ -2,7 +2,9 @@
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheet\Helper;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Chart\Chart;
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
use PhpOffice\PhpSpreadsheet\Settings;
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\IWriter;
|
||||
@ -12,6 +14,7 @@ use RecursiveRegexIterator;
|
||||
use ReflectionClass;
|
||||
use RegexIterator;
|
||||
use RuntimeException;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Helper class to be used in sample code.
|
||||
@ -120,7 +123,7 @@ class Sample
|
||||
* @param string $filename
|
||||
* @param string[] $writers
|
||||
*/
|
||||
public function write(Spreadsheet $spreadsheet, $filename, array $writers = ['Xlsx', 'Xls']): void
|
||||
public function write(Spreadsheet $spreadsheet, $filename, array $writers = ['Xlsx', 'Xls'], bool $withCharts = false, ?callable $writerCallback = null): void
|
||||
{
|
||||
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
|
||||
$spreadsheet->setActiveSheetIndex(0);
|
||||
@ -129,9 +132,16 @@ class Sample
|
||||
foreach ($writers as $writerType) {
|
||||
$path = $this->getFilename($filename, mb_strtolower($writerType));
|
||||
$writer = IOFactory::createWriter($spreadsheet, $writerType);
|
||||
$writer->setIncludeCharts($withCharts);
|
||||
if ($writerCallback !== null) {
|
||||
$writerCallback($writer);
|
||||
}
|
||||
$callStartTime = microtime(true);
|
||||
$writer->save($path);
|
||||
$this->logWrite($writer, $path, /** @scrutinizer ignore-type */ $callStartTime);
|
||||
if ($this->isCli() === false) {
|
||||
echo '<a href="/download.php?type=' . pathinfo($path, PATHINFO_EXTENSION) . '&name=' . basename($path) . '">Download ' . basename($path) . '</a><br />';
|
||||
}
|
||||
}
|
||||
|
||||
$this->logEndingNotes();
|
||||
@ -147,7 +157,7 @@ class Sample
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getTemporaryFolder()
|
||||
public function getTemporaryFolder()
|
||||
{
|
||||
$tempFolder = sys_get_temp_dir() . '/phpspreadsheet';
|
||||
if (!$this->isDirOrMkdir($tempFolder)) {
|
||||
@ -162,10 +172,8 @@ class Sample
|
||||
*
|
||||
* @param string $filename
|
||||
* @param string $extension
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFilename($filename, $extension = 'xlsx')
|
||||
public function getFilename($filename, $extension = 'xlsx'): string
|
||||
{
|
||||
$originalExtension = pathinfo($filename, PATHINFO_EXTENSION);
|
||||
|
||||
@ -195,7 +203,29 @@ class Sample
|
||||
public function log(string $message): void
|
||||
{
|
||||
$eol = $this->isCli() ? PHP_EOL : '<br />';
|
||||
echo date('H:i:s ') . $message . $eol;
|
||||
echo($this->isCli() ? date('H:i:s ') : '') . $message . $eol;
|
||||
}
|
||||
|
||||
public function renderChart(Chart $chart, string $fileName): void
|
||||
{
|
||||
if ($this->isCli() === true) {
|
||||
return;
|
||||
}
|
||||
|
||||
Settings::setChartRenderer(\PhpOffice\PhpSpreadsheet\Chart\Renderer\MtJpGraphRenderer::class);
|
||||
|
||||
$fileName = $this->getFilename($fileName, 'png');
|
||||
|
||||
try {
|
||||
$chart->render($fileName);
|
||||
$this->log('Rendered image: ' . $fileName);
|
||||
$imageData = file_get_contents($fileName);
|
||||
if ($imageData !== false) {
|
||||
echo '<div><img src="data:image/gif;base64,' . base64_encode($imageData) . '" /></div>';
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
$this->log('Error rendering chart: ' . $e->getMessage() . PHP_EOL);
|
||||
}
|
||||
}
|
||||
|
||||
public function titles(string $category, string $functionName, ?string $description = null): void
|
||||
@ -246,7 +276,10 @@ class Sample
|
||||
$callTime = $callEndTime - $callStartTime;
|
||||
$reflection = new ReflectionClass($writer);
|
||||
$format = $reflection->getShortName();
|
||||
$message = "Write {$format} format to <code>{$path}</code> in " . sprintf('%.4f', $callTime) . ' seconds';
|
||||
|
||||
$message = ($this->isCli() === true)
|
||||
? "Write {$format} format to {$path} in " . sprintf('%.4f', $callTime) . ' seconds'
|
||||
: "Write {$format} format to <code>{$path}</code> in " . sprintf('%.4f', $callTime) . ' seconds';
|
||||
|
||||
$this->log($message);
|
||||
}
|
||||
|
||||
0
vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Helper/Size.php
vendored
Executable file → Normal file
0
vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Helper/Size.php
vendored
Executable file → Normal file
16
vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Helper/TextGrid.php
vendored
Executable file → Normal file
16
vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Helper/TextGrid.php
vendored
Executable file → Normal file
@ -48,17 +48,17 @@ class TextGrid
|
||||
|
||||
public function render(): string
|
||||
{
|
||||
$this->gridDisplay = $this->isCli ? '' : '<code>';
|
||||
$this->gridDisplay = $this->isCli ? '' : '<pre>';
|
||||
|
||||
$maxRow = max($this->rows);
|
||||
$maxRowLength = strlen((string) $maxRow) + 1;
|
||||
$maxRowLength = mb_strlen((string) $maxRow) + 1;
|
||||
$columnWidths = $this->getColumnWidths();
|
||||
|
||||
$this->renderColumnHeader($maxRowLength, $columnWidths);
|
||||
$this->renderRows($maxRowLength, $columnWidths);
|
||||
$this->renderFooter($maxRowLength, $columnWidths);
|
||||
|
||||
$this->gridDisplay .= $this->isCli ? '' : '</code>';
|
||||
$this->gridDisplay .= $this->isCli ? '' : '</pre>';
|
||||
|
||||
return $this->gridDisplay;
|
||||
}
|
||||
@ -75,9 +75,9 @@ class TextGrid
|
||||
private function renderCells(array $rowData, array $columnWidths): void
|
||||
{
|
||||
foreach ($rowData as $column => $cell) {
|
||||
$cell = ($this->isCli) ? (string) $cell : htmlentities((string) $cell);
|
||||
$displayCell = ($this->isCli) ? (string) $cell : htmlentities((string) $cell);
|
||||
$this->gridDisplay .= '| ';
|
||||
$this->gridDisplay .= str_pad($cell, $columnWidths[$column] + 1, ' ');
|
||||
$this->gridDisplay .= $displayCell . str_repeat(' ', $columnWidths[$column] - mb_strlen($cell ?? '') + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -126,12 +126,12 @@ class TextGrid
|
||||
|
||||
foreach ($columnData as $columnValue) {
|
||||
if (is_string($columnValue)) {
|
||||
$columnWidth = max($columnWidth, strlen($columnValue));
|
||||
$columnWidth = max($columnWidth, mb_strlen($columnValue));
|
||||
} elseif (is_bool($columnValue)) {
|
||||
$columnWidth = max($columnWidth, strlen($columnValue ? 'TRUE' : 'FALSE'));
|
||||
$columnWidth = max($columnWidth, mb_strlen($columnValue ? 'TRUE' : 'FALSE'));
|
||||
}
|
||||
|
||||
$columnWidth = max($columnWidth, strlen((string) $columnWidth));
|
||||
$columnWidth = max($columnWidth, mb_strlen((string) $columnWidth));
|
||||
}
|
||||
|
||||
return $columnWidth;
|
||||
|
||||
Reference in New Issue
Block a user