diff --git a/assets/uploads/vouchers/6a05e1314a730-Captura de pantalla 2026-05-14 095002.png b/assets/uploads/vouchers/6a05e1314a730-Captura de pantalla 2026-05-14 095002.png deleted file mode 100644 index cda22088..00000000 Binary files a/assets/uploads/vouchers/6a05e1314a730-Captura de pantalla 2026-05-14 095002.png and /dev/null differ diff --git a/assets/uploads/vouchers/6a065123cd904-987.png b/assets/uploads/vouchers/6a065123cd904-987.png new file mode 100644 index 00000000..1602af55 Binary files /dev/null and b/assets/uploads/vouchers/6a065123cd904-987.png differ diff --git a/assets/uploads/vouchers/6a06563c8c198-Captura de pantalla 2026-05-14 180630.png b/assets/uploads/vouchers/6a06563c8c198-Captura de pantalla 2026-05-14 180630.png new file mode 100644 index 00000000..5314a043 Binary files /dev/null and b/assets/uploads/vouchers/6a06563c8c198-Captura de pantalla 2026-05-14 180630.png differ diff --git a/assets/uploads/vouchers/6a0656974ed8f-153.png b/assets/uploads/vouchers/6a0656974ed8f-153.png new file mode 100644 index 00000000..7d408b49 Binary files /dev/null and b/assets/uploads/vouchers/6a0656974ed8f-153.png differ diff --git a/assets/uploads/vouchers/6a07369773e2a-Captura de pantalla 2026-05-15 100633.png b/assets/uploads/vouchers/6a07369773e2a-Captura de pantalla 2026-05-15 100633.png new file mode 100644 index 00000000..8ba6cb8f Binary files /dev/null and b/assets/uploads/vouchers/6a07369773e2a-Captura de pantalla 2026-05-15 100633.png differ diff --git a/assets/uploads/vouchers/6a073a137ef5e-Captura de pantalla 2026-05-15 102012.png b/assets/uploads/vouchers/6a073a137ef5e-Captura de pantalla 2026-05-15 102012.png new file mode 100644 index 00000000..1e59c50a Binary files /dev/null and b/assets/uploads/vouchers/6a073a137ef5e-Captura de pantalla 2026-05-15 102012.png differ diff --git a/assets/uploads/vouchers/6a073a9d06478-Captura de pantalla 2026-05-15 102331.png b/assets/uploads/vouchers/6a073a9d06478-Captura de pantalla 2026-05-15 102331.png new file mode 100644 index 00000000..26c9ce95 Binary files /dev/null and b/assets/uploads/vouchers/6a073a9d06478-Captura de pantalla 2026-05-15 102331.png differ diff --git a/assets/uploads/vouchers/6a074ad060f50-Captura de pantalla 2026-05-15 113301.png b/assets/uploads/vouchers/6a074ad060f50-Captura de pantalla 2026-05-15 113301.png new file mode 100644 index 00000000..26312f76 Binary files /dev/null and b/assets/uploads/vouchers/6a074ad060f50-Captura de pantalla 2026-05-15 113301.png differ diff --git a/assets/uploads/vouchers/6a074b7537c71-Captura de pantalla 2026-05-15 113357.png b/assets/uploads/vouchers/6a074b7537c71-Captura de pantalla 2026-05-15 113357.png new file mode 100644 index 00000000..dc079fc2 Binary files /dev/null and b/assets/uploads/vouchers/6a074b7537c71-Captura de pantalla 2026-05-15 113357.png differ diff --git a/assets/uploads/vouchers/6a074d0741071-Captura de pantalla 2026-05-15 114217.png b/assets/uploads/vouchers/6a074d0741071-Captura de pantalla 2026-05-15 114217.png new file mode 100644 index 00000000..32ca5871 Binary files /dev/null and b/assets/uploads/vouchers/6a074d0741071-Captura de pantalla 2026-05-15 114217.png differ diff --git a/assets/uploads/vouchers/6a07544df0665-Captura de pantalla 2026-05-15 121146.png b/assets/uploads/vouchers/6a07544df0665-Captura de pantalla 2026-05-15 121146.png new file mode 100644 index 00000000..da4bab3a Binary files /dev/null and b/assets/uploads/vouchers/6a07544df0665-Captura de pantalla 2026-05-15 121146.png differ diff --git a/assets/uploads/vouchers/6a07772927899-Screenshot_341.png b/assets/uploads/vouchers/6a07772927899-Screenshot_341.png new file mode 100644 index 00000000..43ac0e1d Binary files /dev/null and b/assets/uploads/vouchers/6a07772927899-Screenshot_341.png differ diff --git a/assets/uploads/vouchers/6a07814db2836-Screenshot_342.png b/assets/uploads/vouchers/6a07814db2836-Screenshot_342.png new file mode 100644 index 00000000..31da822f Binary files /dev/null and b/assets/uploads/vouchers/6a07814db2836-Screenshot_342.png differ diff --git a/assets/uploads/vouchers/6a07835ddd8ef-Screenshot_343.png b/assets/uploads/vouchers/6a07835ddd8ef-Screenshot_343.png new file mode 100644 index 00000000..4f554c51 Binary files /dev/null and b/assets/uploads/vouchers/6a07835ddd8ef-Screenshot_343.png differ diff --git a/assets/uploads/vouchers/6a0790f50c5e6-Captura de pantalla 2026-05-15 163159.png b/assets/uploads/vouchers/6a0790f50c5e6-Captura de pantalla 2026-05-15 163159.png new file mode 100644 index 00000000..a3f240a6 Binary files /dev/null and b/assets/uploads/vouchers/6a0790f50c5e6-Captura de pantalla 2026-05-15 163159.png differ diff --git a/assets/uploads/vouchers/6a07911f610fa-Captura de pantalla 2026-05-15 163252.png b/assets/uploads/vouchers/6a07911f610fa-Captura de pantalla 2026-05-15 163252.png new file mode 100644 index 00000000..bbb81d6d Binary files /dev/null and b/assets/uploads/vouchers/6a07911f610fa-Captura de pantalla 2026-05-15 163252.png differ diff --git a/assets/uploads/vouchers/6a0791cba4882-1787.png b/assets/uploads/vouchers/6a0791cba4882-1787.png new file mode 100644 index 00000000..0d96a3db Binary files /dev/null and b/assets/uploads/vouchers/6a0791cba4882-1787.png differ diff --git a/assets/uploads/vouchers/6a0792665505b-640.png b/assets/uploads/vouchers/6a0792665505b-640.png new file mode 100644 index 00000000..7b57580e Binary files /dev/null and b/assets/uploads/vouchers/6a0792665505b-640.png differ diff --git a/assets/uploads/vouchers/6a0793286d90e-700.png b/assets/uploads/vouchers/6a0793286d90e-700.png new file mode 100644 index 00000000..d8306155 Binary files /dev/null and b/assets/uploads/vouchers/6a0793286d90e-700.png differ diff --git a/assets/uploads/vouchers/6a0793e78c53d-448.png b/assets/uploads/vouchers/6a0793e78c53d-448.png new file mode 100644 index 00000000..79d8e757 Binary files /dev/null and b/assets/uploads/vouchers/6a0793e78c53d-448.png differ diff --git a/assets/uploads/vouchers/6a07949d343ea-648.png b/assets/uploads/vouchers/6a07949d343ea-648.png new file mode 100644 index 00000000..ca21cecf Binary files /dev/null and b/assets/uploads/vouchers/6a07949d343ea-648.png differ diff --git a/assets/uploads/vouchers/6a07951bbf9c0-947.png b/assets/uploads/vouchers/6a07951bbf9c0-947.png new file mode 100644 index 00000000..cd55cdb1 Binary files /dev/null and b/assets/uploads/vouchers/6a07951bbf9c0-947.png differ diff --git a/assets/uploads/vouchers/6a07a0832530c-Screenshot_344.png b/assets/uploads/vouchers/6a07a0832530c-Screenshot_344.png new file mode 100644 index 00000000..341f8b19 Binary files /dev/null and b/assets/uploads/vouchers/6a07a0832530c-Screenshot_344.png differ diff --git a/assets/uploads/vouchers/6a07aa4be8ee8-476.png b/assets/uploads/vouchers/6a07aa4be8ee8-476.png new file mode 100644 index 00000000..6ca6b0a9 Binary files /dev/null and b/assets/uploads/vouchers/6a07aa4be8ee8-476.png differ diff --git a/composer.json b/composer.json new file mode 100644 index 00000000..cd360a28 --- /dev/null +++ b/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "shuchkin/simplexlsxgen": "^1.5" + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 00000000..af224ca9 --- /dev/null +++ b/composer.lock @@ -0,0 +1,72 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "7b99e2d4bb14267c09672e3efc5786bd", + "packages": [ + { + "name": "shuchkin/simplexlsxgen", + "version": "1.5.17", + "source": { + "type": "git", + "url": "https://github.com/shuchkin/simplexlsxgen.git", + "reference": "162a4a9b929611d69dbd6f1a7f42af483a87b537" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/shuchkin/simplexlsxgen/zipball/162a4a9b929611d69dbd6f1a7f42af483a87b537", + "reference": "162a4a9b929611d69dbd6f1a7f42af483a87b537", + "shasum": "" + }, + "require": { + "ext-mbstring": "*", + "ext-zlib": "*", + "php": ">=5.4" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/SimpleXLSXGen.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Sergey Shuchkin (SMSPILOT)", + "email": "sergey.shuchkin@gmail.com", + "homepage": "https://shuchkin.ru/" + } + ], + "description": "Export data to Excel XLSx file. PHP XLSX generator.", + "homepage": "https://github.com/shuchkin/simplexlsxgen", + "keywords": [ + "backend", + "creator", + "excel", + "generator", + "php", + "writer", + "xlsx" + ], + "support": { + "issues": "https://github.com/shuchkin/simplexlsxgen/issues", + "source": "https://github.com/shuchkin/simplexlsxgen/tree/1.5.17" + }, + "time": "2026-05-03T13:04:04+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [], + "plugin-api-version": "2.3.0" +} diff --git a/download_shalom.php b/download_shalom.php index 6ec43387..f69d1fbc 100644 --- a/download_shalom.php +++ b/download_shalom.php @@ -5,6 +5,9 @@ if (!isset($_SESSION['user_id'])) { exit; } require_once 'db/config.php'; +require_once 'vendor/autoload.php'; + +use Shuchkin\SimpleXLSXGen; try { $pdo = db(); @@ -12,7 +15,7 @@ try { // Filtramos solo los pedidos que están en estado 'ROTULADO 📦' y son de la agencia 'SHALOM' $query = " - SELECT p.dni_cliente, p.celular, p.sede_envio, p.agencia + SELECT p.dni_cliente, p.celular, p.sede_envio, p.agencia, p.producto, p.cantidad FROM pedidos p WHERE p.estado = 'ROTULADO 📦' AND p.agencia LIKE '%SHALOM%' @@ -30,35 +33,23 @@ try { $stmt->execute(); $pedidos = $stmt->fetchAll(PDO::FETCH_ASSOC); - $filename = "masivo_shalom"; - if ($type === 'terrestre') $filename .= "_terrestre"; - if ($type === 'aereo') $filename .= "_aereo"; - $filename .= ".xls"; - - header('Content-Type: application/vnd.ms-excel; charset=utf-8'); - header('Content-Disposition: attachment; filename="' . $filename . '"'); - header('Pragma: no-cache'); - header('Expires: 0'); - - $output = ' - - '; - $output .= ''; - $output .= ''; - $output .= ''; - $output .= ''; - $output .= ''; - $output .= ''; - $output .= ''; - $output .= ''; - $output .= ''; - $output .= ''; - $output .= ''; - $output .= ''; - $output .= ''; + $data = []; + // Header + $data[] = [ + 'DESTINATARIO (DOC)', + 'TELF. DESTINATARIO', + 'CONTACTO (DOC)', + 'TELF. CONTACTO', + 'NRO GRR', + 'ORIGEN', + 'DESTINO', + 'MERCADERIA', + 'ALTO', + 'ANCHO', + 'LARGO', + 'PESO', + 'CANTIDAD' + ]; foreach ($pedidos as $pedido) { // Limpiar el DNI: solo números @@ -72,31 +63,52 @@ try { $celular = substr($celular, 2); } - $celular = htmlspecialchars($celular); - $destino_raw = str_ireplace('shalom:', '', $pedido['sede_envio'] ?? ''); - $parts = explode('/', $destino_raw); - $destino = trim(end($parts)); + + // Buscamos la última parte después del slash + $last_slash_pos = mb_strrpos($destino_raw, '/'); + if ($last_slash_pos !== false) { + $destino = mb_substr($destino_raw, $last_slash_pos + 1); + } else { + $destino = $destino_raw; + } + + // Solo quitamos UN espacio al inicio y UN espacio al final si existen, + // para respetar espacios dobles internos o intencionales. + if (str_starts_with($destino, ' ')) { + $destino = substr($destino, 1); + } + if (str_ends_with($destino, ' ')) { + $destino = substr($destino, 0, -1); + } + // Convertir a mayúsculas $destino = mb_strtoupper($destino, 'UTF-8'); - $destino = htmlspecialchars($destino); - $output .= ''; - $output .= ''; // Solo el número de DNI con formato texto - $output .= ''; // Teléfono con formato texto - $output .= ''; // Contacto vacío - $output .= ''; // Telf Contacto vacío - $output .= ''; // NRO GRR vacío - $output .= ''; // ORIGEN fijo - $output .= ''; // Destino - $output .= ''; + $data[] = [ + (string)$dni, + (string)$celular, + '', + '', + '', + 'AV MEXICO CO', + $destino, + 'PAQUETE XXS', // MERCADERIA + '0.1', // ALTO + '0.1', // ANCHO + '0.1', // LARGO + '0.1', // PESO + '1' // CANTIDAD + ]; } - $output .= ''; - $output .= '
DESTINATARIO (DOC)TELF. DESTINATARIOCONTACTO (DOC)TELF. CONTACTONRO GRRORIGENDESTINO
' . $dni . '' . $celular . 'AV MEXICO CO' . $destino . '
'; - $output .= ''; + $filename = "masivo_shalom"; + if ($type === 'terrestre') $filename .= "_terrestre"; + if ($type === 'aereo') $filename .= "_aereo"; + $filename .= "_" . date('Y-m-d') . ".xlsx"; - echo $output; + SimpleXLSXGen::fromArray($data)->downloadAs($filename); + exit; } catch (Exception $e) { header('HTTP/1.1 500 Internal Server Error'); diff --git a/vendor/autoload.php b/vendor/autoload.php new file mode 100644 index 00000000..355b4832 --- /dev/null +++ b/vendor/autoload.php @@ -0,0 +1,25 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Autoload; + +/** + * ClassLoader implements a PSR-0, PSR-4 and classmap class loader. + * + * $loader = new \Composer\Autoload\ClassLoader(); + * + * // register classes with namespaces + * $loader->add('Symfony\Component', __DIR__.'/component'); + * $loader->add('Symfony', __DIR__.'/framework'); + * + * // activate the autoloader + * $loader->register(); + * + * // to enable searching the include path (eg. for PEAR packages) + * $loader->setUseIncludePath(true); + * + * In this example, if you try to use a class in the Symfony\Component + * namespace or one of its children (Symfony\Component\Console for instance), + * the autoloader will first look for the class under the component/ + * directory, and it will then fallback to the framework/ directory if not + * found before giving up. + * + * This class is loosely based on the Symfony UniversalClassLoader. + * + * @author Fabien Potencier + * @author Jordi Boggiano + * @see https://www.php-fig.org/psr/psr-0/ + * @see https://www.php-fig.org/psr/psr-4/ + */ +class ClassLoader +{ + /** @var \Closure(string):void */ + private static $includeFile; + + /** @var ?string */ + private $vendorDir; + + // PSR-4 + /** + * @var array[] + * @psalm-var array> + */ + private $prefixLengthsPsr4 = array(); + /** + * @var array[] + * @psalm-var array> + */ + private $prefixDirsPsr4 = array(); + /** + * @var array[] + * @psalm-var array + */ + private $fallbackDirsPsr4 = array(); + + // PSR-0 + /** + * @var array[] + * @psalm-var array> + */ + private $prefixesPsr0 = array(); + /** + * @var array[] + * @psalm-var array + */ + private $fallbackDirsPsr0 = array(); + + /** @var bool */ + private $useIncludePath = false; + + /** + * @var string[] + * @psalm-var array + */ + private $classMap = array(); + + /** @var bool */ + private $classMapAuthoritative = false; + + /** + * @var bool[] + * @psalm-var array + */ + private $missingClasses = array(); + + /** @var ?string */ + private $apcuPrefix; + + /** + * @var self[] + */ + private static $registeredLoaders = array(); + + /** + * @param ?string $vendorDir + */ + public function __construct($vendorDir = null) + { + $this->vendorDir = $vendorDir; + self::initializeIncludeClosure(); + } + + /** + * @return string[] + */ + public function getPrefixes() + { + if (!empty($this->prefixesPsr0)) { + return call_user_func_array('array_merge', array_values($this->prefixesPsr0)); + } + + return array(); + } + + /** + * @return array[] + * @psalm-return array> + */ + public function getPrefixesPsr4() + { + return $this->prefixDirsPsr4; + } + + /** + * @return array[] + * @psalm-return array + */ + public function getFallbackDirs() + { + return $this->fallbackDirsPsr0; + } + + /** + * @return array[] + * @psalm-return array + */ + public function getFallbackDirsPsr4() + { + return $this->fallbackDirsPsr4; + } + + /** + * @return string[] Array of classname => path + * @psalm-return array + */ + public function getClassMap() + { + return $this->classMap; + } + + /** + * @param string[] $classMap Class to filename map + * @psalm-param array $classMap + * + * @return void + */ + public function addClassMap(array $classMap) + { + if ($this->classMap) { + $this->classMap = array_merge($this->classMap, $classMap); + } else { + $this->classMap = $classMap; + } + } + + /** + * Registers a set of PSR-0 directories for a given prefix, either + * appending or prepending to the ones previously set for this prefix. + * + * @param string $prefix The prefix + * @param string[]|string $paths The PSR-0 root directories + * @param bool $prepend Whether to prepend the directories + * + * @return void + */ + public function add($prefix, $paths, $prepend = false) + { + if (!$prefix) { + if ($prepend) { + $this->fallbackDirsPsr0 = array_merge( + (array) $paths, + $this->fallbackDirsPsr0 + ); + } else { + $this->fallbackDirsPsr0 = array_merge( + $this->fallbackDirsPsr0, + (array) $paths + ); + } + + return; + } + + $first = $prefix[0]; + if (!isset($this->prefixesPsr0[$first][$prefix])) { + $this->prefixesPsr0[$first][$prefix] = (array) $paths; + + return; + } + if ($prepend) { + $this->prefixesPsr0[$first][$prefix] = array_merge( + (array) $paths, + $this->prefixesPsr0[$first][$prefix] + ); + } else { + $this->prefixesPsr0[$first][$prefix] = array_merge( + $this->prefixesPsr0[$first][$prefix], + (array) $paths + ); + } + } + + /** + * Registers a set of PSR-4 directories for a given namespace, either + * appending or prepending to the ones previously set for this namespace. + * + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param string[]|string $paths The PSR-4 base directories + * @param bool $prepend Whether to prepend the directories + * + * @throws \InvalidArgumentException + * + * @return void + */ + public function addPsr4($prefix, $paths, $prepend = false) + { + if (!$prefix) { + // Register directories for the root namespace. + if ($prepend) { + $this->fallbackDirsPsr4 = array_merge( + (array) $paths, + $this->fallbackDirsPsr4 + ); + } else { + $this->fallbackDirsPsr4 = array_merge( + $this->fallbackDirsPsr4, + (array) $paths + ); + } + } elseif (!isset($this->prefixDirsPsr4[$prefix])) { + // Register directories for a new namespace. + $length = strlen($prefix); + if ('\\' !== $prefix[$length - 1]) { + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); + } + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; + $this->prefixDirsPsr4[$prefix] = (array) $paths; + } elseif ($prepend) { + // Prepend directories for an already registered namespace. + $this->prefixDirsPsr4[$prefix] = array_merge( + (array) $paths, + $this->prefixDirsPsr4[$prefix] + ); + } else { + // Append directories for an already registered namespace. + $this->prefixDirsPsr4[$prefix] = array_merge( + $this->prefixDirsPsr4[$prefix], + (array) $paths + ); + } + } + + /** + * Registers a set of PSR-0 directories for a given prefix, + * replacing any others previously set for this prefix. + * + * @param string $prefix The prefix + * @param string[]|string $paths The PSR-0 base directories + * + * @return void + */ + public function set($prefix, $paths) + { + if (!$prefix) { + $this->fallbackDirsPsr0 = (array) $paths; + } else { + $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; + } + } + + /** + * Registers a set of PSR-4 directories for a given namespace, + * replacing any others previously set for this namespace. + * + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param string[]|string $paths The PSR-4 base directories + * + * @throws \InvalidArgumentException + * + * @return void + */ + public function setPsr4($prefix, $paths) + { + if (!$prefix) { + $this->fallbackDirsPsr4 = (array) $paths; + } else { + $length = strlen($prefix); + if ('\\' !== $prefix[$length - 1]) { + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); + } + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; + $this->prefixDirsPsr4[$prefix] = (array) $paths; + } + } + + /** + * Turns on searching the include path for class files. + * + * @param bool $useIncludePath + * + * @return void + */ + public function setUseIncludePath($useIncludePath) + { + $this->useIncludePath = $useIncludePath; + } + + /** + * Can be used to check if the autoloader uses the include path to check + * for classes. + * + * @return bool + */ + public function getUseIncludePath() + { + return $this->useIncludePath; + } + + /** + * Turns off searching the prefix and fallback directories for classes + * that have not been registered with the class map. + * + * @param bool $classMapAuthoritative + * + * @return void + */ + public function setClassMapAuthoritative($classMapAuthoritative) + { + $this->classMapAuthoritative = $classMapAuthoritative; + } + + /** + * Should class lookup fail if not found in the current class map? + * + * @return bool + */ + public function isClassMapAuthoritative() + { + return $this->classMapAuthoritative; + } + + /** + * APCu prefix to use to cache found/not-found classes, if the extension is enabled. + * + * @param string|null $apcuPrefix + * + * @return void + */ + public function setApcuPrefix($apcuPrefix) + { + $this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null; + } + + /** + * The APCu prefix in use, or null if APCu caching is not enabled. + * + * @return string|null + */ + public function getApcuPrefix() + { + return $this->apcuPrefix; + } + + /** + * Registers this instance as an autoloader. + * + * @param bool $prepend Whether to prepend the autoloader or not + * + * @return void + */ + public function register($prepend = false) + { + spl_autoload_register(array($this, 'loadClass'), true, $prepend); + + if (null === $this->vendorDir) { + return; + } + + if ($prepend) { + self::$registeredLoaders = array($this->vendorDir => $this) + self::$registeredLoaders; + } else { + unset(self::$registeredLoaders[$this->vendorDir]); + self::$registeredLoaders[$this->vendorDir] = $this; + } + } + + /** + * Unregisters this instance as an autoloader. + * + * @return void + */ + public function unregister() + { + spl_autoload_unregister(array($this, 'loadClass')); + + if (null !== $this->vendorDir) { + unset(self::$registeredLoaders[$this->vendorDir]); + } + } + + /** + * Loads the given class or interface. + * + * @param string $class The name of the class + * @return true|null True if loaded, null otherwise + */ + public function loadClass($class) + { + if ($file = $this->findFile($class)) { + $includeFile = self::$includeFile; + $includeFile($file); + + return true; + } + + return null; + } + + /** + * Finds the path to the file where the class is defined. + * + * @param string $class The name of the class + * + * @return string|false The path if found, false otherwise + */ + public function findFile($class) + { + // class map lookup + if (isset($this->classMap[$class])) { + return $this->classMap[$class]; + } + if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) { + return false; + } + if (null !== $this->apcuPrefix) { + $file = apcu_fetch($this->apcuPrefix.$class, $hit); + if ($hit) { + return $file; + } + } + + $file = $this->findFileWithExtension($class, '.php'); + + // Search for Hack files if we are running on HHVM + if (false === $file && defined('HHVM_VERSION')) { + $file = $this->findFileWithExtension($class, '.hh'); + } + + if (null !== $this->apcuPrefix) { + apcu_add($this->apcuPrefix.$class, $file); + } + + if (false === $file) { + // Remember that this class does not exist. + $this->missingClasses[$class] = true; + } + + return $file; + } + + /** + * Returns the currently registered loaders indexed by their corresponding vendor directories. + * + * @return self[] + */ + public static function getRegisteredLoaders() + { + return self::$registeredLoaders; + } + + /** + * @param string $class + * @param string $ext + * @return string|false + */ + private function findFileWithExtension($class, $ext) + { + // PSR-4 lookup + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; + + $first = $class[0]; + if (isset($this->prefixLengthsPsr4[$first])) { + $subPath = $class; + while (false !== $lastPos = strrpos($subPath, '\\')) { + $subPath = substr($subPath, 0, $lastPos); + $search = $subPath . '\\'; + if (isset($this->prefixDirsPsr4[$search])) { + $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1); + foreach ($this->prefixDirsPsr4[$search] as $dir) { + if (file_exists($file = $dir . $pathEnd)) { + return $file; + } + } + } + } + } + + // PSR-4 fallback dirs + foreach ($this->fallbackDirsPsr4 as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { + return $file; + } + } + + // PSR-0 lookup + if (false !== $pos = strrpos($class, '\\')) { + // namespaced class name + $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) + . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); + } else { + // PEAR-like class name + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; + } + + if (isset($this->prefixesPsr0[$first])) { + foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { + if (0 === strpos($class, $prefix)) { + foreach ($dirs as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + return $file; + } + } + } + } + } + + // PSR-0 fallback dirs + foreach ($this->fallbackDirsPsr0 as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + return $file; + } + } + + // PSR-0 include paths. + if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { + return $file; + } + + return false; + } + + /** + * @return void + */ + private static function initializeIncludeClosure() + { + if (self::$includeFile !== null) { + return; + } + + /** + * Scope isolated include. + * + * Prevents access to $this/self from included files. + * + * @param string $file + * @return void + */ + self::$includeFile = \Closure::bind(static function($file) { + include $file; + }, null, null); + } +} diff --git a/vendor/composer/InstalledVersions.php b/vendor/composer/InstalledVersions.php new file mode 100644 index 00000000..51e734a7 --- /dev/null +++ b/vendor/composer/InstalledVersions.php @@ -0,0 +1,359 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer; + +use Composer\Autoload\ClassLoader; +use Composer\Semver\VersionParser; + +/** + * This class is copied in every Composer installed project and available to all + * + * See also https://getcomposer.org/doc/07-runtime.md#installed-versions + * + * To require its presence, you can require `composer-runtime-api ^2.0` + * + * @final + */ +class InstalledVersions +{ + /** + * @var mixed[]|null + * @psalm-var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array}|array{}|null + */ + private static $installed; + + /** + * @var bool|null + */ + private static $canGetVendors; + + /** + * @var array[] + * @psalm-var array}> + */ + private static $installedByVendor = array(); + + /** + * Returns a list of all package names which are present, either by being installed, replaced or provided + * + * @return string[] + * @psalm-return list + */ + public static function getInstalledPackages() + { + $packages = array(); + foreach (self::getInstalled() as $installed) { + $packages[] = array_keys($installed['versions']); + } + + if (1 === \count($packages)) { + return $packages[0]; + } + + return array_keys(array_flip(\call_user_func_array('array_merge', $packages))); + } + + /** + * Returns a list of all package names with a specific type e.g. 'library' + * + * @param string $type + * @return string[] + * @psalm-return list + */ + public static function getInstalledPackagesByType($type) + { + $packagesByType = array(); + + foreach (self::getInstalled() as $installed) { + foreach ($installed['versions'] as $name => $package) { + if (isset($package['type']) && $package['type'] === $type) { + $packagesByType[] = $name; + } + } + } + + return $packagesByType; + } + + /** + * Checks whether the given package is installed + * + * This also returns true if the package name is provided or replaced by another package + * + * @param string $packageName + * @param bool $includeDevRequirements + * @return bool + */ + public static function isInstalled($packageName, $includeDevRequirements = true) + { + foreach (self::getInstalled() as $installed) { + if (isset($installed['versions'][$packageName])) { + return $includeDevRequirements || !isset($installed['versions'][$packageName]['dev_requirement']) || $installed['versions'][$packageName]['dev_requirement'] === false; + } + } + + return false; + } + + /** + * Checks whether the given package satisfies a version constraint + * + * e.g. If you want to know whether version 2.3+ of package foo/bar is installed, you would call: + * + * Composer\InstalledVersions::satisfies(new VersionParser, 'foo/bar', '^2.3') + * + * @param VersionParser $parser Install composer/semver to have access to this class and functionality + * @param string $packageName + * @param string|null $constraint A version constraint to check for, if you pass one you have to make sure composer/semver is required by your package + * @return bool + */ + public static function satisfies(VersionParser $parser, $packageName, $constraint) + { + $constraint = $parser->parseConstraints((string) $constraint); + $provided = $parser->parseConstraints(self::getVersionRanges($packageName)); + + return $provided->matches($constraint); + } + + /** + * Returns a version constraint representing all the range(s) which are installed for a given package + * + * It is easier to use this via isInstalled() with the $constraint argument if you need to check + * whether a given version of a package is installed, and not just whether it exists + * + * @param string $packageName + * @return string Version constraint usable with composer/semver + */ + public static function getVersionRanges($packageName) + { + foreach (self::getInstalled() as $installed) { + if (!isset($installed['versions'][$packageName])) { + continue; + } + + $ranges = array(); + if (isset($installed['versions'][$packageName]['pretty_version'])) { + $ranges[] = $installed['versions'][$packageName]['pretty_version']; + } + if (array_key_exists('aliases', $installed['versions'][$packageName])) { + $ranges = array_merge($ranges, $installed['versions'][$packageName]['aliases']); + } + if (array_key_exists('replaced', $installed['versions'][$packageName])) { + $ranges = array_merge($ranges, $installed['versions'][$packageName]['replaced']); + } + if (array_key_exists('provided', $installed['versions'][$packageName])) { + $ranges = array_merge($ranges, $installed['versions'][$packageName]['provided']); + } + + return implode(' || ', $ranges); + } + + throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); + } + + /** + * @param string $packageName + * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present + */ + public static function getVersion($packageName) + { + foreach (self::getInstalled() as $installed) { + if (!isset($installed['versions'][$packageName])) { + continue; + } + + if (!isset($installed['versions'][$packageName]['version'])) { + return null; + } + + return $installed['versions'][$packageName]['version']; + } + + throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); + } + + /** + * @param string $packageName + * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present + */ + public static function getPrettyVersion($packageName) + { + foreach (self::getInstalled() as $installed) { + if (!isset($installed['versions'][$packageName])) { + continue; + } + + if (!isset($installed['versions'][$packageName]['pretty_version'])) { + return null; + } + + return $installed['versions'][$packageName]['pretty_version']; + } + + throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); + } + + /** + * @param string $packageName + * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as reference + */ + public static function getReference($packageName) + { + foreach (self::getInstalled() as $installed) { + if (!isset($installed['versions'][$packageName])) { + continue; + } + + if (!isset($installed['versions'][$packageName]['reference'])) { + return null; + } + + return $installed['versions'][$packageName]['reference']; + } + + throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); + } + + /** + * @param string $packageName + * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as install path. Packages of type metapackages also have a null install path. + */ + public static function getInstallPath($packageName) + { + foreach (self::getInstalled() as $installed) { + if (!isset($installed['versions'][$packageName])) { + continue; + } + + return isset($installed['versions'][$packageName]['install_path']) ? $installed['versions'][$packageName]['install_path'] : null; + } + + throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); + } + + /** + * @return array + * @psalm-return array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool} + */ + public static function getRootPackage() + { + $installed = self::getInstalled(); + + return $installed[0]['root']; + } + + /** + * Returns the raw installed.php data for custom implementations + * + * @deprecated Use getAllRawData() instead which returns all datasets for all autoloaders present in the process. getRawData only returns the first dataset loaded, which may not be what you expect. + * @return array[] + * @psalm-return array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array} + */ + public static function getRawData() + { + @trigger_error('getRawData only returns the first dataset loaded, which may not be what you expect. Use getAllRawData() instead which returns all datasets for all autoloaders present in the process.', E_USER_DEPRECATED); + + if (null === self::$installed) { + // only require the installed.php file if this file is loaded from its dumped location, + // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937 + if (substr(__DIR__, -8, 1) !== 'C') { + self::$installed = include __DIR__ . '/installed.php'; + } else { + self::$installed = array(); + } + } + + return self::$installed; + } + + /** + * Returns the raw data of all installed.php which are currently loaded for custom implementations + * + * @return array[] + * @psalm-return list}> + */ + public static function getAllRawData() + { + return self::getInstalled(); + } + + /** + * Lets you reload the static array from another file + * + * This is only useful for complex integrations in which a project needs to use + * this class but then also needs to execute another project's autoloader in process, + * and wants to ensure both projects have access to their version of installed.php. + * + * A typical case would be PHPUnit, where it would need to make sure it reads all + * the data it needs from this class, then call reload() with + * `require $CWD/vendor/composer/installed.php` (or similar) as input to make sure + * the project in which it runs can then also use this class safely, without + * interference between PHPUnit's dependencies and the project's dependencies. + * + * @param array[] $data A vendor/composer/installed.php data set + * @return void + * + * @psalm-param array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array} $data + */ + public static function reload($data) + { + self::$installed = $data; + self::$installedByVendor = array(); + } + + /** + * @return array[] + * @psalm-return list}> + */ + private static function getInstalled() + { + if (null === self::$canGetVendors) { + self::$canGetVendors = method_exists('Composer\Autoload\ClassLoader', 'getRegisteredLoaders'); + } + + $installed = array(); + + if (self::$canGetVendors) { + foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) { + if (isset(self::$installedByVendor[$vendorDir])) { + $installed[] = self::$installedByVendor[$vendorDir]; + } elseif (is_file($vendorDir.'/composer/installed.php')) { + /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array} $required */ + $required = require $vendorDir.'/composer/installed.php'; + $installed[] = self::$installedByVendor[$vendorDir] = $required; + if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) { + self::$installed = $installed[count($installed) - 1]; + } + } + } + } + + if (null === self::$installed) { + // only require the installed.php file if this file is loaded from its dumped location, + // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937 + if (substr(__DIR__, -8, 1) !== 'C') { + /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array} $required */ + $required = require __DIR__ . '/installed.php'; + self::$installed = $required; + } else { + self::$installed = array(); + } + } + + if (self::$installed !== array()) { + $installed[] = self::$installed; + } + + return $installed; + } +} diff --git a/vendor/composer/LICENSE b/vendor/composer/LICENSE new file mode 100644 index 00000000..62ecfd8d --- /dev/null +++ b/vendor/composer/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) Nils Adermann, Jordi Boggiano + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php new file mode 100644 index 00000000..c1502d1e --- /dev/null +++ b/vendor/composer/autoload_classmap.php @@ -0,0 +1,11 @@ + $vendorDir . '/composer/InstalledVersions.php', + 'Shuchkin\\SimpleXLSXGen' => $vendorDir . '/shuchkin/simplexlsxgen/src/SimpleXLSXGen.php', +); diff --git a/vendor/composer/autoload_namespaces.php b/vendor/composer/autoload_namespaces.php new file mode 100644 index 00000000..15a2ff3a --- /dev/null +++ b/vendor/composer/autoload_namespaces.php @@ -0,0 +1,9 @@ +register(true); + + return $loader; + } +} diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php new file mode 100644 index 00000000..e94166a6 --- /dev/null +++ b/vendor/composer/autoload_static.php @@ -0,0 +1,21 @@ + __DIR__ . '/..' . '/composer/InstalledVersions.php', + 'Shuchkin\\SimpleXLSXGen' => __DIR__ . '/..' . '/shuchkin/simplexlsxgen/src/SimpleXLSXGen.php', + ); + + public static function getInitializer(ClassLoader $loader) + { + return \Closure::bind(function () use ($loader) { + $loader->classMap = ComposerStaticInit7443bc322605554a2a2e26076e20764b::$classMap; + + }, null, ClassLoader::class); + } +} diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json new file mode 100644 index 00000000..e56e0410 --- /dev/null +++ b/vendor/composer/installed.json @@ -0,0 +1,62 @@ +{ + "packages": [ + { + "name": "shuchkin/simplexlsxgen", + "version": "1.5.17", + "version_normalized": "1.5.17.0", + "source": { + "type": "git", + "url": "https://github.com/shuchkin/simplexlsxgen.git", + "reference": "162a4a9b929611d69dbd6f1a7f42af483a87b537" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/shuchkin/simplexlsxgen/zipball/162a4a9b929611d69dbd6f1a7f42af483a87b537", + "reference": "162a4a9b929611d69dbd6f1a7f42af483a87b537", + "shasum": "" + }, + "require": { + "ext-mbstring": "*", + "ext-zlib": "*", + "php": ">=5.4" + }, + "time": "2026-05-03T13:04:04+00:00", + "type": "library", + "installation-source": "dist", + "autoload": { + "classmap": [ + "src/SimpleXLSXGen.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Sergey Shuchkin (SMSPILOT)", + "email": "sergey.shuchkin@gmail.com", + "homepage": "https://shuchkin.ru/" + } + ], + "description": "Export data to Excel XLSx file. PHP XLSX generator.", + "homepage": "https://github.com/shuchkin/simplexlsxgen", + "keywords": [ + "backend", + "creator", + "excel", + "generator", + "php", + "writer", + "xlsx" + ], + "support": { + "issues": "https://github.com/shuchkin/simplexlsxgen/issues", + "source": "https://github.com/shuchkin/simplexlsxgen/tree/1.5.17" + }, + "install-path": "../shuchkin/simplexlsxgen" + } + ], + "dev": true, + "dev-package-names": [] +} diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php new file mode 100644 index 00000000..dbe6b174 --- /dev/null +++ b/vendor/composer/installed.php @@ -0,0 +1,32 @@ + array( + 'name' => '__root__', + 'pretty_version' => 'dev-master', + 'version' => 'dev-master', + 'reference' => 'a897557f9b2c5450ce9f867e5945bb040d282791', + 'type' => 'library', + 'install_path' => __DIR__ . '/../../', + 'aliases' => array(), + 'dev' => true, + ), + 'versions' => array( + '__root__' => array( + 'pretty_version' => 'dev-master', + 'version' => 'dev-master', + 'reference' => 'a897557f9b2c5450ce9f867e5945bb040d282791', + 'type' => 'library', + 'install_path' => __DIR__ . '/../../', + 'aliases' => array(), + 'dev_requirement' => false, + ), + 'shuchkin/simplexlsxgen' => array( + 'pretty_version' => '1.5.17', + 'version' => '1.5.17.0', + 'reference' => '162a4a9b929611d69dbd6f1a7f42af483a87b537', + 'type' => 'library', + 'install_path' => __DIR__ . '/../shuchkin/simplexlsxgen', + 'aliases' => array(), + 'dev_requirement' => false, + ), + ), +); diff --git a/vendor/composer/platform_check.php b/vendor/composer/platform_check.php new file mode 100644 index 00000000..590554b4 --- /dev/null +++ b/vendor/composer/platform_check.php @@ -0,0 +1,26 @@ += 50400)) { + $issues[] = 'Your Composer dependencies require a PHP version ">= 5.4.0". You are running ' . PHP_VERSION . '.'; +} + +if ($issues) { + if (!headers_sent()) { + header('HTTP/1.1 500 Internal Server Error'); + } + if (!ini_get('display_errors')) { + if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') { + fwrite(STDERR, 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . implode(PHP_EOL, $issues) . PHP_EOL.PHP_EOL); + } elseif (!headers_sent()) { + echo 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_EOL, $issues)) . PHP_EOL.PHP_EOL; + } + } + trigger_error( + 'Composer detected issues in your platform: ' . implode(' ', $issues), + E_USER_ERROR + ); +} diff --git a/vendor/shuchkin/simplexlsxgen/CHANGELOG.md b/vendor/shuchkin/simplexlsxgen/CHANGELOG.md new file mode 100644 index 00000000..c17b0785 --- /dev/null +++ b/vendor/shuchkin/simplexlsxgen/CHANGELOG.md @@ -0,0 +1,219 @@ +# Changelog + +# 1.5.17 (2026-05-03) +* datetime detection priority, thx [Ced](https://github.com/cauzanne) [#176](https://github.com/shuchkin/simplexlsxgen/issues/176) + +# 1.5.16 (2026-04-22) +* setColWidth accepts column letters and ranges, e.g. setColWidth('A', 35) or setColWidth('A:C', 15), thx [Albert](https://github.com/lazaroagomez) [#171](https://github.com/shuchkin/simplexlsxgen/issues/171) + +# 1.5.15 (2026-03-12) +* fixed formatted numbers, thx [Roland](https://github.com/mrextreme) [#174](https://github.com/shuchkin/simplexlsxgen/issues/174#issuecomment-4045694443) + +# 1.5.14 (2026-03-11) +* real numbers as General + +# 1.5.13 (2026-03-09) +* long numbers right alignment, thx [ErikLtz](https://github.com/ErikLtz) [#173](https://github.com/shuchkin/simplexlsxgen/issues/173) + +# 1.5.12 (2025-10-24) +* added tag ``````, thx [wawaclem](https://github.com/wawaclem) + +# 1.5.11 (2025-08-09) +* added ::rawArray() + + +# 1.5.10 (2025-07-08) +* added cell comments + +# 1.4.15 (2025-05-28) +* added custom dateformats [via nf= work](https://github.com/shuchkin/simplexlsxgen/pull/166), thx [scravy](https://github.com/scravy) + +# 1.4.14 (2025-03-07) +* fixed [empty cells and selection](https://github.com/shuchkin/simplexlsxgen/issues/164) issue, thx [denisboccardo](https://github.com/denisboccardo) + +# 1.4.13 (2024-10-13) +* fixed [formula and style](https://github.com/shuchkin/simplexlsxgen/issues/156) issue, when skpped `v="value"` in formula tag + +## 1.4.12 (2024-07-28) +* tag `````` for styled raw values + +## 1.4.11 (2024-02-07) +* hyperlinks to local files +* num2name static now + +## 1.4.10 (2023-12-31) +* added SimpleXLSXGen::create($title = null) to create empty book with title +* added SimpleXLSXGen::save to save xlsx in current folder as `title`.xslx or `curdate`.xlsx +* SimpleXLSXGen::esc and SimpleXLSXGen::date2excel static now +* added examples SimpleXLSXGen::create, SimpleXSLXGen::raw, SimpleXLSXGen:save in README.md +* fixed [fpassthru disabled issue](https://github.com/shuchkin/simplexlsxgen/issues/116) +* fixed empty book, A1 empty now, text _No data_ removed +* thx [Javier](https://github.com/xaviermdq) + +## 1.3.20 (2023-12-12) +* force little endian numbers in zip headers + +## 1.3.18 (2023-12-02) +* simple linebreaks + +## 1.3.17 (2023-10-02) +* fixed [issue 128](https://github.com/shuchkin/simplexlsxgen/issues/128) date2excel type cast + +## 1.3.16 (2023-09-12) +* preserve leading or traling spaces + +## 1.3.15 (2023-04-19) +* added meta: setTitle, setSubject, setAuthor, setCompany, setManager, setKeywords, setDescription, setCategory, setApplication, setLastModifiedBy. Thx [Oleg Kosarev](https://github.com/DevOlegKosarev) + +## 1.3.14 (2023-04-18) +* fixed "This action doesn't work on multiple selection" error + +## 1.3.13 (2023-04-11) +* ```$xlsx->rightToLeft()``` - RTL mode. Column A is on the far right, Column B is one column left of Column A, and so on. Also, information in cells is displayed in the Right to Left format. + +## 1.3.12 (2023-03-31) +* `````` - font size in cells, thx [Andrew Robinson](https://github.com/mrjemson) + +## 1.3.11 (2023-03-28) +* freezePanes( corner_cell ) - freezePanes to keep an area of a worksheet visible while you scroll, corner_cell is not included, thx [Javier](https://github.com/xaviermdq) + +## 1.3.10 (2022-12-14) +* added borders `````` see colored [examples](https://github.com/shuchkin/simplexlsxgen#formatting) +* added formulas ```SUM(B1:B10)``` see [examples](https://github.com/shuchkin/simplexlsxgen#data-types) +* added internal links ```Go to page 2``` +* added custom number formats `````` +* added 3 currencies ```$data = [ ['$100.23', '2000.00 €', '1200.30 ₽'] ];``` + +## 1.2.16 (2022-08-12) +* added `autoFilter( $range )` +```php +$xlsx->autoFilter('A2:B10'); +``` +* fixed `0%` bug + +## 1.2.15 (2022-07-05) +* added wrap words in long strings `long long line` + +## 1.2.14 (2022-06-10) +* added example [JS array to Excel (AJAX)](https://github.com/shuchkin/simplexlsxgen#js-array-to-excel-ajax) + +## 1.2.13 (2022-06-01) +* setColWidth(num_col_started_1, size_in_chars) - set column width + +## 1.2.12 (2022-05-17) +* Vertical align (tags top,middle,bottom) `12345` + +## 1.2.11 (2022-05-01) +* Row height `` + + +## 1.2.10 (2022-04-24) +* Added colors ``, thx [mrjemson](https://github.com/mrjemson) + +## 1.1.12 (2022-03-15) +* Added `$xlsx->mergeCells('A1:C1')` + +## 1.1.11 (2022-02-05) +* sheet name maximum length is 31 chars, mb_substr used now +* license fixed + +## 1.1.10 (2022-02-05) +* namespace added, use Shuchkin\SimpleXLSXGen + +## 1.0.23 (2022-02-01) +* fixed dates if year < 1900 and time only cells, thx [fapth](https://github.com/shuchkin/simplexlsxgen/issues/51) + +## 1.0.22 (2021-10-29) +* Escape \x00 and \x0B (vertical tab) + +## 1.0.21 (2021-09-03) +* Fixed saveAs / downloadAs / etc methods more than once + +## 1.0.20 (2021-07-29) +* Fixed sheet names duplicates (Page, Page (1), Page (2)...) + +## 1.0.19 (2021-07-28) +* Fixed sheet names duplicates + +## 1.0.18 (2021-07-28) +* Fixed email regex + +## 1.0.17 (2021-07-28) +* Fixed " and & in sheets names + +## 1.0.16 (2021-07-01) +* Fixed "&" in hyperlinks + +## 1.0.15 (2021-06-22) +* Fixed *mailto* hyperlinks detection + +## 1.0.14 (2021-06-08) +* Added *mailto* hyperlinks support (thx Howard Martin) +```php +SimpleXLSXGen::fromArray([ + ['Mailto hyperlink', 'Please email me'] +])->saveAs('test.xlsx'); +``` +## 1.0.13 (2021-05-29) +* Fixed hyperlinks in several sheets +* Added [Opencollective donation link](https://opencollective.com/simplexlsx) + +## 1.0.12 (2021-05-19) +* Fixed hyperlink regex + +## 1.0.11 (2021-05-14) +* Fixed 0.00% format, thx [marcrobledo](https://github.com/shuchkin/simplexlsxgen/pull/34), more examples in README.md + +## 1.0.10 (2021-05-03) +Stable release + +* Added hyperlinks and minimal formatting + +## 0.9.25 (2021-02-26) +* Added PHP Datetime object values in a cells + +## 0.9.24 (2021-02-26) +* Percent support + + +## 0.9.23 (2021-01-25) +* Fix local floats in XML + +## 0.9.22 (2020-11-04) +* Added multiple sheets support, thx [Savino59](https://github.com/Savino59), class ready for extend now + +## 0.9.21 (2020-10-17) +* Updated images + +## 0.9.20 (2020-10-04) +* Disable type detection if string started with chr(0) + +## 0.9.19 (2020-08-23) +* Numbers like SKU right aligned now + +## 0.9.18 (2020-08-22) +* Fixed fast shared strings index + +## 0.9.17 (2020-08-21) +* Fixed real numbers in 123.45 format detection, fast shared strings index (thx fredriksundin) + +## 0.9.16 (2020-07-29) +* Fixed time detection in HH:MM:SS format + +## 0.9.15 (2020-07-14) +* Escape of shared strings for special chars in cells [#1](https://github.com/shuchkin/simplexlsxgen/issues/1) + +## 0.9.14 (2020-05-31) +* Fixed num2name A-Z,AA-AZ column names, thx Ertan Yusufoglu + +## 0.9.13 (2020-05-21) +* If string more 160 chars, save as inlineStr + +## 0.9.12 (2020-05-21) +* Readme fixed + +## 0.9.11 (2020-05-21) +* Removed XML unimportant attributes + +## 0.9.10 (2020-05-20) +* Initial release \ No newline at end of file diff --git a/vendor/shuchkin/simplexlsxgen/README.md b/vendor/shuchkin/simplexlsxgen/README.md new file mode 100644 index 00000000..8a512bb8 --- /dev/null +++ b/vendor/shuchkin/simplexlsxgen/README.md @@ -0,0 +1,261 @@ +# SimpleXLSXGen +[](https://github.com/shuchkin/simplexlsxgen/blob/master/license.md) [](https://github.com/shuchkin/simplexlsxgen/stargazers) [](https://github.com/shuchkin/simplexlsxgen/network) [](https://github.com/shuchkin/simplexlsxgen/issues) + +Export data to Excel XLSX file. PHP XLSX generator. No external tools and libraries. +- XLSX reader [here](https://github.com/shuchkin/simplexlsx) +- XLS reader [here](https://github.com/shuchkin/simplexls) +- CSV reader/writer [here](https://github.com/shuchkin/simplecsv) + +**Sergey Shuchkin** 2020-2025
+ +*Hey, bro, please ★ the package for my motivation :) and [donate](https://opencollective.com/simplexlsx) for more motivation!* + +## Basic Usage +```php +$books = [ + ['ISBN', 'title', 'author', 'publisher', 'ctry' ], + [618260307, 'The Hobbit', 'J. R. R. Tolkien', 'Houghton Mifflin', 'USA'], + [908606664, 'Slinky Malinki', 'Lynley Dodd', 'Mallinson Rendel', 'NZ'] +]; +$xlsx = Shuchkin\SimpleXLSXGen::fromArray( $books ); +$xlsx->saveAs('books.xlsx'); // or downloadAs('books.xlsx') or $xlsx_content = (string) $xlsx +``` +![XLSX screenshot](books.png) + +## Installation +The recommended way to install this library is [through Composer](https://getcomposer.org). +[New to Composer?](https://getcomposer.org/doc/00-intro.md) + +This will install the latest supported version: +```bash +$ composer require shuchkin/simplexlsxgen +``` +or download class [here](https://github.com/shuchkin/simplexlsxgen/blob/master/src/SimpleXLSXGen.php) + +## Examples +Use UTF-8 encoded strings. +### Data types +```php +$data = [ + ['Integer', 123], + ['Float', 12.35], + ['Percent', '12%'], + ['Currency $', '$500.67'], + ['Currency €', '200 €'], + ['Currency ₽', '1200.30 ₽'], + ['Currency (other)', ''], + ['Currency Float (other)', ''], + ['Datetime', '2020-05-20 02:38:00'], + ['Date', '2020-05-20'], + ['Time', '02:38:00'], + ['Datetime PHP', new DateTime('2021-02-06 21:07:00')], + ['String', 'Very long UTF-8 string in autoresized column'], + ['Formula', 'SUM(B1:B2)'], + ['Hyperlink', 'https://github.com/shuchkin/simplexlsxgen'], + ['Hyperlink + Anchor', 'SimpleXLSXGen'], + ['Internal link', 'Go to second page'], + ['RAW string', "\0" . '2020-10-04 16:02:00'], + ['Formatted RAW string', '2024-07-28 16:02:00'], +]; +SimpleXLSXGen::fromArray($data)->saveAs('datatypes.xlsx'); +``` +![XLSX screenshot](datatypes.png) + +### Formatting +```php +$data = [ + ['Normal', '12345.67'], + ['Bold', '12345.67'], + ['Italic', '12345.67'], + ['Underline', '12345.67'], + ['Strike', '12345.67'], + ['Bold + Italic', '12345.67'], + ['Hyperlink', 'https://github.com/shuchkin/simplexlsxgen'], + ['Italic + Hyperlink + Anchor', 'SimpleXLSXGen'], + ['Green', ''], + ['Bold Red Text', ''], + ['Size 32 Font', ''], + ['Blue Text and Yellow Fill', ''], + ['Border color', ''], + ['Border style',''], + ['Border sides', ''], + ['Left', '12345.67'], + ['Center', '
12345.67
'], + ['Right', 'Right Text'], + ['Center + Bold', '
Name
'], + ['Row height', ''], + ['Top', ''], + ['Middle + Center', ''], + ['Bottom + Right', ''], + ['
MERGE CELLS MERGE CELLS MERGE CELLS MERGE CELLS MERGE CELLS
', null], + ['Word wrap', "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book"], + ['Linebreaks', "Line 1\nLine 2\nLine 3"], + ['Comments', 'No Author'], + ['Comments + author + linebreaks', "Pushkin"], + ['Rotation 90', 'Rotated header'], +]; +SimpleXLSXGen::fromArray($data) + ->setDefaultFont('Courier New') + ->setDefaultFontSize(14) + ->setColWidth(1, 35) // or ->setColWidth('A', 35) + ->setColWidth('B:C', 20) // column letters and ranges also work + ->mergeCells('A20:B20') + ->saveAs('styles_and_tags.xlsx'); +``` +![XLSX screenshot](styles.png) + +### RAW Strings +Prefix #0 cell value (use double quotes) or use ::raw() ::rawArray() methods or tag `````` +```php +$PushkinDOB = '1799-07-06'; +$data = [ + ['Datetime as raw string', "\0" . '2023-01-09 11:16:34'], + ['Date as raw string', "\0" . $PushkinDOB], + ['Disable type detection', "\0" . '+12345'], + ['Method ::raw, insert greater/less them simbols', SimpleXLSXGen::raw('20- short term: <6 month')], + ['Formatted raw', '
+123456 <tag>
'], +]; +SimpleXLSXGen::fromArray($data) + ->saveAs('test_rawstrings.xlsx'); + +$data = [ + ['test', 'raw', 'array'], + ['2025-08-09 14:36:34', '< tag >', 1] +]; +$raw_data = SimpleXLSXGen::rawArray($data); +SimpleXLSXGen::fromArray($raw_data)->saveAs('test_raw_array.xlsx'); +``` +### More examples +```php +// Fluid interface, output to browser for download +Shuchkin\SimpleXLSXGen::fromArray( $books )->downloadAs('table.xlsx'); + +// Fluid interface, multiple sheets +Shuchkin\SimpleXLSXGen::fromArray( $books, 'My books' )->addSheet( $books2 )->download(); + +// Alternative interface, sheet name, get xlsx content +$xlsx_cache = (string) (new Shuchkin\SimpleXLSXGen)->addSheet( $books, 'Modern style'); + +// Classic interface +use Shuchkin\SimpleXLSXGen; +$xlsx = new SimpleXLSXGen(); +$xlsx->addSheet( $books, 'Catalog 2021' ); +$xlsx->addSheet( $books2, 'Stephen King catalog'); +$xlsx->downloadAs('books_2021.xlsx'); +exit(); + +// Empty book with title +$xlsx = SimpleXLSX::create('My books'); +$xlsx->addSheet( $books ); +$xlsx->save(); // ./My books.xlsx + +// Hyperlinks +$xlsx = SimpleXLSX::fromArray([ + ['internal link', 'Go to second sheet'], + ['http', 'https://example.com/'], // autodetect + ['http + hash', 'https://en.wikipedia.org/wiki/Office_Open_XML#References'], // autodetect + ['external anchor', 'Open XML'], + ['relative link', 'books'], + ['relative link + cell addr', 'link to second sheet in other book'], + ['mailto', 'info@example.com'], // autodetect + ['mailto 2', 'Please email me'], +])->addSheet([['Second sheet']], 'My books 2')->saveAs('hyperlinks.xlsx'); + +// Autofilter +$xlsx->autoFilter('A1:B10'); + +// Freeze rows and columns from top-left corner up to, but not including, +// the row and column of the indicated cell +$xlsx->freezePanes('B2'); // B1 - freeze first column, A2 - freeze top row + +// RTL mode +// Column A is on the far right, Column B is one column left of Column A, and so on. +// Also, information in cells is displayed in the Right to Left format. +$xlsx->rightToLeft(); + +// Set Meta Data Files +// this data in propertis Files and Info file in Office +$xlsx->setAuthor('John Doe ') + ->setCompany('JD LLC ') + ->setManager('Jane Doe ') + ->setLastModifiedBy("John Doe ") + ->setTitle('My Books') + ->setSubject('My bookshelf') + ->setKeywords('Tolkien,Rowling,Kipling') + ->setDescription('Cool books worn by time') + ->setCategory('Books') + ->setLanguage('en-US') + ->setApplication('Shuchkin\SimpleXLSXGen') +``` +### JS array to Excel (AJAX) +```php +downloadAs('file.xlsx'); + return; +} +?> + + + JS array to Excel + + + + + + +``` + +## Debug +```php +ini_set('error_reporting', E_ALL ); +ini_set('display_errors', 1 ); + +$data = [ + ['Debug', 123] +]; + +Shuchkin\SimpleXLSXGen::fromArray( $data )->saveAs('debug.xlsx'); +``` diff --git a/vendor/shuchkin/simplexlsxgen/books.png b/vendor/shuchkin/simplexlsxgen/books.png new file mode 100644 index 00000000..afe7dfe1 Binary files /dev/null and b/vendor/shuchkin/simplexlsxgen/books.png differ diff --git a/vendor/shuchkin/simplexlsxgen/composer.json b/vendor/shuchkin/simplexlsxgen/composer.json new file mode 100644 index 00000000..2a8a9530 --- /dev/null +++ b/vendor/shuchkin/simplexlsxgen/composer.json @@ -0,0 +1,24 @@ +{ + "name": "shuchkin/simplexlsxgen", + "description": "Export data to Excel XLSx file. PHP XLSX generator.", + "keywords": ["php", "excel", "xlsx", "generator", "writer", "creator", "backend"], + "homepage": "https://github.com/shuchkin/simplexlsxgen", + "license": "MIT", + "authors": [ + { + "name": "Sergey Shuchkin (SMSPILOT)", + "email": "sergey.shuchkin@gmail.com", + "homepage": "https://shuchkin.ru/" + } + ], + "autoload": { + "classmap": [ + "src/SimpleXLSXGen.php" + ] + }, + "require": { + "php": ">=5.4", + "ext-mbstring": "*", + "ext-zlib": "*" + } +} diff --git a/vendor/shuchkin/simplexlsxgen/composer.lock b/vendor/shuchkin/simplexlsxgen/composer.lock new file mode 100644 index 00000000..bcf801c0 --- /dev/null +++ b/vendor/shuchkin/simplexlsxgen/composer.lock @@ -0,0 +1,20 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "9e2d3c362fd0bf028d5ee5081bdf5e4b", + "packages": [], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "ext-mbstring": "*", + "ext-zlib": "*" + }, + "platform-dev": [] +} diff --git a/vendor/shuchkin/simplexlsxgen/datatypes.png b/vendor/shuchkin/simplexlsxgen/datatypes.png new file mode 100644 index 00000000..db59361a Binary files /dev/null and b/vendor/shuchkin/simplexlsxgen/datatypes.png differ diff --git a/vendor/shuchkin/simplexlsxgen/examples/.gitignore b/vendor/shuchkin/simplexlsxgen/examples/.gitignore new file mode 100644 index 00000000..7c122203 --- /dev/null +++ b/vendor/shuchkin/simplexlsxgen/examples/.gitignore @@ -0,0 +1 @@ +*.xlsx diff --git a/vendor/shuchkin/simplexlsxgen/examples/custom-date-format.php b/vendor/shuchkin/simplexlsxgen/examples/custom-date-format.php new file mode 100644 index 00000000..d599a44c --- /dev/null +++ b/vendor/shuchkin/simplexlsxgen/examples/custom-date-format.php @@ -0,0 +1,12 @@ +addSheet([ + ["foo", "bar"], + ["something", ''], +]); + +$xlsx->saveAs(basename(__FILE__, ".php") . '.xlsx'); diff --git a/vendor/shuchkin/simplexlsxgen/license.md b/vendor/shuchkin/simplexlsxgen/license.md new file mode 100644 index 00000000..162854fa --- /dev/null +++ b/vendor/shuchkin/simplexlsxgen/license.md @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2020-2022 Sergey Shuchkin sergey.shuchkin@gmail.com + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/vendor/shuchkin/simplexlsxgen/src/SimpleXLSXGen.php b/vendor/shuchkin/simplexlsxgen/src/SimpleXLSXGen.php new file mode 100644 index 00000000..daeae962 --- /dev/null +++ b/vendor/shuchkin/simplexlsxgen/src/SimpleXLSXGen.php @@ -0,0 +1,1377 @@ +subject = ''; + $this->title = ''; + $this->author = ''; + $this->company = ''; + $this->manager = ''; + $this->description = ''; + $this->keywords = ''; + $this->category = ''; + $this->language = 'en-US'; + $this->lastModifiedBy = ''; + $this->application = __CLASS__; + + $this->curSheet = -1; + $this->defaultFont = 'Calibri'; + $this->defaultFontSize = 10; + $this->rtl = false; + $this->sheets = []; + $this->SI = []; // sharedStrings index + $this->SI_KEYS = []; // & keys + + // https://c-rex.net/projects/samples/ooxml/e1/Part4/OOXML_P4_DOCX_numFmts_topic_ID0E6KK6.html + $this->NF = [ + self::N_RUB => '#,##0.00\ "₽"', + self::N_DOLLAR => '[$$-1]#,##0.00', + self::N_EURO => '#,##0.00\ [$€-1]' + ]; + $this->NF_KEYS = array_flip($this->NF); + + $this->BR_STYLE = [ + self::B_NONE => 'none', + self::B_THIN => 'thin', + self::B_MEDIUM => 'medium', + self::B_DASHED => 'dashed', + self::B_DOTTED => 'dotted', + self::B_THICK => 'thick', + self::B_DOUBLE => 'double', + self::B_HAIR => 'hair', + self::B_MEDIUM_DASHED => 'mediumDashed', + self::B_DASH_DOT => 'dashDot', + self::B_MEDIUM_DASH_DOT => 'mediumDashDot', + self::B_DASH_DOT_DOT => 'dashDotDot', + self::B_MEDIUM_DASH_DOT_DOT => 'mediumDashDotDot', + self::B_SLANT_DASH_DOT => 'slantDashDot' + ]; + + $this->XF = [ // styles 0 - num fmt, 1 - align, 2 - font, 3 - fill, 4 - font color, 5 - bgcolor, 6 - border, 7 - font size + [self::N_NORMAL, self::A_DEFAULT, self::F_NORMAL, self::FL_NONE, 0, 0, '', 0], + [self::N_NORMAL, self::A_DEFAULT, self::F_NORMAL, self::FL_GRAY_125, 0, 0, '', 0], // hack + ]; + $this->XF_KEYS[implode('-', $this->XF[0])] = 0; // & keys + $this->XF_KEYS[implode('-', $this->XF[1])] = 1; + $this->template = [ + '_rels/.rels' => ''."\r\n" + .''."\r\n" + .''."\r\n" + .''."\r\n" + .''."\r\n" + .'', + 'docProps/app.xml' => ''."\r\n" + .''."\r\n" + .'0'."\r\n" + .'{APP}'."\r\n" + .'{COMPANY}'."\r\n" + .'{MANAGER}'."\r\n" + .'', + 'docProps/core.xml' => ''."\r\n" + .''."\r\n" + .'{DATE}'."\r\n" + .'{TITLE}'."\r\n" + .'{SUBJECT}'."\r\n" + .'{AUTHOR}'."\r\n" + .'{LAST_MODIFY_BY}'."\r\n" + .'{KEYWORD}'."\r\n" + .'{DESCRIPTION}'."\r\n" + .'{CATEGORY}'."\r\n" + .'{LANGUAGE}'."\r\n" + .'{DATE}'."\r\n" + .'1'."\r\n" + .'', + 'xl/_rels/workbook.xml.rels' => ''."\r\n" + .'' + ."\r\n{RELS}\r\n", + 'xl/worksheets/sheet1.xml' => ''."\r\n" + . '' . "\r\n" + .''."\r\n" + ."{SHEETVIEWS}\r\n{COLS}\r\n{ROWS}\r\n{AUTOFILTER}{MERGECELLS}{HYPERLINKS}{VML}", + 'xl/worksheets/_rels/sheet1.xml.rels' => ''."\r\n" + .'{RELS}', + 'xl/sharedStrings.xml' => ''."\r\n" + .'{STRINGS}', + 'xl/styles.xml' => ''."\r\n" + .'' + ."\r\n{NUMFMTS}\r\n{FONTS}\r\n{FILLS}\r\n{BORDERS}\r\n" + .'' + ."\r\n{XF}\r\n" + .'', + 'xl/workbook.xml' => ''."\r\n" + .''."\r\n" + .'{SHEETS}', + 'xl/comments1.xml' => ''."\r\n" + . '' . "\r\n" + . '{AUTHORS}' . "\r\n" + . '{COMMENTS}' . "\r\n" + . '', + 'xl/drawings/vmlDrawing1.vml' => '' . "\r\n" + . '' . "\r\n" + .'' . "\r\n" + .'{SHAPES}', + '[Content_Types].xml' => ''."\r\n" + .''."\r\n" + .'' . "\r\n" + .'' . "\r\n" + .'' . "\r\n" + .''."\r\n" + .''."\r\n" + .''."\r\n" + .' +' + ."\r\n{TYPES}", + ]; + } + public static function create($title = null) + { + $xlsx = new static(); + if ($title) { + $xlsx->setTitle($title); + } + return $xlsx; + } + + public static function fromArray(array $rows, $sheetName = null) + { + $xlsx = new static(); + $xlsx->addSheet($rows, $sheetName); + if ($sheetName) { + $xlsx->setTitle($sheetName); + } + return $xlsx; + } + + public function addSheet(array $rows, $name = null) + { + $this->curSheet++; + if ($name === null) { // autogenerated sheet names + $name = ($this->title ? mb_substr($this->title, 0, 31) : 'Sheet') . ($this->curSheet + 1); + } else { + $name = mb_substr($name, 0, 31); + $names = []; + foreach ($this->sheets as $sh) { + $names[mb_strtoupper($sh['name'])] = 1; + } + for ($i = 0; $i < 100; $i++) { + $postfix = ' (' . $i . ')'; + $new_name = ($i === 0) ? $name : $name . $postfix; + if (mb_strlen($new_name) > 31) { + $new_name = mb_substr($name, 0, 31 - mb_strlen($postfix)) . $postfix; + } + $NEW_NAME = mb_strtoupper($new_name); + if (!isset($names[$NEW_NAME])) { + $name = $new_name; + break; + } + } + } + $this->sheets[$this->curSheet] = ['name' => $name, 'relidx' => 0, 'hyperlinks' => [], 'comments' => [], 'mergecells' => [], 'colwidth' => [], 'autofilter' => '', 'frozen' => '']; + if (isset($rows[0]) && is_array($rows[0])) { + $this->sheets[$this->curSheet]['rows'] = $rows; + } else { + $this->sheets[$this->curSheet]['rows'] = []; + } + return $this; + } + + public function __toString() + { + $fh = fopen('php://memory', 'wb'); + if (!$fh) { + return ''; + } + if (!$this->_write($fh)) { + fclose($fh); + return ''; + } + $size = ftell($fh); + fseek($fh, 0); + return (string)fread($fh, $size); + } + + public function save() + { + return $this->saveAs(($this->title ?: gmdate('YmdHi')) . '.xlsx'); + } + public function saveAs($filename) + { + $fh = fopen(str_replace(["\0","\r","\n","\t",'"'], '', $filename), 'wb'); + if (!$fh) { + return false; + } + if (!$this->_write($fh)) { + fclose($fh); + return false; + } + fclose($fh); + return true; + } + + public function download() + { + return $this->downloadAs(($this->title ?: gmdate('YmdHi')) . '.xlsx'); + } + + public function downloadAs($filename) + { + $fh = fopen('php://memory', 'wb'); + if (!$fh) { + return false; + } + if (!$this->_write($fh)) { + fclose($fh); + return false; + } + $size = ftell($fh); + header('Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); + header('Content-Disposition: attachment; filename="' . str_replace(["\0","\r","\n","\t",'"'], '', $filename) . '"'); + header('Last-Modified: ' . gmdate('D, d M Y H:i:s \G\M\T', time())); + header('Content-Length: ' . $size); + while (ob_get_level()) { + ob_end_clean(); + } + fseek($fh, 0); + //Some servers disable fpassthru function. The alternative, stream_get_contents, use more memory + if (function_exists('fpassthru')) { + fpassthru($fh); + } else { + echo stream_get_contents($fh); + } + fclose($fh); + return true; + } + + protected function _write($fh) + { + $dirSignatureE = "\x50\x4b\x05\x06"; // end of central dir signature + $zipComments = 'Generated by ' . __CLASS__ . ' PHP class, thanks sergey.shuchkin@gmail.com'; + if (!$fh) { + return false; + } + $cdrec = ''; // central directory content + $entries = 0; // number of zipped files + $cnt_sheets = count($this->sheets); + if ($cnt_sheets === 0) { + $this->addSheet([], 'No data'); + $cnt_sheets = 1; + } + foreach ($this->template as $cfilename => $template) { + if ($cfilename === 'xl/_rels/workbook.xml.rels') { + $s = ''; + for ($i = 0; $i < $cnt_sheets; $i++) { + $s .= '\r\n"; + } + $s .= '' . "\r\n"; + $s .= ''; + + $template = str_replace('{RELS}', $s, $template); + $this->_writeEntry($fh, $cdrec, $cfilename, $template); + $entries++; + } elseif ($cfilename === 'xl/workbook.xml') { + $s = ''; + foreach ($this->sheets as $k => $v) { + $s .= ''; + } + $search = ['{SHEETS}', '{APP}']; + $replace = [$s, self::esc($this->application)]; + $template = str_replace($search, $replace, $template); + $this->_writeEntry($fh, $cdrec, $cfilename, $template); + $entries++; + } elseif ($cfilename === 'docProps/app.xml') { + $search = ['{APP}', '{COMPANY}', '{MANAGER}']; + $replace = [self::esc($this->application), self::esc($this->company), self::esc($this->manager)]; + $template = str_replace($search, $replace, $template); + $this->_writeEntry($fh, $cdrec, $cfilename, $template); + $entries++; + } elseif ($cfilename === 'docProps/core.xml') { + $search = ['{DATE}', '{AUTHOR}', '{TITLE}', '{SUBJECT}', '{KEYWORD}', '{DESCRIPTION}', '{CATEGORY}', '{LANGUAGE}', '{LAST_MODIFY_BY}']; + $replace = [gmdate('Y-m-d\TH:i:s\Z'), self::esc($this->author), self::esc($this->title), self::esc($this->subject), self::esc($this->keywords), self::esc($this->description), self::esc($this->category), self::esc($this->language), self::esc($this->lastModifiedBy)]; + $template = str_replace($search, $replace, $template); + $this->_writeEntry($fh, $cdrec, $cfilename, $template); + $entries++; + } elseif ($cfilename === 'xl/sharedStrings.xml') { + $si_cnt = count($this->SI); + if ($si_cnt) { + $si = []; + foreach ($this->SI as $s) { + $si[] = '' . (preg_match('/^\s|\s$/', $s) ? '' . $s . '' : '' . $s . '') . ''; + } + $template = str_replace(['{CNT}', '{STRINGS}'], [$si_cnt, implode("\r\n", $si)], $template); + $this->_writeEntry($fh, $cdrec, $cfilename, $template); + $entries++; + } + } elseif ($cfilename === 'xl/worksheets/sheet1.xml') { + foreach ($this->sheets as $k => $v) { + $filename = 'xl/worksheets/sheet' . ($k + 1) . '.xml'; + $xml = $this->_sheetToXML($k, $template); + $this->_writeEntry($fh, $cdrec, $filename, $xml); + $entries++; + } + $xml = null; + } elseif ($cfilename === 'xl/worksheets/_rels/sheet1.xml.rels') { + foreach ($this->sheets as $k => $v) { + $R = []; + if (count($v['comments'])) { + $this->sheets[$k]['relidx']++; + $R[] = ''; + $R[] = ''; + } + foreach ($v['hyperlinks'] as $h) { + if ($h['ID']) { + $R[] = ''; + } + } + if (count($R)) { + $filename = 'xl/worksheets/_rels/sheet' . ($k + 1) . '.xml.rels'; + $xml = str_replace('{RELS}', implode("\r\n", $R), $template); + $this->_writeEntry($fh, $cdrec, $filename, $xml); + $entries++; + } + } + $xml = null; + } elseif ($cfilename === 'xl/comments1.xml') { + foreach ($this->sheets as $k => $v) { + $C = []; + $A = []; + foreach ($v['comments'] as $com) { + $A[$com['A']] = count($A); + } + foreach ($v['comments'] as $com) { + $C[] = '' . "\r\n" + . ($com['A'] ? ('' . $com['A'] . ":\r\n" .'' . "\r\n") : '') + .'' . self::esc($com['T']) . '' . "\r\n" +// .'' . self::esc($com['T']) . ($com['A'] ? "\r\n\t-" . $com['A'] : '') . '' . "\r\n" + . ''; + } + if (count($C)) { + $filename = 'xl/comments' . ($k + 1) . '.xml'; + $xml = str_replace( + array('{AUTHORS}', '{COMMENTS}'), + array('' . implode("\r\n", array_keys($A)) . '', + implode("\r\n", $C)), $template + ); + $this->_writeEntry($fh, $cdrec, $filename, $xml); + $entries++; + } + } + $xml = null; + } elseif ($cfilename === 'xl/drawings/vmlDrawing1.vml') { + foreach ($this->sheets as $k => $v) { + if (count($v['comments'])) { + $S = []; + foreach ($v['comments'] as $k2 => $com) { +// Anchor: LeftColumn, LeftOffset, TopRow, TopOffset, RightColumn, RightOffset, BottomRow, BottomOffset + $a = [ + $com['C'], + 15, + $com['R'], + 10, + $com['C'] + 4, + 15, + $com['R'] + 4, + 4 + ]; + $S[] = ''; + } + $filename = 'xl/drawings/vmlDrawing' . ($k + 1) . '.vml'; + $xml = str_replace('{SHAPES}', "\r\n" . implode("\r\n", $S) . "\r\n", $template); + $this->_writeEntry($fh, $cdrec, $filename, $xml); + $entries++; + } + } + $xml = null; + } elseif ($cfilename === '[Content_Types].xml') { + $TYPES = []; + foreach ($this->sheets as $k => $v) { + $TYPES[] = ''; + if (count($v['comments'])) { + $TYPES[] = ''; + } + } + $template = str_replace('{TYPES}', implode("\r\n", $TYPES), $template); + $this->_writeEntry($fh, $cdrec, $cfilename, $template); + $entries++; + } elseif ($cfilename === 'xl/styles.xml') { + $NF = $XF = $FONTS = $F_KEYS = $FILLS = $FL_KEYS = []; + $BR = ['']; + $BR_KEYS = [0 => 0]; + foreach ($this->NF as $k => $v) { + $NF[] = ''; + } + foreach ($this->XF as $xf) { + // 0 - num fmt, 1 - align, 2 - font, 3 - fill, 4 - font color, 5 - bgcolor, 6 - border, 7 - font size + // fonts + $F_KEY = $xf[2] . '-' . $xf[4] . '-' . $xf[7]; + if (isset($F_KEYS[$F_KEY])) { + $F_ID = $F_KEYS[$F_KEY]; + } else { + $F_ID = $F_KEYS[$F_KEY] = count($FONTS); + $FONTS[] = '' + . ($xf[7] ? '' : '') + . ($xf[2] & self::F_BOLD ? '' : '') + . ($xf[2] & self::F_ITALIC ? '' : '') + . ($xf[2] & self::F_UNDERLINE ? '' : '') + . ($xf[2] & self::F_STRIKE ? '' : '') + . ($xf[2] & self::F_HYPERLINK ? '' : '') + . ($xf[2] & self::F_COLOR ? '' : '') + . ''; + } + // fills + $FL_KEY = $xf[3] . '-' . $xf[5]; + if (isset($FL_KEYS[$FL_KEY])) { + $FL_ID = $FL_KEYS[$FL_KEY]; + } else { + $FL_ID = $FL_KEYS[$FL_KEY] = count($FILLS); + $FILLS[] = '' : ' />') + . ''; + } + $align = ''; + if ($xf[1] & self::A_LEFT) { + $align .= ' horizontal="left"'; + } elseif ($xf[1] & self::A_RIGHT) { + $align .= ' horizontal="right"'; + } elseif ($xf[1] & self::A_CENTER) { + $align .= ' horizontal="center"'; + } + if ($xf[1] & self::A_TOP) { + $align .= ' vertical="top"'; + } elseif ($xf[1] & self::A_MIDDLE) { + $align .= ' vertical="center"'; + } elseif ($xf[1] & self::A_BOTTOM) { + $align .= ' vertical="bottom"'; + } + if ($xf[1] & self::A_WRAPTEXT) { + $align .= ' wrapText="1"'; + } + if ($xf[1] & self::A_ROTATION_90) { + $align .= ' textRotation="90"'; + } + + // border + $BR_ID = 0; + if ($xf[6] !== '') { + $b = $xf[6]; + if (isset($BR_KEYS[$b])) { + $BR_ID = $BR_KEYS[$b]; + } else { + $BR_ID = count($BR_KEYS); + $BR_KEYS[$b] = $BR_ID; + $border = ''; + $ba = explode(' ', $b); + if (!isset($ba[1])) { + $ba[] = $ba[0]; + $ba[] = $ba[0]; + $ba[] = $ba[0]; + } + if (!isset($ba[4])) { // diagonal + $ba[] = 'none'; + } + $sides = ['left' => 3, 'right' => 1, 'top' => 0, 'bottom' => 2, 'diagonal' => 4]; + foreach ($sides as $side => $idx) { + $s = 'thin'; + $c = ''; + $va = explode('#', $ba[$idx]); + if (isset($va[1])) { + $s = $va[0] === '' ? 'thin' : $va[0]; + $c = $va[1]; + } elseif (in_array($va[0], $this->BR_STYLE, true)) { + $s = $va[0]; + } else { + $c = $va[0]; + } + if (strlen($c) === 6) { + $c = 'FF' . $c; + } + if ($s && $s !== 'none') { + $border .= '<' . $side . ' style="' . $s . '">' + . '' + . ''; + } else { + $border .= '<' . $side . '/>'; + } + } + $border .= ''; + $BR[] = $border; + } + } + $XF[] = ' 0 ? ' applyNumberFormat="1"' : '') + . ($F_ID > 0 ? ' applyFont="1"' : '') + . ($FL_ID > 0 ? ' applyFill="1"' : '') + . ($BR_ID > 0 ? ' applyBorder="1"' : '') + . ($align ? ' applyAlignment="1">' : '/>'); + } + // wrap collections + array_unshift($NF, ''); + $NF[] = ''; + array_unshift($XF, ''); + $XF[] = ''; + array_unshift($FONTS, ''); + $FONTS[] = ''; + array_unshift($FILLS, ''); + $FILLS[] = ''; + array_unshift($BR, ''); + $BR[] = ''; + + $template = str_replace( + ['{NUMFMTS}', '{FONTS}', '{XF}', '{FILLS}', '{BORDERS}'], + [implode("\r\n", $NF), implode("\r\n", $FONTS), implode("\r\n", $XF), implode("\r\n", $FILLS), implode("\r\n", $BR)], + $template + ); + $this->_writeEntry($fh, $cdrec, $cfilename, $template); + $entries++; + } else { + $this->_writeEntry($fh, $cdrec, $cfilename, $template); + $entries++; + } + } + $before_cd = ftell($fh); + fwrite($fh, $cdrec); + // end of central dir + fwrite($fh, $dirSignatureE); + fwrite($fh, pack('v', 0)); // number of this disk + fwrite($fh, pack('v', 0)); // number of the disk with the start of the central directory + fwrite($fh, pack('v', $entries)); // total # of entries "on this disk" + fwrite($fh, pack('v', $entries)); // total # of entries overall + fwrite($fh, pack('V', mb_strlen($cdrec, '8bit'))); // size of central dir + fwrite($fh, pack('V', $before_cd)); // offset to start of central dir + fwrite($fh, pack('v', mb_strlen($zipComments, '8bit'))); // .zip file comment length + fwrite($fh, $zipComments); + + return true; + } + + protected function _writeEntry($fh, &$cdrec, $cfilename, $data) + { + $zipSignature = "\x50\x4b\x03\x04"; // local file header signature + $dirSignature = "\x50\x4b\x01\x02"; // central dir header signature + + $e = []; + $e['uncsize'] = mb_strlen($data, '8bit'); + // if data to compress is too small, just store it + if ($e['uncsize'] < 256) { + $e['comsize'] = $e['uncsize']; + $e['vneeded'] = 10; + $e['cmethod'] = 0; + $zdata = $data; + } else { // otherwise, compress it + $zdata = gzcompress($data); + $zdata = substr(substr($zdata, 0, -4), 2); // fix crc bug (thanks to Eric Mueller) + $e['comsize'] = mb_strlen($zdata, '8bit'); + $e['vneeded'] = 10; + $e['cmethod'] = 8; + } + $e['bitflag'] = 0; + $e['crc_32'] = crc32($data); + + // Convert date and time to DOS Format, and set then + $date = getdate(); + $e['dostime'] = ( + (($date['year'] - 1980) << 25) + | ($date['mon'] << 21) + | ($date['mday'] << 16) + | ($date['hours'] << 11) + | ($date['minutes'] << 5) + | ($date['seconds'] >> 1) + ); + + $e['offset'] = ftell($fh); + + fwrite($fh, $zipSignature); + fwrite($fh, pack('v', $e['vneeded'])); // version_needed + fwrite($fh, pack('v', $e['bitflag'])); // general_bit_flag + fwrite($fh, pack('v', $e['cmethod'])); // compression_method + fwrite($fh, pack('V', $e['dostime'])); // lastmod datetime + fwrite($fh, pack('V', $e['crc_32'])); // crc-32 + fwrite($fh, pack('V', $e['comsize'])); // compressed_size + fwrite($fh, pack('V', $e['uncsize'])); // uncompressed_size + fwrite($fh, pack('v', mb_strlen($cfilename, '8bit'))); // file_name_length + fwrite($fh, pack('v', 0)); // extra_field_length + fwrite($fh, $cfilename); // file_name + // ignoring extra_field + fwrite($fh, $zdata); + + // Append it to central dir + $e['external_attributes'] = (substr($cfilename, -1) === '/' && !$zdata) ? 16 : 32; // Directory or file name + $e['comments'] = ''; + + $cdrec .= $dirSignature; + $cdrec .= "\x0\x0"; // version made by + $cdrec .= pack('v', $e['vneeded']); // version needed to extract + $cdrec .= "\x0\x0"; // general bit flag + $cdrec .= pack('v', $e['cmethod']); // compression method + $cdrec .= pack('V', $e['dostime']); // lastmod datetime + $cdrec .= pack('V', $e['crc_32']); // crc32 + $cdrec .= pack('V', $e['comsize']); // compressed filesize + $cdrec .= pack('V', $e['uncsize']); // uncompressed filesize + $cdrec .= pack('v', mb_strlen($cfilename, '8bit')); // file name length + $cdrec .= pack('v', 0); // extra field length + $cdrec .= pack('v', mb_strlen($e['comments'], '8bit')); // file comment length + $cdrec .= pack('v', 0); // disk number start + $cdrec .= pack('v', 0); // internal file attributes + $cdrec .= pack('V', $e['external_attributes']); // internal file attributes + $cdrec .= pack('V', $e['offset']); // relative offset of local header + $cdrec .= $cfilename; + $cdrec .= $e['comments']; + } + + protected function _sheetToXML($idx, $template) + { + // locale floats fr_FR 1.234,56 -> 1234.56 + $_loc = setlocale(LC_NUMERIC, 0); + setlocale(LC_NUMERIC, 'C'); + $COLS = []; + $ROWS = []; + $VML = []; + // $SHEETVIEWS = 'rtl ? ' rightToLeft="1"' : '').'>'; + $SHEETVIEWS = ''; + $PANE = ''; + if (count($this->sheets[$idx]['rows'])) { + $ROWS[] = ''; + if ($this->sheets[$idx]['frozen'] !== '' || isset($this->sheets[$idx]['frozen'][0]) || isset($this->sheets[$idx]['frozen'][1])) { + // $AC = 'A1'; // Active Cell + $x = $y = 0; + if (is_string($this->sheets[$idx]['frozen'])) { + $AC = $this->sheets[$idx]['frozen']; + self::cell2coord($AC, $x, $y); + } else { + if (isset($this->sheets[$idx]['frozen'][0])) { + $x = $this->sheets[$idx]['frozen'][0]; + } + if (isset($this->sheets[$idx]['frozen'][1])) { + $y = $this->sheets[$idx]['frozen'][1]; + } + $AC = self::coord2cell($x, $y); + } + if ($x > 0 || $y > 0) { + $split = ''; + if ($x > 0) { + $split .= ' xSplit="' . $x . '"'; + } + if ($y > 0) { + $split .= ' ySplit="' . $y . '"'; + } + $activepane = 'bottomRight'; + if ($x > 0 && $y === 0) { + $activepane = 'topRight'; + } + if ($x === 0 && $y > 0) { + $activepane = 'bottomLeft'; + } + $PANE .= ''; + $PANE .= ''; + } + } + if ($this->rtl || $PANE) { + $SHEETVIEWS .= ' +rtl ? ' rightToLeft="1"' : ''); + $SHEETVIEWS .= $PANE ? ">\r\n" . $PANE . "\r\n" : ' />'; + $SHEETVIEWS .= "\r\n"; + } + $CUR_ROW = 0; + $COL = []; + foreach ($this->sheets[$idx]['rows'] as $r) { + $CUR_ROW++; + $row = ''; + $CUR_COL = 0; + $RH = 0; // row height + foreach ($r as $v) { + $CUR_COL++; + if (!isset($COL[$CUR_COL])) { + $COL[$CUR_COL] = 0; + } + $cname = self::coord2cell($CUR_COL-1) . $CUR_ROW; + if ($v === null || $v === '') { + $row .= ''; + continue; + } + $ct = $cv = $cf = null; + $N = $NF = $A = $F = $FL = $C = $BG = $FS = $FR = 0; + $m = $m2 = null; + $BR = ''; + if (is_string($v)) { + if (strpos($v, "\0") === 0) { // RAW value as string + $v = substr($v, 1); + $vl = mb_strlen($v); + } else { + if (strpos($v, '<') !== false) { // tags? + if (preg_match('//s', $v, $m)) { + $com = trim($m[1]); + $a = $this->author; + if (preg_match('/^([^:]+): (.*)$/us', $com, $m2)) { + $a = $m2[1]; + /** @noinspection MultiAssignmentUsageInspection */ + $com = $m2[2]; + } + $this->sheets[$idx]['comments'][] = ['C' => $CUR_COL, 'R' => $CUR_ROW, 'N' => $cname, 'T' => $com, 'A' => $a]; + $v = str_replace($m[0], '', $v); + } + if (strpos($v, '') !== false) { + $F += self::F_BOLD; + } + if (strpos($v, '') !== false) { + $F += self::F_ITALIC; + } + if (strpos($v, '') !== false) { + $F += self::F_UNDERLINE; + } + if (strpos($v, '') !== false) { + $F += self::F_STRIKE; + } + if (preg_match('/]+)>/', $v, $m)) { + if (preg_match('/ color="([^"]+)"/', $m[1], $m2)) { + $F += self::F_COLOR; + $c = ltrim($m2[1], '#'); + $C = strlen($c) === 8 ? $c : ('FF' . $c); + } + if (preg_match('/ bgcolor="([^"]+)"/', $m[1], $m2)) { + $FL += self::FL_COLOR; + $c = ltrim($m2[1], '#'); + $BG = strlen($c) === 8 ? $c : ('FF' . $c); + } + if (preg_match('/ height="([^"]+)"/', $m[1], $m2)) { + $RH = $m2[1]; + } + if (preg_match('/ nf="([^"]+)"/', $m[1], $m2)) { + $c = htmlspecialchars_decode($m2[1], ENT_QUOTES); + $NF = $this->getNumFmtId($c); + } + if (preg_match('/ border="([^"]+)"/', $m[1], $m2)) { + $b = htmlspecialchars_decode($m2[1], ENT_QUOTES); + if ($b && $b !== 'none') { + $BR = $b; + } + } + if (preg_match('/ font-size="([^"]+)"/', $m[1], $m2)) { + $FS = (int)$m2[1]; + if ($RH === 0) { // fix row height + $RH = ($FS > $this->defaultFontSize) ? round($FS * 1.50, 1, PHP_ROUND_HALF_UP) : 0; + } + } + } + if (strpos($v, '') !== false) { + $A += self::A_LEFT; + } + if (strpos($v, '
') !== false) { + $A += self::A_CENTER; + } + if (strpos($v, '') !== false) { + $A += self::A_RIGHT; + } + if (strpos($v, '') !== false) { + $A += self::A_TOP; + } + if (strpos($v, '') !== false) { + $A += self::A_MIDDLE; + } + if (strpos($v, '') !== false) { + $A += self::A_BOTTOM; + } + if (strpos($v, '') !== false) { + $A += self::A_WRAPTEXT; + } + if (strpos($v, '') !== false) { + $A += self::A_ROTATION_90; + } + if (preg_match('/(.*?)<\/a>/i', $v, $m)) { + $F += self::F_HYPERLINK; + + $h = explode('#', $m[1]); + if (count($h) === 1) { + if (strpos($h[0], '!') > 0) { // internal hyperlink + $this->sheets[$idx]['hyperlinks'][] = ['ID' => null, 'R' => $cname, 'H' => null, 'L' => $m[1]]; + } else { + $this->sheets[$idx]['relidx']++; + $this->sheets[$idx]['hyperlinks'][] = ['ID' => 'rId' . $this->sheets[$idx]['relidx'], 'R' => $cname, 'H' => $m[1], 'L' => '']; + } + } else { + $this->sheets[$idx]['relidx']++; + $this->sheets[$idx]['hyperlinks'][] = ['ID' => 'rId' . $this->sheets[$idx]['relidx'], 'R' => $cname, 'H' => $h[0], 'L' => $h[1]]; + } + } + // formatted raw? + if (preg_match('/(.*)<\/raw>/', $v, $m)) { + $FR = 1; + $v = $m[1]; + } elseif (preg_match('/]*)>/', $v, $m)) { + $cf = strip_tags($v); + $v = 0; + if (preg_match('/ v="([^"]+)"/', $m[1], $m2)) { + $v = $m2[1]; + } + } else { + $v = strip_tags($v); + } + } // \tags + $vl = mb_strlen($v); + if ($FR) { + $v = htmlspecialchars_decode($v); + $vl = mb_strlen($v); + } elseif ($NF) { + $cv = ltrim($v, '+'); // Formatted Number + } elseif ($v === '0' || preg_match('/^[-+]?[1-9]\d{0,14}$/', $v)) { // Integer as General + $cv = ltrim($v, '+'); + if ($vl > 10) { + $N = self::N_INT; // [1] 0 + } + } elseif (preg_match('/^[-+]?(0|[1-9]\d*)\.\d\d?$/', $v)) { // Decimal + $cv = ltrim($v, '+'); + $N = self::N_DEC; + } elseif (preg_match('/^[-+]?(0|[1-9]{1,8})\.\d\d{0,8}$/', $v)) { // Real as General + $cv = ltrim($v, '+'); + } elseif (preg_match('/^\$[-+]?[0-9\.]+$/', $v)) { // currency $? + $N = self::N_DOLLAR; + $cv = ltrim($v, '+$'); + } elseif (preg_match('/^[-+]?[0-9\.]+( ₽| €)$/u', $v, $m)) { // currency ₽ €? + if ($m[1] === ' ₽') { + $N = self::N_RUB; + } elseif ($m[1] === ' €') { + $N = self::N_EURO; + } + $cv = trim($v, ' +₽€'); + } elseif (preg_match('/^([-+]?\d+)%$/', $v, $m)) { + $cv = round($m[1] / 100, 2, PHP_ROUND_HALF_UP); + $N = self::N_PERCENT_INT; // [9] 0% + } elseif (preg_match('/^([-+]?\d+\.\d+)%$/', $v, $m)) { + $cv = round($m[1] / 100, 4, PHP_ROUND_HALF_UP); + $N = self::N_PRECENT_DEC; // [10] 0.00% + } elseif (preg_match('/^(\d\d\d\d)-(\d\d)-(\d\d)$/', $v, $m)) { + $cv = self::date2excel($m[1], $m[2], $m[3]); + $N = self::N_DATE; // [14] mm-dd-yy + } elseif (preg_match('/^(\d\d)\/(\d\d)\/(\d\d\d\d)$/', $v, $m)) { + $cv = self::date2excel($m[3], $m[2], $m[1]); + $N = self::N_DATE; // [14] mm-dd-yy + } elseif (preg_match('/^(\d\d):(\d\d):(\d\d)$/', $v, $m)) { + $cv = self::date2excel(0, 0, 0, $m[1], $m[2], $m[3]); + $N = self::N_TIME; // time + } elseif (preg_match('/^(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)$/', $v, $m)) { + $cv = self::date2excel($m[1], $m[2], $m[3], $m[4], $m[5], $m[6]); + $N = ((int)$m[1] === 0) ? self::N_TIME : self::N_DATETIME; // [22] m/d/yy h:mm + } elseif (preg_match('/^(\d\d)\/(\d\d)\/(\d\d\d\d) (\d\d):(\d\d):(\d\d)$/', $v, $m)) { + $cv = self::date2excel($m[3], $m[2], $m[1], $m[4], $m[5], $m[6]); + $N = self::N_DATETIME; // [22] m/d/yy h:mm + } elseif (preg_match('/^[0-9\.\-\+]+$/', $v)) { // Long Number (card, phone, serial)? + $A += ($A & (self::A_LEFT | self::A_CENTER)) ? 0 : self::A_RIGHT; + } elseif (preg_match('/^https?:\/\/\S+$/i', $v)) { // Hyperlink ? + $h = explode('#', $v); + $this->sheets[$idx]['relidx']++; + $this->sheets[$idx]['hyperlinks'][] = ['ID' => 'rId' . $this->sheets[$idx]['relidx'], 'R' => $cname, 'H' => $h[0], 'L' => isset($h[1]) ? $h[1] : '']; + $F += self::F_HYPERLINK; + } elseif (preg_match("/^[a-zA-Z0-9_\.\-]+@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/", $v)) { // email? + $this->sheets[$idx]['relidx']++; + $this->sheets[$idx]['hyperlinks'][] = ['ID' => 'rId' . $this->sheets[$idx]['relidx'], 'R' => $cname, 'H' => 'mailto:' . $v, 'L' => '']; + $F += self::F_HYPERLINK; + } elseif (strpos($v,"\n") !== false) { + $A |= self::A_WRAPTEXT; + } + + if (($N === self::N_DATE || $N === self::N_DATETIME) && $cv < 0) { + $cv = null; + $N = 0; + } + + } + if ($cv === null) { // string + $v = self::esc($v); + if ($cf) { + $ct = 'str'; + $cv = $v; + } elseif ($v === '') { + $ct = 's'; + } elseif (mb_strlen($v) > 160) { + $ct = 'inlineStr'; + $cv = $v; + } else { + $ct = 's'; // shared string + $cv = false; + $skey = '~' . $v; + if (isset($this->SI_KEYS[$skey])) { + $cv = $this->SI_KEYS[$skey]; + } + if ($cv === false) { + $this->SI[] = $v; + $cv = count($this->SI) - 1; + $this->SI_KEYS[$skey] = $cv; + } + } + } + } elseif (is_int($v)) { + $vl = mb_strlen((string)$v); + $cv = $v; + } elseif (is_float($v)) { + $vl = mb_strlen((string)$v); + $cv = $v; + } elseif ($v instanceof \DateTime) { + $vl = 16; + $cv = self::date2excel($v->format('Y'), $v->format('m'), $v->format('d'), $v->format('H'), $v->format('i'), $v->format('s')); + $N = self::N_DATETIME; // [22] m/d/yy h:mm + } else { + continue; + } + if ($NF) { + $N = $NF; + } + $COL[$CUR_COL] = max($vl, $COL[$CUR_COL]); + $cs = 0; + if (($N + $A + $F + $FL + $FS > 0) || $BR !== '') { + if ($FL === self::FL_COLOR) { + $FL += self::FL_SOLID; + } + if (($F & self::F_HYPERLINK) && !($F & self::F_COLOR)) { + $F += self::F_COLOR; + $C = 'FF0563C1'; + } + $XF_KEY = $N . '-' . $A . '-' . $F . '-' . $FL . '-' . $C . '-' . $BG . '-' . $BR . '-' . $FS; + if (isset($this->XF_KEYS[$XF_KEY])) { + $cs = $this->XF_KEYS[$XF_KEY]; + } + if ($cs === 0) { + $cs = count($this->XF); + $this->XF_KEYS[$XF_KEY] = $cs; + $this->XF[] = [$N, $A, $F, $FL, $C, $BG, $BR, $FS]; + } + } + $row .= '' . $cf . '' : '') + . ($ct === 'inlineStr' ? '' . $cv . '' : '' . $cv . '') + . "\r\n"; + } + } + $ROWS[] = '' . $row . ""; + } + $COLS[] = ''; + foreach ($COL as $k => $max) { + if ($max === 0) { + continue; + } + $w = isset($this->sheets[$idx]['colwidth'][$k]) ? $this->sheets[$idx]['colwidth'][$k] : min($max + 1, 60); + $COLS[] = ''; + } + $COLS[] = ''; + if (count($COLS) === 2) { + $COLS = []; + } + $ROWS[] = ''; + $REF = 'A1:' . self::coord2cell(count($COL)-1) . $CUR_ROW; + } else { + $ROWS[] = ''; + $REF = 'A1:A1'; + } + + $AUTOFILTER = ''; + if ($this->sheets[$idx]['autofilter']) { + $AUTOFILTER = ''; + } + + $MERGECELLS = []; + if (count($this->sheets[$idx]['mergecells'])) { + $MERGECELLS[] = ''; + $MERGECELLS[] = ''; + foreach ($this->sheets[$idx]['mergecells'] as $m) { + $MERGECELLS[] = ''; + } + $MERGECELLS[] = ''; + } + + $HYPERLINKS = []; + if (count($this->sheets[$idx]['hyperlinks'])) { + $HYPERLINKS[] = ''; + foreach ($this->sheets[$idx]['hyperlinks'] as $h) { + $HYPERLINKS[] = ''; + } + $HYPERLINKS[] = ''; + } + if (count($this->sheets[$idx]['comments'])) { + + $VML[] = ''; + } + + //restore locale + setlocale(LC_NUMERIC, $_loc); + + return str_replace( + ['{REF}', '{COLS}', '{ROWS}', '{AUTOFILTER}', '{MERGECELLS}', '{HYPERLINKS}', '{SHEETVIEWS}', '{VML}'], + [ + $REF, + implode("\r\n", $COLS), + implode("\r\n", $ROWS), + $AUTOFILTER, + implode("\r\n", $MERGECELLS), + implode("\r\n", $HYPERLINKS), + $SHEETVIEWS, + implode("\r\n", $VML) + ], + $template + ); + } + + public function setDefaultFont($name) + { + $this->defaultFont = $name; + return $this; + } + + public function setDefaultFontSize($size) + { + $this->defaultFontSize = $size; + return $this; + } + + public function setTitle($title) + { + $this->title = $title; + return $this; + } + public function setSubject($subject) + { + $this->subject = $subject; + return $this; + } + public function setAuthor($author) + { + $this->author = $author; + return $this; + } + public function setCompany($company) + { + $this->company = $company; + return $this; + } + public function setManager($manager) + { + $this->manager = $manager; + return $this; + } + public function setKeywords($keywords) + { + $this->keywords = $keywords; + return $this; + } + public function setDescription($description) + { + $this->description = $description; + return $this; + } + public function setCategory($category) + { + $this->category = $category; + return $this; + } + + public function setLanguage($language) + { + $this->language = $language; + return $this; + } + + public function setApplication($application) + { + $this->application = $application; + return $this; + } + public function setLastModifiedBy($lastModifiedBy) + { + $this->lastModifiedBy = $lastModifiedBy; + return $this; + } + + /** + * @param $range string 'A2:B10' + * @return $this + */ + public function autoFilter($range) + { + $this->sheets[$this->curSheet]['autofilter'] = $range; + return $this; + } + + public function mergeCells($range) + { + $this->sheets[$this->curSheet]['mergecells'][] = $range; + return $this; + } + + /** + * @param $col int|string Column index starts with 1, or column letter ('A', 'AA'), or range ('A:C') + * @param $width int Width in chars + * @return $this + */ + public function setColWidth($col, $width) + { + if (is_string($col) && strpos($col, ':') !== false) { + list($from, $to) = explode(':', $col, 2); + $from = self::col2index($from); + $to = self::col2index($to); + for ($i = $from; $i <= $to; $i++) { + $this->sheets[$this->curSheet]['colwidth'][$i] = $width; + } + return $this; + } + $this->sheets[$this->curSheet]['colwidth'][self::col2index($col)] = $width; + return $this; + } + public function rightToLeft($value = true) + { + $this->rtl = $value; + return $this; + } + + public function freezePanes($cell) + { + $this->sheets[$this->curSheet]['frozen'] = $cell; + return $this; + } + + public function getNumFmtId($code) + { + if (isset($this->NF[$code])) { // id? + return (int)$code; + } + if (isset($this->NF_KEYS[$code])) { + return $this->NF_KEYS[$code]; + } + $id = self::N_CUSTOM + count($this->NF); // custom + $this->NF[$id] = $code; + $this->NF_KEYS[$code] = $id; + return $id; + } + + public static function date2excel($year, $month, $day, $hours = 0, $minutes = 0, $seconds = 0) + { + $excelTime = (($hours * 3600) + ($minutes * 60) + $seconds) / 86400; + $year = (int) $year; + $month = (int) $month; + $day = (int) $day; +// echo "y=$year m=$month d=$day h=$hours m=$minutes s=$seconds".PHP_EOL; + if ($year === 0) { + return $excelTime; + } + // self::CALENDAR_WINDOWS_1900 + $excel1900isLeapYear = 1; + if (($year === 1900) && ($month <= 2)) { + $excel1900isLeapYear = 0; + } + $myExcelBaseDate = 2415020; + // Julian base date Adjustment + if ($month > 2) { + $month -= 3; + } else { + $month += 9; + --$year; + } + $century = floor($year / 100); + $decade = $year - floor($year / 100) * 100; +// echo "y=$year m=$month d=$day cent=$century dec=$decade h=$hours m=$minutes s=$seconds".PHP_EOL; + // Calculate the Julian Date, then subtract the Excel base date (JD 2415020 = 31-Dec-1899 Giving Excel Date of 0) + $excelDate = floor((146097 * $century) / 4) + floor((1461 * $decade) / 4) + floor((153 * $month + 2) / 5) + $day + 1721119 - $myExcelBaseDate + $excel1900isLeapYear; + return (float)$excelDate + $excelTime; + } + + + + public static function esc($str) + { + // XML UTF-8: #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] + // but we use fast version + return str_replace(['&', '<', '>', "\x00", "\x03", "\x0B"], ['&', '<', '>', '', '', ''], $str); + } + + + public static function raw($value) + { + return "\0" . $value; + } + public static function rawArray($array) + { + foreach ($array as &$row) { + foreach ($row as &$value) { + $value = "\0" . $value; + } + } + return $array; + } + + private static function col2index($col) + { + if (is_int($col)) { + return $col; + } + $m = null; + if (preg_match('/^([A-Za-z]+)$/', $col, $m)) { + $letters = strtoupper($m[1]); + $len = strlen($letters); + $x = 0; + for ($i = 0; $i < $len; $i++) { + $int = ord($letters[$i]) - 65; // A -> 0, B -> 1 + $int += ($i === $len - 1) ? 0 : 1; + $x += $int * pow(26, $len-$i-1); + } + return $x + 1; + } + return (int)$col; + } + + public static function cell2coord($cell, &$x, &$y) + { + $x = $y = 0; + $m = null; + if (preg_match('/^([A-Z]+)(\d+)$/', $cell, $m)) { + $len = strlen($m[1]); + for ($i = 0; $i < $len; $i++) { + $int = ord($m[1][$i]) - 65; // A -> 0, B -> 1 + $int += ($i === $len - 1) ? 0 : 1; + $x += $int * pow(26, $len-$i-1); + } + $y = ((int)$m[2]) - 1; + } + } + + public static function coord2cell($x, $y = null) + { + $c = ''; + for ($i = $x; $i >= 0; $i = ((int)($i / 26)) - 1) { + $c = chr(65 + $i % 26) . $c; + } + return $c . ($y === null ? '' : ($y + 1)); + } + +} diff --git a/vendor/shuchkin/simplexlsxgen/styles.png b/vendor/shuchkin/simplexlsxgen/styles.png new file mode 100644 index 00000000..f9cd4957 Binary files /dev/null and b/vendor/shuchkin/simplexlsxgen/styles.png differ