Geoffrey J. Teale 11 years ago
parent
commit
cf13d6c87d
13 changed files with 40 additions and 52 deletions
  1. 1 3
      common_test.go
  2. 2 3
      date.go
  3. 1 4
      date_test.go
  4. 8 13
      lib.go
  5. 9 10
      lib_test.go
  6. 2 3
      macExcel_test.go
  7. 2 2
      macNumbers_test.go
  8. 1 1
      sharedstrings_test.go
  9. 1 3
      style.go
  10. 3 3
      workbook.go
  11. 5 4
      workbook_test.go
  12. 3 2
      worksheet_test.go
  13. 2 1
      wpsBlankLine_test.go

+ 1 - 3
common_test.go

@@ -1,10 +1,8 @@
 package xlsx
 
 import (
-	"testing"
 	. "gopkg.in/check.v1"
+	"testing"
 )
 
 func Test(t *testing.T) { TestingT(t) }
-
-

+ 2 - 3
date.go

@@ -68,7 +68,6 @@ func doTheFliegelAndVanFlandernAlgorithm(jd int) (day, month, year int) {
 	return d, m, y
 }
 
-
 // Convert an excelTime representation (stored as a floating point number) to a time.Time.
 func TimeFromExcelTime(excelTime float64, date1904 bool) time.Time {
 	var date time.Time
@@ -80,9 +79,9 @@ func TimeFromExcelTime(excelTime float64, date1904 bool) time.Time {
 		const OFFSET1904 = 16480.0
 		var date time.Time
 		if date1904 {
-			date = julianDateToGregorianTime(MJD_0, excelTime + OFFSET1904)
+			date = julianDateToGregorianTime(MJD_0, excelTime+OFFSET1904)
 		} else {
-			date = julianDateToGregorianTime(MJD_0, excelTime + OFFSET1900)
+			date = julianDateToGregorianTime(MJD_0, excelTime+OFFSET1900)
 		}
 		return date
 	}

+ 1 - 4
date_test.go

@@ -23,7 +23,6 @@ func (d *DateSuite) TestFractionOfADay(c *C) {
 	c.Assert(n, Equals, 0)
 }
 
-
 func (d *DateSuite) TestJulianDateToGregorianTime(c *C) {
 	c.Assert(julianDateToGregorianTime(2400000.5, 51544.0),
 		Equals, time.Date(2000, 1, 1, 0, 0, 0, 0, time.Local))
@@ -37,7 +36,6 @@ func (d *DateSuite) TestJulianDateToGregorianTime(c *C) {
 		Equals, time.Date(2000, 1, 1, 18, 0, 0, 0, time.Local))
 }
 
-
 func (d *DateSuite) TestTimeFromExcelTime(c *C) {
 	date := TimeFromExcelTime(0, false)
 	c.Assert(date, Equals, time.Date(1899, 12, 30, 0, 0, 0, 0, time.Local))
@@ -49,7 +47,6 @@ func (d *DateSuite) TestTimeFromExcelTime(c *C) {
 	c.Assert(date, Equals, time.Date(2013, 1, 1, 0, 0, 0, 0, time.Local))
 }
 
-
 func (d *DateSuite) TestTimeFromExcelTimeWithFractionalPart(c *C) {
 	date := TimeFromExcelTime(0.114583333333333, false)
 	c.Assert(date.Round(time.Second), Equals, time.Date(1899, 12, 30, 2, 45, 0, 0, time.Local))
@@ -67,7 +64,7 @@ func (d *DateSuite) TestTimeFromExcelTimeWithFractionalPart(c *C) {
 	c.Assert(date.Round(time.Second), Equals, time.Date(2013, 1, 1, 2, 45, 0, 0, time.Local))
 }
 
-func (d *DateSuite) TestTimeFromExcelTimeWith1904Offest(c *C){
+func (d *DateSuite) TestTimeFromExcelTimeWith1904Offest(c *C) {
 	date1904Offset := TimeFromExcelTime(39813.0, true)
 	c.Assert(date1904Offset, Equals, time.Date(2013, 1, 1, 0, 0, 0, 0, time.Local))
 

+ 8 - 13
lib.go

@@ -26,11 +26,11 @@ func (e *XLSXReaderError) Error() string {
 // Cell is a high level structure intended to provide user access to
 // the contents of Cell within an xlsx.Row.
 type Cell struct {
-	Value      string
-	styleIndex int
-	styles     *xlsxStyles
+	Value          string
+	styleIndex     int
+	styles         *xlsxStyles
 	numFmtRefTable map[int]xlsxNumFmt
-	date1904   bool
+	date1904       bool
 }
 
 // CellInterface defines the public API of the Cell.
@@ -103,7 +103,6 @@ func (c *Cell) formatToFloat(format string) string {
 	return fmt.Sprintf(format, f)
 }
 
-
 func (c *Cell) formatToInt(format string) string {
 	f, err := strconv.ParseFloat(c.Value, 64)
 	if err != nil {
@@ -133,7 +132,7 @@ func (c *Cell) FormattedValue() string {
 		}
 		i := int(f)
 		return fmt.Sprintf("%d", i)
-	case  "#,##0.00;(#,##0.00)", "#,##0.00;[red](#,##0.00)":
+	case "#,##0.00;(#,##0.00)", "#,##0.00;[red](#,##0.00)":
 		f, err := strconv.ParseFloat(c.Value, 64)
 		if err != nil {
 			return err.Error()
@@ -194,7 +193,7 @@ func (c *Cell) FormattedValue() string {
 			return err.Error()
 		}
 		t := TimeFromExcelTime(f, c.date1904)
-		return fmt.Sprintf("%0d%0d.%d", t.Minute(), t.Second(), t.Nanosecond() / 1000)
+		return fmt.Sprintf("%0d%0d.%d", t.Minute(), t.Second(), t.Nanosecond()/1000)
 
 	case "yyyy\\-mm\\-dd":
 		return c.formatToTime("2006\\-01\\-02")
@@ -210,7 +209,7 @@ func (c *Cell) FormattedValue() string {
 		return c.formatToTime("06-01-02")
 	case "d-mmm-yyyy":
 		return c.formatToTime("2-Jan-2006")
-	case  "m/d/yy":
+	case "m/d/yy":
 		return c.formatToTime("1/2/06")
 	case "m/d/yyyy":
 		return c.formatToTime("1/2/2006")
@@ -228,7 +227,6 @@ func (c *Cell) FormattedValue() string {
 	return c.Value
 }
 
-
 // Row is a high level structure indended to provide user access to a
 // row within a xlsx.Sheet.  An xlsx.Row contains a slice of xlsx.Cell.
 type Row struct {
@@ -244,7 +242,6 @@ type Sheet struct {
 	MaxCol int
 }
 
-
 // Style is a high level structure intended to provide user access to
 // the contents of Style within an XLSX file.
 type Style struct {
@@ -419,8 +416,6 @@ func calculateMaxMinFromWorksheet(worksheet *xlsxWorksheet) (minx, miny, maxx, m
 	return
 }
 
-
-
 // makeRowFromSpan will, when given a span expressed as a string,
 // return an empty Row large enough to encompass that span and
 // populate it with empty cells.  All rows start from cell 1 -
@@ -483,7 +478,7 @@ func getValueFromCellData(rawcell xlsxC, reftable []string) string {
 	if len(data) > 0 {
 		vval := strings.Trim(data, " \t\n\r")
 		switch rawcell.T {
-		case "s":  // Shared String
+		case "s": // Shared String
 			ref, error := strconv.Atoi(vval)
 			if error != nil {
 				panic(error)

+ 9 - 10
lib_test.go

@@ -4,13 +4,13 @@ import (
 	"bytes"
 	"encoding/xml"
 	// "strconv"
-	"strings"
 	. "gopkg.in/check.v1"
+	"strings"
 )
 
+type LibSuite struct{}
 
-type LibSuite struct {}
-var _  = Suite(&LibSuite{})
+var _ = Suite(&LibSuite{})
 
 // Test we can correctly open a XSLX file and return a xlsx.File
 // struct.
@@ -113,16 +113,16 @@ func (l *LibSuite) TestFormattedValue(c *C) {
 	c.Assert(cell.FormattedValue(), Equals, "37947")
 
 	setCode("#,##0") // For the time being we're not doing this
-			 // comma formatting, so it'll fall back to
-			 // the related non-comma form.
+	// comma formatting, so it'll fall back to
+	// the related non-comma form.
 	c.Assert(cell.FormattedValue(), Equals, "37947")
 
 	setCode("0.00")
 	c.Assert(cell.FormattedValue(), Equals, "37947.75")
 
 	setCode("#,##0.00") // For the time being we're not doing this
-	                    // comma formatting, so it'll fall back to
-	                    // the related non-comma form.
+	// comma formatting, so it'll fall back to
+	// the related non-comma form.
 	c.Assert(cell.FormattedValue(), Equals, "37947.75")
 
 	setCode("#,##0 ;(#,##0)")
@@ -173,7 +173,7 @@ func (l *LibSuite) TestFormattedValue(c *C) {
 
 	setCode("h:mm:ss")
 	c.Assert(cell.FormattedValue(), Equals, "18:00:00")
-	 // This is wrong, but there's no eary way aroud it in Go right now, AFAICT.
+	// This is wrong, but there's no eary way aroud it in Go right now, AFAICT.
 	c.Assert(smallCell.FormattedValue(), Equals, "00:14:47")
 
 	setCode("m/d/yy h:mm")
@@ -779,7 +779,7 @@ func (l *LibSuite) TestReadRowsFromSheetWithEmptyCells(c *C) {
 	c.Assert(cell1.String(), Equals, "No")
 
 	cell2 := row.Cells[1]
-	c.Assert(cell2.String(), Equals,"")
+	c.Assert(cell2.String(), Equals, "")
 
 	cell3 := row.Cells[2]
 	c.Assert(cell3.String(), Equals, "Yes")
@@ -840,7 +840,6 @@ func (l *LibSuite) TestReadRowsFromSheetWithTrailingEmptyCells(c *C) {
 	c.Assert(cell4.String(), Equals, "")
 }
 
-
 func (l *LibSuite) TestReadRowsFromSheetWithMultipleSpans(c *C) {
 	var sharedstringsXML = bytes.NewBufferString(`
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>

+ 2 - 3
macExcel_test.go

@@ -4,10 +4,9 @@ import (
 	. "gopkg.in/check.v1"
 )
 
+type MacExcelSuite struct{}
 
-type MacExcelSuite struct {}
-var _  = Suite(&MacExcelSuite{})
-
+var _ = Suite(&MacExcelSuite{})
 
 // Test that we can successfully read an XLSX file generated by
 // Microsoft Excel for Mac.  In particular this requires that we

+ 2 - 2
macNumbers_test.go

@@ -4,9 +4,9 @@ import (
 	. "gopkg.in/check.v1"
 )
 
-type MacNumbersSuite struct {}
-var _ = Suite(&MacNumbersSuite{})
+type MacNumbersSuite struct{}
 
+var _ = Suite(&MacNumbersSuite{})
 
 // Test that we can successfully read an XLSX file generated by
 // Numbers for Mac.

+ 1 - 1
sharedstrings_test.go

@@ -9,8 +9,8 @@ import (
 type SharedStringsSuite struct {
 	SharedStringsXML *bytes.Buffer
 }
-var _ = Suite(&SharedStringsSuite{})
 
+var _ = Suite(&SharedStringsSuite{})
 
 func (s *SharedStringsSuite) SetUpTest(c *C) {
 	s.SharedStringsXML = bytes.NewBufferString(

+ 1 - 3
style.go

@@ -25,12 +25,10 @@ type xlsxStyles struct {
 // currently I have not checked it for completeness - it does as much
 // as I need.
 type xlsxNumFmt struct {
-	NumFmtId int `xml:"numFmtId"`
+	NumFmtId   int    `xml:"numFmtId"`
 	FormatCode string `xml:"formatCode"`
 }
 
-
-
 // xlsxFont directly maps the font element in the namespace
 // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
 // currently I have not checked it for completeness - it does as much

+ 3 - 3
workbook.go

@@ -49,9 +49,9 @@ type xlsxFileVersion struct {
 // much as I need.
 type xlsxWorkbookPr struct {
 	DefaultThemeVersion string `xml:"defaultThemeVersion,attr"`
-	BackUpFile bool `xml:"backupFile,attr"`
-	ShowObjects string `xml:"showObjects,attr"`
-	Date1904 bool `xml:"date1904,attr"`
+	BackUpFile          bool   `xml:"backupFile,attr"`
+	ShowObjects         string `xml:"showObjects,attr"`
+	Date1904            bool   `xml:"date1904,attr"`
 }
 
 // xlsxBookViews directly maps the bookViews element from the

+ 5 - 4
workbook_test.go

@@ -6,7 +6,8 @@ import (
 	. "gopkg.in/check.v1"
 )
 
-type WorkbookSuite struct {}
+type WorkbookSuite struct{}
+
 var _ = Suite(&WorkbookSuite{})
 
 // Test we can succesfully unmarshal the workbook.xml file from within
@@ -57,18 +58,18 @@ func (w *WorkbookSuite) TestUnmarshallWorkbookXML(c *C) {
 	c.Assert(workbook.FileVersion.RupBuild, Equals, "4506")
 	c.Assert(workbook.WorkbookPr.DefaultThemeVersion, Equals, "124226")
 	c.Assert(workbook.WorkbookPr.Date1904, Equals, true)
-	c.Assert(workbook.BookViews.WorkBookView, HasLen,  1)
+	c.Assert(workbook.BookViews.WorkBookView, HasLen, 1)
 	workBookView := workbook.BookViews.WorkBookView[0]
 	c.Assert(workBookView.XWindow, Equals, "120")
 	c.Assert(workBookView.YWindow, Equals, "75")
 	c.Assert(workBookView.WindowWidth, Equals, "15135")
 	c.Assert(workBookView.WindowHeight, Equals, "7620")
-	c.Assert(workbook.Sheets.Sheet, HasLen,  3)
+	c.Assert(workbook.Sheets.Sheet, HasLen, 3)
 	sheet := workbook.Sheets.Sheet[0]
 	c.Assert(sheet.Id, Equals, "rId1")
 	c.Assert(sheet.Name, Equals, "Sheet1")
 	c.Assert(sheet.SheetId, Equals, "1")
-	c.Assert(workbook.DefinedNames.DefinedName, HasLen,  1)
+	c.Assert(workbook.DefinedNames.DefinedName, HasLen, 1)
 	dname := workbook.DefinedNames.DefinedName[0]
 	c.Assert(dname.Data, Equals, "Sheet1!$A$1533")
 	c.Assert(dname.LocalSheetID, Equals, "0")

+ 3 - 2
worksheet_test.go

@@ -6,14 +6,15 @@ import (
 	. "gopkg.in/check.v1"
 )
 
-type WorksheetSuite struct {}
+type WorksheetSuite struct{}
+
 var _ = Suite(&WorksheetSuite{})
 
 // Test we can succesfully unmarshal the sheetN.xml files within and
 // XLSX file into an xlsxWorksheet struct (and it's related children).
 func (w *WorksheetSuite) TestUnmarshallWorksheet(c *C) {
 	var sheetxml = bytes.NewBufferString(
-	`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+		`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
         <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"
                    xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
           <sheetPr filterMode="false">

+ 2 - 1
wpsBlankLine_test.go

@@ -4,7 +4,8 @@ import (
 	. "gopkg.in/check.v1"
 )
 
-type WpsBlankLineSuite struct {}
+type WpsBlankLineSuite struct{}
+
 var _ = Suite(&WorksheetSuite{})
 
 // Test that we can successfully read an XLSX file generated by