mirror of
https://github.com/shuchkin/simplexlsxgen.git
synced 2023-08-10 21:12:59 +03:00
Added Font Color
This commit is contained in:
parent
c55d77c63e
commit
ac34d8f527
@ -31,6 +31,7 @@ class SimpleXLSXGen {
|
|||||||
const F_ITALIC = 4;
|
const F_ITALIC = 4;
|
||||||
const F_UNDERLINE = 8;
|
const F_UNDERLINE = 8;
|
||||||
const F_STRIKE = 16;
|
const F_STRIKE = 16;
|
||||||
|
const C_NORMAL = 0;
|
||||||
const A_DEFAULT = 0;
|
const A_DEFAULT = 0;
|
||||||
const A_LEFT = 1;
|
const A_LEFT = 1;
|
||||||
const A_RIGHT = 2;
|
const A_RIGHT = 2;
|
||||||
@ -44,6 +45,9 @@ class SimpleXLSXGen {
|
|||||||
$this->SI_KEYS = []; // & keys
|
$this->SI_KEYS = []; // & keys
|
||||||
$this->F = [ self::F_NORMAL ]; // fonts
|
$this->F = [ self::F_NORMAL ]; // fonts
|
||||||
$this->F_KEYS = [0]; // & keys
|
$this->F_KEYS = [0]; // & keys
|
||||||
|
$this->C = [ self::C_NORMAL ]; //
|
||||||
|
$this->C_KEYS = [0]; // & keys
|
||||||
|
|
||||||
$this->XF = [ [self::N_NORMAL, self::F_NORMAL, self::A_DEFAULT] ]; // styles
|
$this->XF = [ [self::N_NORMAL, self::F_NORMAL, self::A_DEFAULT] ]; // styles
|
||||||
$this->XF_KEYS = ['N0F0A0' => 0 ]; // & keys
|
$this->XF_KEYS = ['N0F0A0' => 0 ]; // & keys
|
||||||
|
|
||||||
@ -295,14 +299,15 @@ class SimpleXLSXGen {
|
|||||||
$entries++;
|
$entries++;
|
||||||
} elseif ( $cfilename === 'xl/styles.xml' ) {
|
} elseif ( $cfilename === 'xl/styles.xml' ) {
|
||||||
$FONTS = ['<fonts count="'.count($this->F).'">'];
|
$FONTS = ['<fonts count="'.count($this->F).'">'];
|
||||||
foreach ( $this->F as $f ) {
|
foreach ( $this->F as $index => $f ) {
|
||||||
$FONTS[] = '<font><name val="'.$this->defaultFont.'"/><family val="2"/>'
|
$FONTS[] = '<font><name val="'.$this->defaultFont.'"/><family val="2"/>'
|
||||||
. ( $this->defaultFontSize ? '<sz val="'.$this->defaultFontSize.'"/>' : '' )
|
. ( $this->defaultFontSize ? '<sz val="'.$this->defaultFontSize.'"/>' : '' )
|
||||||
.( $f & self::F_BOLD ? '<b/>' : '')
|
.( $f & self::F_UNDERLINE ? '<b/>' : '')
|
||||||
.( $f & self::F_ITALIC ? '<i/>' : '')
|
.( $f & self::F_ITALIC ? '<i/>' : '')
|
||||||
.( $f & self::F_UNDERLINE ? '<u/>' : '')
|
.( $f & self::F_UNDERLINE ? '<u/>' : '')
|
||||||
.( $f & self::F_STRIKE ? '<strike/>' : '')
|
.( $f & self::F_STRIKE ? '<strike/>' : '')
|
||||||
.( $f & self::F_HYPERLINK ? '<color rgb="FF0563C1"/><u/>' : '')
|
.( $f & self::F_HYPERLINK ? '<color rgb="C2C2C2"/><u/>' : '')
|
||||||
|
.( isset($this->C[$index]) ? '<color rgb="'.$this->C[$index].'"/>' : '')
|
||||||
.'</font>';
|
.'</font>';
|
||||||
}
|
}
|
||||||
$FONTS[] = '</fonts>';
|
$FONTS[] = '</fonts>';
|
||||||
@ -448,7 +453,7 @@ class SimpleXLSXGen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$ct = $cv = null;
|
$ct = $cv = null;
|
||||||
$N = $F = $A = 0;
|
$N = $F = $A = $C = 0;
|
||||||
|
|
||||||
if ( is_string($v) ) {
|
if ( is_string($v) ) {
|
||||||
|
|
||||||
@ -469,6 +474,10 @@ class SimpleXLSXGen {
|
|||||||
if ( strpos( $v, '<s>' ) !== false ) {
|
if ( strpos( $v, '<s>' ) !== false ) {
|
||||||
$F += self::F_STRIKE;
|
$F += self::F_STRIKE;
|
||||||
}
|
}
|
||||||
|
if ( strpos( $v, '<color rgb' ) !== false ) {
|
||||||
|
preg_match('/(?<=<color rgb=").*?(?=")/', $v, $cValue);
|
||||||
|
$C = $cValue[0];
|
||||||
|
}
|
||||||
if ( strpos( $v, '<left>' ) !== false ) {
|
if ( strpos( $v, '<left>' ) !== false ) {
|
||||||
$A += self::A_LEFT;
|
$A += self::A_LEFT;
|
||||||
}
|
}
|
||||||
@ -582,6 +591,7 @@ class SimpleXLSXGen {
|
|||||||
$cf = count($this->F);
|
$cf = count($this->F);
|
||||||
$this->F_KEYS[$F] = $cf;
|
$this->F_KEYS[$F] = $cf;
|
||||||
$this->F[] = $F;
|
$this->F[] = $F;
|
||||||
|
$this->C[] = $C;
|
||||||
}
|
}
|
||||||
$NFA = 'N' . $N . 'F' . $cf . 'A' . $A;
|
$NFA = 'N' . $N . 'F' . $cf . 'A' . $A;
|
||||||
if ( isset( $this->XF_KEYS[ $NFA ] ) ) {
|
if ( isset( $this->XF_KEYS[ $NFA ] ) ) {
|
||||||
@ -689,4 +699,4 @@ class SimpleXLSXGen {
|
|||||||
// but we use fast version
|
// but we use fast version
|
||||||
return str_replace( ['&', '<', '>', "\x00","\x03","\x0B"], ['&', '<', '>', '', '', ''], $str );
|
return str_replace( ['&', '<', '>', "\x00","\x03","\x0B"], ['&', '<', '>', '', '', ''], $str );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user