Xls writer improve styles (#2014)
* Extract 3 separate (duplicated) switch statements for mapping colours in conditional formatting rules into a single class * Replace switch statement with an array map for colour lookup * Eliminate duplicate colour map entries * Apply some stricter type checking * Extract Cell Data Validations * Extract Error Code mappings
This commit is contained in:
parent
3b8ef420ac
commit
557601f584
|
|
@ -4735,11 +4735,6 @@ parameters:
|
|||
count: 4
|
||||
path: src/PhpSpreadsheet/ReferenceHelper.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#2 \\$pPassword of method PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet\\:\\:protectCells\\(\\) expects string, array given\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/ReferenceHelper.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$index of method PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension\\:\\:setRowIndex\\(\\) expects int, string given\\.$#"
|
||||
count: 1
|
||||
|
|
@ -7405,16 +7400,6 @@ parameters:
|
|||
count: 1
|
||||
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#2 \\$height of method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xls\\\\Worksheet\\:\\:writeRow\\(\\) expects int, float given\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#4 \\$hidden of method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xls\\\\Worksheet\\:\\:writeRow\\(\\) expects bool, string given\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
|
||||
|
||||
-
|
||||
message: "#^Cannot call method getHashCode\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Font\\|null\\.$#"
|
||||
count: 1
|
||||
|
|
@ -7445,11 +7430,6 @@ parameters:
|
|||
count: 1
|
||||
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$hexadecimal_number of function hexdec expects string, array given\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$coordinates of static method PhpOffice\\\\PhpSpreadsheet\\\\Cell\\\\Coordinate\\:\\:indexesFromString\\(\\) expects string, string\\|null given\\.$#"
|
||||
count: 1
|
||||
|
|
@ -7550,26 +7530,6 @@ parameters:
|
|||
count: 1
|
||||
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$value of static method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\StringHelper\\:\\:UTF8toBIFF8UnicodeLong\\(\\) expects string, string\\|null given\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$fillType of static method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xls\\\\Xf\\:\\:mapFillType\\(\\) expects string, string\\|null given\\.$#"
|
||||
count: 2
|
||||
path: src/PhpSpreadsheet/Writer/Xls/Xf.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$hAlign of method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xls\\\\Xf\\:\\:mapHAlign\\(\\) expects string, string\\|null given\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Writer/Xls/Xf.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$vAlign of static method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xls\\\\Xf\\:\\:mapVAlign\\(\\) expects string, string\\|null given\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Writer/Xls/Xf.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$textRotation of static method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xls\\\\Xf\\:\\:mapTextRotation\\(\\) expects int, int\\|null given\\.$#"
|
||||
count: 1
|
||||
|
|
@ -8080,11 +8040,6 @@ parameters:
|
|||
count: 2
|
||||
path: src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#2 \\$value of method XMLWriter\\:\\:writeAttribute\\(\\) expects string, array given\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#2 \\$value of method XMLWriter\\:\\:writeAttribute\\(\\) expects string, array\\<string\\>\\|string given\\.$#"
|
||||
count: 2
|
||||
|
|
|
|||
|
|
@ -5,62 +5,62 @@ namespace PhpOffice\PhpSpreadsheet\Reader\Xls\Color;
|
|||
class BIFF8
|
||||
{
|
||||
protected static $map = [
|
||||
0x08 => '000000',
|
||||
0x09 => 'FFFFFF',
|
||||
0x0A => 'FF0000',
|
||||
0x0B => '00FF00',
|
||||
0x0C => '0000FF',
|
||||
0x0D => 'FFFF00',
|
||||
0x0E => 'FF00FF',
|
||||
0x0F => '00FFFF',
|
||||
0x10 => '800000',
|
||||
0x11 => '008000',
|
||||
0x12 => '000080',
|
||||
0x13 => '808000',
|
||||
0x14 => '800080',
|
||||
0x15 => '008080',
|
||||
0x16 => 'C0C0C0',
|
||||
0x17 => '808080',
|
||||
0x18 => '9999FF',
|
||||
0x19 => '993366',
|
||||
0x1A => 'FFFFCC',
|
||||
0x1B => 'CCFFFF',
|
||||
0x1C => '660066',
|
||||
0x1D => 'FF8080',
|
||||
0x1E => '0066CC',
|
||||
0x1F => 'CCCCFF',
|
||||
0x20 => '000080',
|
||||
0x21 => 'FF00FF',
|
||||
0x22 => 'FFFF00',
|
||||
0x23 => '00FFFF',
|
||||
0x24 => '800080',
|
||||
0x25 => '800000',
|
||||
0x26 => '008080',
|
||||
0x27 => '0000FF',
|
||||
0x28 => '00CCFF',
|
||||
0x29 => 'CCFFFF',
|
||||
0x2A => 'CCFFCC',
|
||||
0x2B => 'FFFF99',
|
||||
0x2C => '99CCFF',
|
||||
0x2D => 'FF99CC',
|
||||
0x2E => 'CC99FF',
|
||||
0x2F => 'FFCC99',
|
||||
0x30 => '3366FF',
|
||||
0x31 => '33CCCC',
|
||||
0x32 => '99CC00',
|
||||
0x33 => 'FFCC00',
|
||||
0x34 => 'FF9900',
|
||||
0x35 => 'FF6600',
|
||||
0x36 => '666699',
|
||||
0x37 => '969696',
|
||||
0x38 => '003366',
|
||||
0x39 => '339966',
|
||||
0x3A => '003300',
|
||||
0x3B => '333300',
|
||||
0x3C => '993300',
|
||||
0x3D => '993366',
|
||||
0x3E => '333399',
|
||||
0x3F => '333333',
|
||||
'000000' => 0x08,
|
||||
'FFFFFF' => 0x09,
|
||||
'FF0000' => 0x0A,
|
||||
'00FF00' => 0x0B,
|
||||
'0000FF' => 0x0C,
|
||||
'FFFF00' => 0x0D,
|
||||
'FF00FF' => 0x0E,
|
||||
'00FFFF' => 0x0F,
|
||||
'800000' => 0x10,
|
||||
'008000' => 0x11,
|
||||
'000080' => 0x12,
|
||||
'808000' => 0x13,
|
||||
'800080' => 0x14,
|
||||
'008080' => 0x15,
|
||||
'C0C0C0' => 0x16,
|
||||
'808080' => 0x17,
|
||||
'9999FF' => 0x18,
|
||||
'993366' => 0x19,
|
||||
'FFFFCC' => 0x1A,
|
||||
'CCFFFF' => 0x1B,
|
||||
'660066' => 0x1C,
|
||||
'FF8080' => 0x1D,
|
||||
'0066CC' => 0x1E,
|
||||
'CCCCFF' => 0x1F,
|
||||
// '000080' => 0x20,
|
||||
// 'FF00FF' => 0x21,
|
||||
// 'FFFF00' => 0x22,
|
||||
// '00FFFF' => 0x23,
|
||||
// '800080' => 0x24,
|
||||
// '800000' => 0x25,
|
||||
// '008080' => 0x26,
|
||||
// '0000FF' => 0x27,
|
||||
'00CCFF' => 0x28,
|
||||
// 'CCFFFF' => 0x29,
|
||||
'CCFFCC' => 0x2A,
|
||||
'FFFF99' => 0x2B,
|
||||
'99CCFF' => 0x2C,
|
||||
'FF99CC' => 0x2D,
|
||||
'CC99FF' => 0x2E,
|
||||
'FFCC99' => 0x2F,
|
||||
'3366FF' => 0x30,
|
||||
'33CCCC' => 0x31,
|
||||
'99CC00' => 0x32,
|
||||
'FFCC00' => 0x33,
|
||||
'FF9900' => 0x34,
|
||||
'FF6600' => 0x35,
|
||||
'666699' => 0x36,
|
||||
'969696' => 0x37,
|
||||
'003366' => 0x38,
|
||||
'339966' => 0x39,
|
||||
'003300' => 0x3A,
|
||||
'333300' => 0x3B,
|
||||
'993300' => 0x3C,
|
||||
// '993366' => 0x3D,
|
||||
'333399' => 0x3E,
|
||||
'333333' => 0x3F,
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -194,7 +194,7 @@ class Worksheet implements IComparable
|
|||
/**
|
||||
* Collection of protected cell ranges.
|
||||
*
|
||||
* @var array
|
||||
* @var string[]
|
||||
*/
|
||||
private $protectedCells = [];
|
||||
|
||||
|
|
@ -1871,7 +1871,7 @@ class Worksheet implements IComparable
|
|||
/**
|
||||
* Get protected cells.
|
||||
*
|
||||
* @return array[]
|
||||
* @return string[]
|
||||
*/
|
||||
public function getProtectedCells()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheet\Writer\Xls;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Cell\DataValidation;
|
||||
|
||||
class CellDataValidation
|
||||
{
|
||||
/**
|
||||
* @var array<string, int>
|
||||
*/
|
||||
protected static $validationTypeMap = [
|
||||
DataValidation::TYPE_NONE => 0x00,
|
||||
DataValidation::TYPE_WHOLE => 0x01,
|
||||
DataValidation::TYPE_DECIMAL => 0x02,
|
||||
DataValidation::TYPE_LIST => 0x03,
|
||||
DataValidation::TYPE_DATE => 0x04,
|
||||
DataValidation::TYPE_TIME => 0x05,
|
||||
DataValidation::TYPE_TEXTLENGTH => 0x06,
|
||||
DataValidation::TYPE_CUSTOM => 0x07,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array<string, int>
|
||||
*/
|
||||
protected static $errorStyleMap = [
|
||||
DataValidation::STYLE_STOP => 0x00,
|
||||
DataValidation::STYLE_WARNING => 0x01,
|
||||
DataValidation::STYLE_INFORMATION => 0x02,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array<string, int>
|
||||
*/
|
||||
protected static $operatorMap = [
|
||||
DataValidation::OPERATOR_BETWEEN => 0x00,
|
||||
DataValidation::OPERATOR_NOTBETWEEN => 0x01,
|
||||
DataValidation::OPERATOR_EQUAL => 0x02,
|
||||
DataValidation::OPERATOR_NOTEQUAL => 0x03,
|
||||
DataValidation::OPERATOR_GREATERTHAN => 0x04,
|
||||
DataValidation::OPERATOR_LESSTHAN => 0x05,
|
||||
DataValidation::OPERATOR_GREATERTHANOREQUAL => 0x06,
|
||||
DataValidation::OPERATOR_LESSTHANOREQUAL => 0x07,
|
||||
];
|
||||
|
||||
public static function type(DataValidation $dataValidation): int
|
||||
{
|
||||
$validationType = $dataValidation->getType();
|
||||
|
||||
if (is_string($validationType) && array_key_exists($validationType, self::$validationTypeMap)) {
|
||||
return self::$validationTypeMap[$validationType];
|
||||
}
|
||||
|
||||
return self::$validationTypeMap[DataValidation::TYPE_NONE];
|
||||
}
|
||||
|
||||
public static function errorStyle(DataValidation $dataValidation): int
|
||||
{
|
||||
$errorStyle = $dataValidation->getErrorStyle();
|
||||
|
||||
if (is_string($errorStyle) && array_key_exists($errorStyle, self::$errorStyleMap)) {
|
||||
return self::$errorStyleMap[$errorStyle];
|
||||
}
|
||||
|
||||
return self::$errorStyleMap[DataValidation::STYLE_STOP];
|
||||
}
|
||||
|
||||
public static function operator(DataValidation $dataValidation): int
|
||||
{
|
||||
$operator = $dataValidation->getOperator();
|
||||
|
||||
if (is_string($operator) && array_key_exists($operator, self::$operatorMap)) {
|
||||
return self::$operatorMap[$operator];
|
||||
}
|
||||
|
||||
return self::$operatorMap[DataValidation::OPERATOR_BETWEEN];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheet\Writer\Xls;
|
||||
|
||||
class ErrorCode
|
||||
{
|
||||
/**
|
||||
* @var array<string, int>
|
||||
*/
|
||||
protected static $errorCodeMap = [
|
||||
'#NULL!' => 0x00,
|
||||
'#DIV/0!' => 0x07,
|
||||
'#VALUE!' => 0x0F,
|
||||
'#REF!' => 0x17,
|
||||
'#NAME?' => 0x1D,
|
||||
'#NUM!' => 0x24,
|
||||
'#N/A' => 0x2A,
|
||||
];
|
||||
|
||||
public static function error(string $errorCode): int
|
||||
{
|
||||
if (array_key_exists($errorCode, self::$errorCodeMap)) {
|
||||
return self::$errorCodeMap[$errorCode];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheet\Writer\Xls\Style;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
||||
|
||||
class CellAlignment
|
||||
{
|
||||
/**
|
||||
* @var array<string, int>
|
||||
*/
|
||||
private static $horizontalMap = [
|
||||
Alignment::HORIZONTAL_GENERAL => 0,
|
||||
Alignment::HORIZONTAL_LEFT => 1,
|
||||
Alignment::HORIZONTAL_RIGHT => 3,
|
||||
Alignment::HORIZONTAL_CENTER => 2,
|
||||
Alignment::HORIZONTAL_CENTER_CONTINUOUS => 6,
|
||||
Alignment::HORIZONTAL_JUSTIFY => 5,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array<string, int>
|
||||
*/
|
||||
private static $verticalMap = [
|
||||
Alignment::VERTICAL_BOTTOM => 2,
|
||||
Alignment::VERTICAL_TOP => 0,
|
||||
Alignment::VERTICAL_CENTER => 1,
|
||||
Alignment::VERTICAL_JUSTIFY => 3,
|
||||
];
|
||||
|
||||
public static function horizontal(Alignment $alignment): int
|
||||
{
|
||||
$horizontalAlignment = $alignment->getHorizontal();
|
||||
|
||||
if (is_string($horizontalAlignment) && array_key_exists($horizontalAlignment, self::$horizontalMap)) {
|
||||
return self::$horizontalMap[$horizontalAlignment];
|
||||
}
|
||||
|
||||
return self::$horizontalMap[Alignment::HORIZONTAL_GENERAL];
|
||||
}
|
||||
|
||||
public static function wrap(Alignment $alignment): int
|
||||
{
|
||||
$wrap = $alignment->getWrapText();
|
||||
|
||||
return ($wrap === true) ? 1 : 0;
|
||||
}
|
||||
|
||||
public static function vertical(Alignment $alignment): int
|
||||
{
|
||||
$verticalAlignment = $alignment->getVertical();
|
||||
|
||||
if (is_string($verticalAlignment) && array_key_exists($verticalAlignment, self::$verticalMap)) {
|
||||
return self::$verticalMap[$verticalAlignment];
|
||||
}
|
||||
|
||||
return self::$verticalMap[Alignment::VERTICAL_BOTTOM];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheet\Writer\Xls\Style;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Style\Border;
|
||||
|
||||
class CellBorder
|
||||
{
|
||||
/**
|
||||
* @var array<string, int>
|
||||
*/
|
||||
protected static $styleMap = [
|
||||
Border::BORDER_NONE => 0x00,
|
||||
Border::BORDER_THIN => 0x01,
|
||||
Border::BORDER_MEDIUM => 0x02,
|
||||
Border::BORDER_DASHED => 0x03,
|
||||
Border::BORDER_DOTTED => 0x04,
|
||||
Border::BORDER_THICK => 0x05,
|
||||
Border::BORDER_DOUBLE => 0x06,
|
||||
Border::BORDER_HAIR => 0x07,
|
||||
Border::BORDER_MEDIUMDASHED => 0x08,
|
||||
Border::BORDER_DASHDOT => 0x09,
|
||||
Border::BORDER_MEDIUMDASHDOT => 0x0A,
|
||||
Border::BORDER_DASHDOTDOT => 0x0B,
|
||||
Border::BORDER_MEDIUMDASHDOTDOT => 0x0C,
|
||||
Border::BORDER_SLANTDASHDOT => 0x0D,
|
||||
];
|
||||
|
||||
public static function style(Border $border): int
|
||||
{
|
||||
$borderStyle = $border->getBorderStyle();
|
||||
|
||||
if (is_string($borderStyle) && array_key_exists($borderStyle, self::$styleMap)) {
|
||||
return self::$styleMap[$borderStyle];
|
||||
}
|
||||
|
||||
return self::$styleMap[Border::BORDER_NONE];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheet\Writer\Xls\Style;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Style\Fill;
|
||||
|
||||
class CellFill
|
||||
{
|
||||
/**
|
||||
* @var array<string, int>
|
||||
*/
|
||||
protected static $fillStyleMap = [
|
||||
Fill::FILL_NONE => 0x00,
|
||||
Fill::FILL_SOLID => 0x01,
|
||||
Fill::FILL_PATTERN_MEDIUMGRAY => 0x02,
|
||||
Fill::FILL_PATTERN_DARKGRAY => 0x03,
|
||||
Fill::FILL_PATTERN_LIGHTGRAY => 0x04,
|
||||
Fill::FILL_PATTERN_DARKHORIZONTAL => 0x05,
|
||||
Fill::FILL_PATTERN_DARKVERTICAL => 0x06,
|
||||
Fill::FILL_PATTERN_DARKDOWN => 0x07,
|
||||
Fill::FILL_PATTERN_DARKUP => 0x08,
|
||||
Fill::FILL_PATTERN_DARKGRID => 0x09,
|
||||
Fill::FILL_PATTERN_DARKTRELLIS => 0x0A,
|
||||
Fill::FILL_PATTERN_LIGHTHORIZONTAL => 0x0B,
|
||||
Fill::FILL_PATTERN_LIGHTVERTICAL => 0x0C,
|
||||
Fill::FILL_PATTERN_LIGHTDOWN => 0x0D,
|
||||
Fill::FILL_PATTERN_LIGHTUP => 0x0E,
|
||||
Fill::FILL_PATTERN_LIGHTGRID => 0x0F,
|
||||
Fill::FILL_PATTERN_LIGHTTRELLIS => 0x10,
|
||||
Fill::FILL_PATTERN_GRAY125 => 0x11,
|
||||
Fill::FILL_PATTERN_GRAY0625 => 0x12,
|
||||
Fill::FILL_GRADIENT_LINEAR => 0x00, // does not exist in BIFF8
|
||||
Fill::FILL_GRADIENT_PATH => 0x00, // does not exist in BIFF8
|
||||
];
|
||||
|
||||
public static function style(Fill $fill): int
|
||||
{
|
||||
$fillStyle = $fill->getFillType();
|
||||
|
||||
if (is_string($fillStyle) && array_key_exists($fillStyle, self::$fillStyleMap)) {
|
||||
return self::$fillStyleMap[$fillStyle];
|
||||
}
|
||||
|
||||
return self::$fillStyleMap[Fill::FILL_NONE];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheet\Writer\Xls\Style;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Style\Color;
|
||||
|
||||
class ColorMap
|
||||
{
|
||||
/**
|
||||
* @var array<string, int>
|
||||
*/
|
||||
private static $colorMap = [
|
||||
'#000000' => 0x08,
|
||||
'#FFFFFF' => 0x09,
|
||||
'#FF0000' => 0x0A,
|
||||
'#00FF00' => 0x0B,
|
||||
'#0000FF' => 0x0C,
|
||||
'#FFFF00' => 0x0D,
|
||||
'#FF00FF' => 0x0E,
|
||||
'#00FFFF' => 0x0F,
|
||||
'#800000' => 0x10,
|
||||
'#008000' => 0x11,
|
||||
'#000080' => 0x12,
|
||||
'#808000' => 0x13,
|
||||
'#800080' => 0x14,
|
||||
'#008080' => 0x15,
|
||||
'#C0C0C0' => 0x16,
|
||||
'#808080' => 0x17,
|
||||
'#9999FF' => 0x18,
|
||||
'#993366' => 0x19,
|
||||
'#FFFFCC' => 0x1A,
|
||||
'#CCFFFF' => 0x1B,
|
||||
'#660066' => 0x1C,
|
||||
'#FF8080' => 0x1D,
|
||||
'#0066CC' => 0x1E,
|
||||
'#CCCCFF' => 0x1F,
|
||||
// '#000080' => 0x20,
|
||||
// '#FF00FF' => 0x21,
|
||||
// '#FFFF00' => 0x22,
|
||||
// '#00FFFF' => 0x23,
|
||||
// '#800080' => 0x24,
|
||||
// '#800000' => 0x25,
|
||||
// '#008080' => 0x26,
|
||||
// '#0000FF' => 0x27,
|
||||
'#00CCFF' => 0x28,
|
||||
// '#CCFFFF' => 0x29,
|
||||
'#CCFFCC' => 0x2A,
|
||||
'#FFFF99' => 0x2B,
|
||||
'#99CCFF' => 0x2C,
|
||||
'#FF99CC' => 0x2D,
|
||||
'#CC99FF' => 0x2E,
|
||||
'#FFCC99' => 0x2F,
|
||||
'#3366FF' => 0x30,
|
||||
'#33CCCC' => 0x31,
|
||||
'#99CC00' => 0x32,
|
||||
'#FFCC00' => 0x33,
|
||||
'#FF9900' => 0x34,
|
||||
'#FF6600' => 0x35,
|
||||
'#666699' => 0x36,
|
||||
'#969696' => 0x37,
|
||||
'#003366' => 0x38,
|
||||
'#339966' => 0x39,
|
||||
'#003300' => 0x3A,
|
||||
'#333300' => 0x3B,
|
||||
'#993300' => 0x3C,
|
||||
// '#993366' => 0x3D,
|
||||
'#333399' => 0x3E,
|
||||
'#333333' => 0x3F,
|
||||
];
|
||||
|
||||
public static function lookup(Color $color, int $defaultIndex = 0x00): int
|
||||
{
|
||||
$colorRgb = $color->getRGB();
|
||||
if (is_string($colorRgb) && array_key_exists("#{$colorRgb}", self::$colorMap)) {
|
||||
return self::$colorMap["#{$colorRgb}"];
|
||||
}
|
||||
|
||||
return $defaultIndex;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -3,11 +3,12 @@
|
|||
namespace PhpOffice\PhpSpreadsheet\Writer\Xls;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Border;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Borders;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Fill;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Protection;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Style;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Xls\Style\CellAlignment;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Xls\Style\CellBorder;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Xls\Style\CellFill;
|
||||
|
||||
// Original file header of PEAR::Spreadsheet_Excel_Writer_Format (used as the base for this class):
|
||||
// -----------------------------------------------------------------------------------------
|
||||
|
|
@ -176,30 +177,30 @@ class Xf
|
|||
$atr_num = ($this->numberFormatIndex != 0) ? 1 : 0;
|
||||
$atr_fnt = ($this->fontIndex != 0) ? 1 : 0;
|
||||
$atr_alc = ((int) $this->style->getAlignment()->getWrapText()) ? 1 : 0;
|
||||
$atr_bdr = (self::mapBorderStyle($this->style->getBorders()->getBottom()->getBorderStyle()) ||
|
||||
self::mapBorderStyle($this->style->getBorders()->getTop()->getBorderStyle()) ||
|
||||
self::mapBorderStyle($this->style->getBorders()->getLeft()->getBorderStyle()) ||
|
||||
self::mapBorderStyle($this->style->getBorders()->getRight()->getBorderStyle())) ? 1 : 0;
|
||||
$atr_bdr = (CellBorder::style($this->style->getBorders()->getBottom()) ||
|
||||
CellBorder::style($this->style->getBorders()->getTop()) ||
|
||||
CellBorder::style($this->style->getBorders()->getLeft()) ||
|
||||
CellBorder::style($this->style->getBorders()->getRight())) ? 1 : 0;
|
||||
$atr_pat = ($this->foregroundColor != 0x40) ? 1 : 0;
|
||||
$atr_pat = ($this->backgroundColor != 0x41) ? 1 : $atr_pat;
|
||||
$atr_pat = self::mapFillType($this->style->getFill()->getFillType()) ? 1 : $atr_pat;
|
||||
$atr_pat = CellFill::style($this->style->getFill()) ? 1 : $atr_pat;
|
||||
$atr_prot = self::mapLocked($this->style->getProtection()->getLocked())
|
||||
| self::mapHidden($this->style->getProtection()->getHidden());
|
||||
|
||||
// Zero the default border colour if the border has not been set.
|
||||
if (self::mapBorderStyle($this->style->getBorders()->getBottom()->getBorderStyle()) == 0) {
|
||||
if (CellBorder::style($this->style->getBorders()->getBottom()) == 0) {
|
||||
$this->bottomBorderColor = 0;
|
||||
}
|
||||
if (self::mapBorderStyle($this->style->getBorders()->getTop()->getBorderStyle()) == 0) {
|
||||
if (CellBorder::style($this->style->getBorders()->getTop()) == 0) {
|
||||
$this->topBorderColor = 0;
|
||||
}
|
||||
if (self::mapBorderStyle($this->style->getBorders()->getRight()->getBorderStyle()) == 0) {
|
||||
if (CellBorder::style($this->style->getBorders()->getRight()) == 0) {
|
||||
$this->rightBorderColor = 0;
|
||||
}
|
||||
if (self::mapBorderStyle($this->style->getBorders()->getLeft()->getBorderStyle()) == 0) {
|
||||
if (CellBorder::style($this->style->getBorders()->getLeft()) == 0) {
|
||||
$this->leftBorderColor = 0;
|
||||
}
|
||||
if (self::mapBorderStyle($this->style->getBorders()->getDiagonal()->getBorderStyle()) == 0) {
|
||||
if (CellBorder::style($this->style->getBorders()->getDiagonal()) == 0) {
|
||||
$this->diagColor = 0;
|
||||
}
|
||||
|
||||
|
|
@ -209,9 +210,10 @@ class Xf
|
|||
$ifnt = $this->fontIndex; // Index to FONT record
|
||||
$ifmt = $this->numberFormatIndex; // Index to FORMAT record
|
||||
|
||||
$align = $this->mapHAlign($this->style->getAlignment()->getHorizontal()); // Alignment
|
||||
$align |= (int) $this->style->getAlignment()->getWrapText() << 3;
|
||||
$align |= self::mapVAlign($this->style->getAlignment()->getVertical()) << 4;
|
||||
// Alignment
|
||||
$align = CellAlignment::horizontal($this->style->getAlignment());
|
||||
$align |= CellAlignment::wrap($this->style->getAlignment()) << 3;
|
||||
$align |= CellAlignment::vertical($this->style->getAlignment()) << 4;
|
||||
$align |= $this->textJustLast << 7;
|
||||
|
||||
$used_attrib = $atr_num << 2;
|
||||
|
|
@ -224,10 +226,10 @@ class Xf
|
|||
$icv = $this->foregroundColor; // fg and bg pattern colors
|
||||
$icv |= $this->backgroundColor << 7;
|
||||
|
||||
$border1 = self::mapBorderStyle($this->style->getBorders()->getLeft()->getBorderStyle()); // Border line style and color
|
||||
$border1 |= self::mapBorderStyle($this->style->getBorders()->getRight()->getBorderStyle()) << 4;
|
||||
$border1 |= self::mapBorderStyle($this->style->getBorders()->getTop()->getBorderStyle()) << 8;
|
||||
$border1 |= self::mapBorderStyle($this->style->getBorders()->getBottom()->getBorderStyle()) << 12;
|
||||
$border1 = CellBorder::style($this->style->getBorders()->getLeft()); // Border line style and color
|
||||
$border1 |= CellBorder::style($this->style->getBorders()->getRight()) << 4;
|
||||
$border1 |= CellBorder::style($this->style->getBorders()->getTop()) << 8;
|
||||
$border1 |= CellBorder::style($this->style->getBorders()->getBottom()) << 12;
|
||||
$border1 |= $this->leftBorderColor << 16;
|
||||
$border1 |= $this->rightBorderColor << 23;
|
||||
|
||||
|
|
@ -242,8 +244,8 @@ class Xf
|
|||
$border2 = $this->topBorderColor; // Border color
|
||||
$border2 |= $this->bottomBorderColor << 7;
|
||||
$border2 |= $this->diagColor << 14;
|
||||
$border2 |= self::mapBorderStyle($this->style->getBorders()->getDiagonal()->getBorderStyle()) << 21;
|
||||
$border2 |= self::mapFillType($this->style->getFill()->getFillType()) << 26;
|
||||
$border2 |= CellBorder::style($this->style->getBorders()->getDiagonal()) << 21;
|
||||
$border2 |= CellFill::style($this->style->getFill()) << 26;
|
||||
|
||||
$header = pack('vv', $record, $length);
|
||||
|
||||
|
|
@ -359,132 +361,6 @@ class Xf
|
|||
$this->fontIndex = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Map of BIFF2-BIFF8 codes for border styles.
|
||||
*
|
||||
* @var int[]
|
||||
*/
|
||||
private static $mapBorderStyles = [
|
||||
Border::BORDER_NONE => 0x00,
|
||||
Border::BORDER_THIN => 0x01,
|
||||
Border::BORDER_MEDIUM => 0x02,
|
||||
Border::BORDER_DASHED => 0x03,
|
||||
Border::BORDER_DOTTED => 0x04,
|
||||
Border::BORDER_THICK => 0x05,
|
||||
Border::BORDER_DOUBLE => 0x06,
|
||||
Border::BORDER_HAIR => 0x07,
|
||||
Border::BORDER_MEDIUMDASHED => 0x08,
|
||||
Border::BORDER_DASHDOT => 0x09,
|
||||
Border::BORDER_MEDIUMDASHDOT => 0x0A,
|
||||
Border::BORDER_DASHDOTDOT => 0x0B,
|
||||
Border::BORDER_MEDIUMDASHDOTDOT => 0x0C,
|
||||
Border::BORDER_SLANTDASHDOT => 0x0D,
|
||||
];
|
||||
|
||||
/**
|
||||
* Map border style.
|
||||
*
|
||||
* @param string $borderStyle
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private static function mapBorderStyle($borderStyle)
|
||||
{
|
||||
return self::$mapBorderStyles[$borderStyle] ?? 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Map of BIFF2-BIFF8 codes for fill types.
|
||||
*
|
||||
* @var int[]
|
||||
*/
|
||||
private static $mapFillTypes = [
|
||||
Fill::FILL_NONE => 0x00,
|
||||
Fill::FILL_SOLID => 0x01,
|
||||
Fill::FILL_PATTERN_MEDIUMGRAY => 0x02,
|
||||
Fill::FILL_PATTERN_DARKGRAY => 0x03,
|
||||
Fill::FILL_PATTERN_LIGHTGRAY => 0x04,
|
||||
Fill::FILL_PATTERN_DARKHORIZONTAL => 0x05,
|
||||
Fill::FILL_PATTERN_DARKVERTICAL => 0x06,
|
||||
Fill::FILL_PATTERN_DARKDOWN => 0x07,
|
||||
Fill::FILL_PATTERN_DARKUP => 0x08,
|
||||
Fill::FILL_PATTERN_DARKGRID => 0x09,
|
||||
Fill::FILL_PATTERN_DARKTRELLIS => 0x0A,
|
||||
Fill::FILL_PATTERN_LIGHTHORIZONTAL => 0x0B,
|
||||
Fill::FILL_PATTERN_LIGHTVERTICAL => 0x0C,
|
||||
Fill::FILL_PATTERN_LIGHTDOWN => 0x0D,
|
||||
Fill::FILL_PATTERN_LIGHTUP => 0x0E,
|
||||
Fill::FILL_PATTERN_LIGHTGRID => 0x0F,
|
||||
Fill::FILL_PATTERN_LIGHTTRELLIS => 0x10,
|
||||
Fill::FILL_PATTERN_GRAY125 => 0x11,
|
||||
Fill::FILL_PATTERN_GRAY0625 => 0x12,
|
||||
Fill::FILL_GRADIENT_LINEAR => 0x00, // does not exist in BIFF8
|
||||
Fill::FILL_GRADIENT_PATH => 0x00, // does not exist in BIFF8
|
||||
];
|
||||
|
||||
/**
|
||||
* Map fill type.
|
||||
*
|
||||
* @param string $fillType
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private static function mapFillType($fillType)
|
||||
{
|
||||
return self::$mapFillTypes[$fillType] ?? 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Map of BIFF2-BIFF8 codes for horizontal alignment.
|
||||
*
|
||||
* @var int[]
|
||||
*/
|
||||
private static $mapHAlignments = [
|
||||
Alignment::HORIZONTAL_GENERAL => 0,
|
||||
Alignment::HORIZONTAL_LEFT => 1,
|
||||
Alignment::HORIZONTAL_CENTER => 2,
|
||||
Alignment::HORIZONTAL_RIGHT => 3,
|
||||
Alignment::HORIZONTAL_FILL => 4,
|
||||
Alignment::HORIZONTAL_JUSTIFY => 5,
|
||||
Alignment::HORIZONTAL_CENTER_CONTINUOUS => 6,
|
||||
];
|
||||
|
||||
/**
|
||||
* Map to BIFF2-BIFF8 codes for horizontal alignment.
|
||||
*
|
||||
* @param string $hAlign
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private function mapHAlign($hAlign)
|
||||
{
|
||||
return self::$mapHAlignments[$hAlign] ?? 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Map of BIFF2-BIFF8 codes for vertical alignment.
|
||||
*
|
||||
* @var int[]
|
||||
*/
|
||||
private static $mapVAlignments = [
|
||||
Alignment::VERTICAL_TOP => 0,
|
||||
Alignment::VERTICAL_CENTER => 1,
|
||||
Alignment::VERTICAL_BOTTOM => 2,
|
||||
Alignment::VERTICAL_JUSTIFY => 3,
|
||||
];
|
||||
|
||||
/**
|
||||
* Map to BIFF2-BIFF8 codes for vertical alignment.
|
||||
*
|
||||
* @param string $vAlign
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private static function mapVAlign($vAlign)
|
||||
{
|
||||
return self::$mapVAlignments[$vAlign] ?? 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Map to BIFF8 codes for text rotation angle.
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue