diff --git a/README.md b/README.md
index 583e73e..42411c8 100644
--- a/README.md
+++ b/README.md
@@ -60,6 +60,9 @@ $data = [
['Italic', '12345.67'],
['Underline', '12345.67'],
['Strike', '12345.67'],
+ ['Green', ''],
+ ['Bold Red Text', ''],
+ ['Blue Text and Yellow Fill', ''],
['Bold + Italic', '12345.67'],
['Hyperlink', 'https://github.com/shuchkin/simplexlsxgen'],
['Italic + Hyperlink + Anchor', 'SimpleXLSXGen'],
diff --git a/src/SimpleXLSXGen.php b/src/SimpleXLSXGen.php
index 8809947..762b64f 100644
--- a/src/SimpleXLSXGen.php
+++ b/src/SimpleXLSXGen.php
@@ -16,6 +16,7 @@ class SimpleXLSXGen {
protected $template;
protected $F, $F_KEYS; // fonts
protected $XF, $XF_KEYS; // cellXfs
+ protected $B, $B_KEYS; // background fills
protected $SI, $SI_KEYS; // shared strings
const N_NORMAL = 0; // General
const N_INT = 1; // 0
@@ -31,6 +32,8 @@ class SimpleXLSXGen {
const F_ITALIC = 4;
const F_UNDERLINE = 8;
const F_STRIKE = 16;
+ const C_NORMAL = 0;
+ const B_NORMAL = 0;
const A_DEFAULT = 0;
const A_LEFT = 1;
const A_RIGHT = 2;
@@ -44,8 +47,10 @@ class SimpleXLSXGen {
$this->SI_KEYS = []; // & keys
$this->F = [ self::F_NORMAL ]; // fonts
$this->F_KEYS = [0]; // & keys
- $this->XF = [ [self::N_NORMAL, self::F_NORMAL, self::A_DEFAULT] ]; // styles
- $this->XF_KEYS = ['N0F0A0' => 0 ]; // & keys
+ $this->C = [ self::C_NORMAL ]; //
+ $this->B = [ self::B_NORMAL ]; //
+ $this->XF = [ [self::N_NORMAL, self::F_NORMAL, self::A_DEFAULT, self::C_NORMAL, self::B_NORMAL] ]; // styles
+ $this->XF_KEYS = ['N0F0A0C0B0' => 0 ]; // & keys
$this->template = [
'_rels/.rels' => '
@@ -80,7 +85,7 @@ class SimpleXLSXGen {
'xl/styles.xml' => '
{FONTS}
-
+{FILLS}
{XF}
@@ -295,14 +300,15 @@ class SimpleXLSXGen {
$entries++;
} elseif ( $cfilename === 'xl/styles.xml' ) {
$FONTS = [''];
- foreach ( $this->F as $f ) {
+ foreach ( $this->F as $index => $f ) {
$FONTS[] = ''
. ( $this->defaultFontSize ? '' : '' )
.( $f & self::F_BOLD ? '' : '')
.( $f & self::F_ITALIC ? '' : '')
.( $f & self::F_UNDERLINE ? '' : '')
.( $f & self::F_STRIKE ? '' : '')
- .( $f & self::F_HYPERLINK ? '' : '')
+ .( $f & self::F_HYPERLINK ? '' : '')
+ .( isset($this->C[$index]) ? '' : '')
.'';
}
$FONTS[] = '';
@@ -311,13 +317,22 @@ class SimpleXLSXGen {
$align = ($xf[2] === self::A_LEFT ? ' applyAlignment="1">' : '')
.($xf[2] === self::A_RIGHT ? ' applyAlignment="1">' : '')
.($xf[2] === self::A_CENTER ? ' applyAlignment="1">' : '');
- $XF[] = ' 0 ? ' applyNumberFormat="1"' : '')
.($align ? $align . '' : '/>');
}
$XF[] = '';
- $template = str_replace(['{FONTS}','{XF}'], [implode("\r\n", $FONTS), implode("\r\n", $XF)], $template);
+ $FILLS = [''];
+ foreach( $this->B as $fill){
+ if($fill===0){
+ $FILLS[] = '';
+ } else {
+ $FILLS[] = '';
+ }
+ }
+ $FILLS[] = '';
+ $template = str_replace(['{FONTS}','{XF}','{FILLS}'], [implode("\r\n", $FONTS), implode("\r\n", $XF), implode("\r\n", $FILLS)], $template);
$this->_writeEntry($fh, $cdrec, $cfilename, $template);
$entries++;
} else {
@@ -448,7 +463,7 @@ class SimpleXLSXGen {
}
$ct = $cv = null;
- $N = $F = $A = 0;
+ $N = $F = $A = $C = $B = 0;
if ( is_string($v) ) {
@@ -469,6 +484,16 @@ class SimpleXLSXGen {
if ( strpos( $v, '' ) !== false ) {
$F += self::F_STRIKE;
}
+ if ( strpos( $v, '