Skip to content

Commit

Permalink
Merge branch 'crahles-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Geoffrey Teale committed Feb 3, 2015
2 parents 9fc9577 + e0aab72 commit 0e88abf
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
4 changes: 2 additions & 2 deletions file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,15 +642,15 @@ func (l *FileSuite) TestMarshalFile(c *C) {

// [Content_Types].xml
expectedContentTypes := `<?xml version="1.0" encoding="UTF-8"?>
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Override PartName="/_rels/.rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"></Override><Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml"></Override><Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"></Override><Override PartName="/xl/_rels/workbook.xml.rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"></Override><Override PartName="/xl/sharedStrings.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml"></Override><Override PartName="/xl/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"></Override><Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"></Override><Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"></Override><Override PartName="/xl/worksheets/sheet2.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"></Override><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"></Default><Default Extension="xml" ContentType="application/xml"></Default></Types>`
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Override PartName="/_rels/.rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"></Override><Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml"></Override><Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"></Override><Override PartName="/xl/_rels/workbook.xml.rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"></Override><Override PartName="/xl/sharedStrings.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml"></Override><Override PartName="/xl/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"></Override><Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"></Override><Override PartName="/xl/theme/theme1.xml" ContentType="application/vnd.openxmlformats-officedocument.theme+xml"></Override><Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"></Override><Override PartName="/xl/worksheets/sheet2.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"></Override><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"></Default><Default Extension="xml" ContentType="application/xml"></Default></Types>`
c.Assert(parts["[Content_Types].xml"], Equals, expectedContentTypes)

// styles.xml
//
// For now we only allow simple string data in the
// spreadsheet. Style support will follow.
expectedStyles := `<?xml version="1.0" encoding="UTF-8"?>
<styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><fonts count="1"><font><sz val="12"/><name val="Verdana"/><family val="0"/><charset val="0"/></font></fonts><cellStyleXfs count="1"><xf applyAlignment="0" applyBorder="0" applyFont="0" applyFill="0" applyProtection="0" borderId="0" fillId="0" fontId="0" numFmtId="0"><alignment horizontal="" indent="0" shrinkToFit="0" textRotation="0" vertical="" wrapText="0"/></xf></cellStyleXfs><cellXfs count="1"><xf applyAlignment="0" applyBorder="0" applyFont="0" applyFill="0" applyProtection="0" borderId="0" fillId="0" fontId="0" numFmtId="0"><alignment horizontal="" indent="0" shrinkToFit="0" textRotation="0" vertical="" wrapText="0"/></xf></cellXfs></styleSheet>`
<styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><fonts count="1"><font><sz val="12"/><name val="Verdana"/><family val="0"/><charset val="0"/></font></fonts><fills count="1"><fill><patternFill patternType="none"><fgColor rgb="FFFFFFFF"/><bgColor rgb="00000000"/></patternFill></fill></fills><borders count="1"><border><left style="none"/><right style="none"/><top style="none"/><bottom style="none"/></border></borders><cellStyleXfs count="1"><xf applyAlignment="0" applyBorder="0" applyFont="0" applyFill="0" applyProtection="0" borderId="0" fillId="0" fontId="0" numFmtId="0"><alignment horizontal="" indent="0" shrinkToFit="0" textRotation="0" vertical="" wrapText="0"/></xf></cellStyleXfs><cellXfs count="1"><xf applyAlignment="0" applyBorder="0" applyFont="0" applyFill="0" applyProtection="0" borderId="0" fillId="0" fontId="0" numFmtId="0"><alignment horizontal="" indent="0" shrinkToFit="0" textRotation="0" vertical="" wrapText="0"/></xf></cellXfs></styleSheet>`
c.Assert(parts["xl/styles.xml"], Equals, expectedStyles)
}

Expand Down
15 changes: 14 additions & 1 deletion style.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ type Style struct {

// Return a new Style structure initialised with the default values.
func NewStyle() *Style {
return &Style{Font: *DefaulFont()}
return &Style{
Font: *DefaulFont(),
Border: *DefaulBorder(),
Fill: *DefaulFill(),
}
}

// Generate the underlying XLSX style elements that correspond to the Style.
Expand Down Expand Up @@ -90,3 +94,12 @@ func NewFont(size int, name string) *Font {
func DefaulFont() *Font {
return NewFont(12, "Verdana")
}

func DefaulFill() *Fill {
return NewFill("none", "FFFFFFFF", "00000000")

}

func DefaulBorder() *Border {
return NewBorder("none", "none", "none", "none")
}
7 changes: 7 additions & 0 deletions style_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ func (s *StyleSuite) TestNewStyle(c *C) {
c.Assert(style, NotNil)
}

func (s *StyleSuite) TestNewStyleDefaults(c *C) {
style := NewStyle()
c.Assert(style.Font, Equals, *DefaulFont())
c.Assert(style.Fill, Equals, *DefaulFill())
c.Assert(style.Border, Equals, *DefaulBorder())
}

func (s *StyleSuite) TestMakeXLSXStyleElements(c *C) {
style := NewStyle()
font := *NewFont(12, "Verdana")
Expand Down
4 changes: 3 additions & 1 deletion xmlContentTypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type xlsxDefault struct {
}

func MakeDefaultContentTypes() (types xlsxTypes) {
types.Overrides = make([]xlsxOverride, 7)
types.Overrides = make([]xlsxOverride, 8)
types.Defaults = make([]xlsxDefault, 2)

types.Overrides[0].PartName = "/_rels/.rels"
Expand All @@ -39,6 +39,8 @@ func MakeDefaultContentTypes() (types xlsxTypes) {
types.Overrides[5].ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"
types.Overrides[6].PartName = "/xl/workbook.xml"
types.Overrides[6].ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"
types.Overrides[7].PartName = "/xl/theme/theme1.xml"
types.Overrides[7].ContentType = "application/vnd.openxmlformats-officedocument.theme+xml"

types.Defaults[0].Extension = "rels"
types.Defaults[0].ContentType = "application/vnd.openxmlformats-package.relationships+xml"
Expand Down
4 changes: 3 additions & 1 deletion xmlContentTypes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (l *ContentTypesSuite) TestMarshalContentTypes(c *C) {

func (l *ContentTypesSuite) TestMakeDefaultContentTypes(c *C) {
var types xlsxTypes = MakeDefaultContentTypes()
c.Assert(len(types.Overrides), Equals, 7)
c.Assert(len(types.Overrides), Equals, 8)
c.Assert(types.Overrides[0].PartName, Equals, "/_rels/.rels")
c.Assert(types.Overrides[0].ContentType, Equals, "application/vnd.openxmlformats-package.relationships+xml")
c.Assert(types.Overrides[1].PartName, Equals, "/docProps/app.xml")
Expand All @@ -39,6 +39,8 @@ func (l *ContentTypesSuite) TestMakeDefaultContentTypes(c *C) {
c.Assert(types.Overrides[5].ContentType, Equals, "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml")
c.Assert(types.Overrides[6].PartName, Equals, "/xl/workbook.xml")
c.Assert(types.Overrides[6].ContentType, Equals, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml")
c.Assert(types.Overrides[7].PartName, Equals, "/xl/theme/theme1.xml")
c.Assert(types.Overrides[7].ContentType, Equals, "application/vnd.openxmlformats-officedocument.theme+xml")

c.Assert(types.Defaults[0].Extension, Equals, "rels")
c.Assert(types.Defaults[0].ContentType, Equals, "application/vnd.openxmlformats-package.relationships+xml")
Expand Down

0 comments on commit 0e88abf

Please sign in to comment.