Browse Source

go fmt *.go

go fmt *.go
zhcy 13 years ago
parent
commit
2ff54efcfa
5 changed files with 34 additions and 44 deletions
  1. 0 1
      doc.go
  2. 18 19
      lib.go
  3. 5 10
      sharedstrings.go
  4. 1 1
      style.go
  5. 10 13
      worksheet.go

+ 0 - 1
doc.go

@@ -6,4 +6,3 @@
 // the source for xlsx2csv here: https://github.com/tealeg/xlsx2csv
 
 package xlsx
-

+ 18 - 19
lib.go

@@ -26,9 +26,9 @@ 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
+	Value      string
 	styleIndex int
-	styles *xlsxStyles
+	styles     *xlsxStyles
 }
 
 // CellInterface defines the public API of the Cell.
@@ -40,7 +40,7 @@ func (c *Cell) String() string {
 	return c.Value
 }
 
-func (c *Cell) GetStyle() *Style {	
+func (c *Cell) GetStyle() *Style {
 	if c.styleIndex > 0 && c.styleIndex < len(c.styles.CellXfs) {
 		xf := c.styles.CellXfs[c.styleIndex]
 		if xf.ApplyBorder != "0" {
@@ -70,7 +70,7 @@ type Row struct {
 // Sheet is a high level structure intended to provide user access to
 // the contents of a particular sheet within an XLSX file.
 type Sheet struct {
-	Rows []*Row
+	Rows   []*Row
 	MaxRow int
 	MaxCol int
 }
@@ -84,9 +84,9 @@ type Style struct {
 // Border is a high level structure intended to provide user access to
 // the contents of Border Style within an Sheet.
 type Border struct {
-	Left string
-	Right string
-	Top string 
+	Left   string
+	Right  string
+	Top    string
 	Bottom string
 }
 
@@ -96,8 +96,8 @@ type File struct {
 	worksheets     map[string]*zip.File
 	referenceTable []string
 	styles         *xlsxStyles
-	Sheets         []*Sheet // sheet access by index
-	Sheet map[string]*Sheet // sheet access by name
+	Sheets         []*Sheet          // sheet access by index
+	Sheet          map[string]*Sheet // sheet access by name
 }
 
 // getRangeFromString is an internal helper function that converts
@@ -256,7 +256,7 @@ func makeRowFromRaw(rawrow xlsxRow) *Row {
 		if error != nil {
 			panic(fmt.Sprintf("Invalid Cell Coord, %s\n", rawcell.R))
 		}
-		if x  > upper {
+		if x > upper {
 			upper = x
 		}
 	}
@@ -293,7 +293,7 @@ func getValueFromCellData(rawcell xlsxC, reftable []string) string {
 // readRowsFromSheet is an internal helper function that extracts the
 // rows from a XSLXWorksheet, poulates them with Cells and resolves
 // the value references from the reference table and stores them in
-func readRowsFromSheet(Worksheet *xlsxWorksheet, file *File) ([]*Row ,int, int) {
+func readRowsFromSheet(Worksheet *xlsxWorksheet, file *File) ([]*Row, int, int) {
 	var rows []*Row
 	var row *Row
 	var maxCol int
@@ -327,21 +327,21 @@ func readRowsFromSheet(Worksheet *xlsxWorksheet, file *File) ([]*Row ,int, int)
 		} else {
 			row = makeRowFromRaw(rawrow)
 		}
-		_,y, _ := getCoordsFromCellIDString(rawrow.C[0].R)
+		_, y, _ := getCoordsFromCellIDString(rawrow.C[0].R)
 		for _, rawcell := range rawrow.C {
-			x,_, _ := getCoordsFromCellIDString(rawcell.R)
+			x, _, _ := getCoordsFromCellIDString(rawcell.R)
 			row.Cells[x].Value = getValueFromCellData(rawcell, reftable)
 			row.Cells[x].styleIndex = rawcell.S
 			row.Cells[x].styles = file.styles
 		}
 		rows[y] = row
 	}
-	for i := 0; i < len(rows); i++{
+	for i := 0; i < len(rows); i++ {
 		if rows[i] == nil {
 			rows[i] = new(Row)
 		}
 	}
-	return rows,maxCol,maxRow
+	return rows, maxCol, maxRow
 }
 
 // readSheetsFromZipFile is an internal helper function that loops
@@ -370,7 +370,7 @@ func readSheetsFromZipFile(f *zip.File, file *File) ([]*Sheet, []string, error)
 			return nil, nil, error
 		}
 		sheet := new(Sheet)
-		sheet.Rows,sheet.MaxCol,sheet.MaxRow = readRowsFromSheet(worksheet, file)
+		sheet.Rows, sheet.MaxCol, sheet.MaxRow = readRowsFromSheet(worksheet, file)
 		sheets[i] = sheet
 		names[i] = rawsheet.Name
 	}
@@ -421,7 +421,6 @@ func readStylesFromZipFile(f *zip.File) (*xlsxStyles, error) {
 	return style, nil
 }
 
-
 // OpenFile() take the name of an XLSX file and returns a populated
 // xlsx.File struct for it.
 func OpenFile(filename string) (x *File, e error) {
@@ -469,7 +468,7 @@ func OpenFile(filename string) (x *File, e error) {
 		return nil, error
 	}
 	file.referenceTable = reftable
-	style , error := readStylesFromZipFile(styles)
+	style, error := readStylesFromZipFile(styles)
 	if error != nil {
 		return nil, error
 	}
@@ -484,7 +483,7 @@ func OpenFile(filename string) (x *File, e error) {
 		return nil, error
 	}
 	file.Sheets = sheets
-	sheetMap = make(map[string]*Sheet,len(names))
+	sheetMap = make(map[string]*Sheet, len(names))
 	for i := 0; i < len(names); i++ {
 		sheetMap[names[i]] = sheets[i]
 	}

+ 5 - 10
sharedstrings.go

@@ -1,23 +1,21 @@
 package xlsx
 
-
 // xlsxSST directly maps the sst element from the namespace
 // http://schemas.openxmlformats.org/spreadsheetml/2006/main currently
 // I have not checked this for completeness - it does as much as need.
 type xlsxSST struct {
-	Count       string    `xml:"count,attr"`
-	UniqueCount string    `xml:"uniqueCount,attr"`
-	SI          []xlsxSI  `xml:"si"`
+	Count       string   `xml:"count,attr"`
+	UniqueCount string   `xml:"uniqueCount,attr"`
+	SI          []xlsxSI `xml:"si"`
 }
 
-
 // xlsxSI directly maps the si element from the namespace
 // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
 // currently I have not checked this for completeness - it does as
 // much as I need.
 type xlsxSI struct {
-	T string `xml:"t"` 
-	R        []xlsxR `xml:"r"`
+	T string  `xml:"t"`
+	R []xlsxR `xml:"r"`
 }
 
 // xlsxR directly maps the r element from the namespace
@@ -36,7 +34,6 @@ type xlsxR struct {
 // 	Data string `xml:"chardata"`
 // }
 
-
 // MakeSharedStringRefTable() takes an xlsxSST struct and converts
 // it's contents to an slice of strings used to refer to string values
 // by numeric index - this is the model used within XLSX worksheet (a
@@ -62,5 +59,3 @@ func MakeSharedStringRefTable(source *xlsxSST) []string {
 func ResolveSharedString(reftable []string, index int) string {
 	return reftable[index]
 }
-
-

+ 1 - 1
style.go

@@ -70,5 +70,5 @@ type xlsxLine struct {
 // as I need.
 type xlsxXf struct {
 	ApplyBorder string `xml:"applyBorder,attr"`
-	BorderId    int `xml:"borderId,attr"`
+	BorderId    int    `xml:"borderId,attr"`
 }

+ 10 - 13
worksheet.go

@@ -5,10 +5,10 @@ package xlsx
 // currently I have not checked it for completeness - it does as much
 // as I need.
 type xlsxWorksheet struct {
-	Dimension     xlsxDimension      `xml:"dimension"`
-	SheetViews    xlsxSheetViews     `xml:"sheetViews"`
-	SheetFormatPr xlsxSheetFormatPr  `xml:"sheetFormatPr"`
-	SheetData     xlsxSheetData      `xml:"sheetData"`
+	Dimension     xlsxDimension     `xml:"dimension"`
+	SheetViews    xlsxSheetViews    `xml:"sheetViews"`
+	SheetFormatPr xlsxSheetFormatPr `xml:"sheetFormatPr"`
+	SheetData     xlsxSheetData     `xml:"sheetData"`
 }
 
 // xlsxDimension directly maps the dimension element in the namespace
@@ -32,12 +32,11 @@ type xlsxSheetViews struct {
 // currently I have not checked it for completeness - it does as much
 // as I need.
 type xlsxSheetView struct {
-	TabSelected    string `xml:"tabSelected,attr"`
-	WorkbookViewID string `xml:"workbookViewId,attr"`
+	TabSelected    string        `xml:"tabSelected,attr"`
+	WorkbookViewID string        `xml:"workbookViewId,attr"`
 	Selection      xlsxSelection `xml:"selection"`
 }
 
-
 // xlsxSelection directly maps the selection element in the namespace
 // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
 // currently I have not checked it for completeness - it does as much
@@ -62,7 +61,7 @@ type xlsxSheetFormatPr struct {
 // currently I have not checked it for completeness - it does as much
 // as I need.
 type xlsxSheetData struct {
-	Row []xlsxRow  `xml:"row"`
+	Row []xlsxRow `xml:"row"`
 }
 
 // xlsxRow directly maps the row element in the namespace
@@ -81,12 +80,11 @@ type xlsxRow struct {
 // as I need.
 type xlsxC struct {
 	R string `xml:"r,attr"`
-	S int `xml:"s,attr"`
+	S int    `xml:"s,attr"`
 	T string `xml:"t,attr"`
-	V string  `xml:"v"`
+	V string `xml:"v"`
 }
 
-
 // xlsxV directly maps the v element in the namespace
 // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
 // currently I have not checked it for completeness - it does as much
@@ -96,11 +94,10 @@ type xlsxC struct {
 // }
 
 // get cell
-func (sh *Sheet) Cell(row,col int) *Cell {
+func (sh *Sheet) Cell(row, col int) *Cell {
 
 	if len(sh.Rows) > row && len(sh.Rows[row].Cells) > col {
 		return sh.Rows[row].Cells[col]
 	}
 	return new(Cell)
 }
-