Browse Source

Merge pull request #99 from sirwart/bold-italic-underline

Expose various cell & font style attributes
Geoffrey J. Teale 10 years ago
parent
commit
2835290700
2 changed files with 32 additions and 6 deletions
  1. 13 5
      style.go
  2. 19 1
      xmlStyle.go

+ 13 - 5
style.go

@@ -11,6 +11,7 @@ type Style struct {
 	ApplyBorder bool
 	ApplyFill   bool
 	ApplyFont   bool
+	Alignment   Alignment
 }
 
 // Return a new Style structure initialised with the default values.
@@ -80,17 +81,24 @@ func NewFill(patternType, fgColor, bgColor string) *Fill {
 }
 
 type Font struct {
-	Size    int
-	Name    string
-	Family  int
-	Charset int
-	Color   string
+	Size      int
+	Name      string
+	Family    int
+	Charset   int
+	Color     string
+	Bold      bool
+	Italic    bool
+	Underline bool
 }
 
 func NewFont(size int, name string) *Font {
 	return &Font{Size: size, Name: name}
 }
 
+type Alignment struct {
+	Horizontal string
+}
+
 func DefaulFont() *Font {
 	return NewFont(12, "Verdana")
 }

+ 19 - 1
xmlStyle.go

@@ -101,13 +101,26 @@ func (styles *xlsxStyleSheet) getStyle(styleIndex int) (style *Style) {
 			style.Font.Name = xfont.Name.Val
 			style.Font.Family, _ = strconv.Atoi(xfont.Family.Val)
 			style.Font.Charset, _ = strconv.Atoi(xfont.Charset.Val)
+			style.Font.Color = xfont.Color.RGB
+
+			if xfont.B != nil {
+				style.Font.Bold = true
+			}
+			if xfont.I != nil {
+				style.Font.Italic = true
+			}
+			if xfont.U != nil {
+				style.Font.Underline = true
+			}
+		}
+		if xf.Alignment.Horizontal != "" {
+			style.Alignment.Horizontal = xf.Alignment.Horizontal
 		}
 		styles.lock.Lock()
 		styles.styleCache[styleIndex] = style
 		styles.lock.Unlock()
 	}
 	return style
-
 }
 
 // Excel styles can reference number formats that are built-in, all of which
@@ -153,6 +166,8 @@ func getBuiltinNumberFormat(numFmtId int) string {
 		return "m/d/yy h:mm"
 	case 37:
 		return "#,##0 ;(#,##0)"
+	case 38:
+		return "#,##0 ;[Red](#,##0)"
 	case 39:
 		return "#,##0.00;(#,##0.00)"
 	case 40:
@@ -420,6 +435,9 @@ type xlsxFont struct {
 	Family  xlsxVal   `xml:"family,omitempty"`
 	Charset xlsxVal   `xml:"charset,omitempty"`
 	Color   xlsxColor `xml:"color,omitempty"`
+	B       *struct{} `xml:"b,omitempty"`
+	I       *struct{} `xml:"i,omitempty"`
+	U       *struct{} `xml:"u,omitempty"`
 }
 
 func (font *xlsxFont) Equals(other xlsxFont) bool {