From 7ac28e0048b270f62ebc4e89daff78c35e5f4bc7 Mon Sep 17 00:00:00 2001
From: "lewa::cpan.org" <lewa@users.noreply.github.com>
Date: Mon, 10 Jul 2017 17:08:33 +0300
Subject: [PATCH] border-style and border-color support

---
 README.md            | 22 ++++++++++++----------
 xlsxwriter.class.php | 28 ++++++++++++++++++++++------
 2 files changed, 34 insertions(+), 16 deletions(-)

diff --git a/README.md b/README.md
index 26de6ae..1dee4a1 100644
--- a/README.md
+++ b/README.md
@@ -83,15 +83,17 @@ Simple cell formats map to more advanced cell formats
 
 Basic cell styles have been available since version 0.30
 
-| style      | allowed values |
-| ---------- | ---- |
-| font       | Arial, Times New Roman, Courier New, Comic Sans MS |
-| font-size  | 8,9,10,11,12 ... |
-| font-style | bold, italic, underline, strikethrough or multiple ie: 'bold,italic' |
-| border     | left, right, top, bottom,   or multiple ie: 'top,left' |
-| color      | #RRGGBB, ie: #ff99cc or #f9c |
-| fill       | #RRGGBB, ie: #eeffee or #efe |
-| halign     | general, left, right, justify, center |
-| valign     | bottom, center, distributed |
+| style        | allowed values |
+| ------------ | ---- |
+| font         | Arial, Times New Roman, Courier New, Comic Sans MS |
+| font-size    | 8,9,10,11,12 ... |
+| font-style   | bold, italic, underline, strikethrough or multiple ie: 'bold,italic' |
+| border       | left, right, top, bottom,   or multiple ie: 'top,left' |
+| border-style | thin, medium, thick, dashDot, dashDotDot, dashed, dotted, double, hair, mediumDashDot, mediumDashDotDot, mediumDashed, slantDashDot |
+| border-color | #RRGGBB, ie: #ff99cc or #f9c |
+| color        | #RRGGBB, ie: #ff99cc or #f9c |
+| fill         | #RRGGBB, ie: #eeffee or #efe |
+| halign       | general, left, right, justify, center |
+| valign       | bottom, center, distributed |
 
 
diff --git a/xlsxwriter.class.php b/xlsxwriter.class.php
index a3a97cd..2a9701d 100644
--- a/xlsxwriter.class.php
+++ b/xlsxwriter.class.php
@@ -312,6 +312,7 @@ class XLSXWriter
 	protected function styleFontIndexes()
 	{
 		static $border_allowed = array('left','right','top','bottom');
+		static $border_style_allowed = array('thin','medium','thick','dashDot','dashDotDot','dashed','dotted','double','hair','mediumDashDot','mediumDashDotDot','mediumDashed','slantDashDot');
 		static $horizontal_allowed = array('general','left','right','justify','center');
 		static $vertical_allowed = array('bottom','center','distributed');
 		$default_font = array('size'=>'10','name'=>'Arial','family'=>'2');
@@ -332,7 +333,17 @@ class XLSXWriter
 				$border_input = explode(",", $style['border']);
 				sort($border_input);
 				$border_value = array_intersect($border_input, $border_allowed);
-				$style_indexes[$i]['border_idx'] = self::add_to_list_get_index($borders, implode(",", $border_value) );
+				if (isset($style['border-style']) && in_array($style['border-style'],$border_style_allowed))
+				{
+					$border_value['style'] = $style['border-style'];
+				}
+				if (isset($style['border-color']) && is_string($style['border-color']) && $style['border-color'][0]=='#')
+				{
+					$v = substr($style['border-color'],1,6);
+					$v = strlen($v)==3 ? $v[0].$v[0].$v[1].$v[1].$v[2].$v[2] : $v;// expand cf0 => ccff00
+					$border_value['color'] = "FF".strtoupper($v);
+				}
+				$style_indexes[$i]['border_idx'] = self::add_to_list_get_index($borders, json_encode($border_value));
 			}
 			if (isset($style['fill']) && is_string($style['fill']) && $style['fill'][0]=='#')
 			{
@@ -442,12 +453,17 @@ class XLSXWriter
         $file->write(    '<border diagonalDown="false" diagonalUp="false"><left/><right/><top/><bottom/><diagonal/></border>');
 		foreach($borders as $border) {
 			if (!empty($border)) { //fonts have an empty placeholder in the array to offset the static xml entry above
-				$pieces = explode(",", $border);
+				$pieces = json_decode($border,true);
+				$border_style = !empty($pieces['style']) ? $pieces['style'] : 'hair';
 				$file->write('<border diagonalDown="false" diagonalUp="false">');
-				$file->write(  '<left'.(in_array('left',$pieces) ? ' style="hair"' : '').'/>');
-				$file->write(  '<right'.(in_array('right',$pieces) ? ' style="hair"' : '').'/>');
-				$file->write(  '<top'.(in_array('top',$pieces) ? ' style="hair"' : '').'/>');
-				$file->write(  '<bottom'.(in_array('bottom',$pieces) ? ' style="hair"' : '').'/>');
+				foreach (array('left', 'right', 'top', 'bottom') as $side)
+				{
+					$file->write('<'.$side.(in_array($side,$pieces) ? ' style="'.$border_style.'"' : '').'>');
+					if (!empty($pieces['color'])) {
+						$file->write('<color rgb="'.strval($pieces['color']).'"/>');
+					}
+					$file->write('</'.$side.'>');
+				}
 				$file->write(  '<diagonal/>');
 				$file->write('</border>');
 			}
-- 
GitLab