Geoffrey J. Teale 12 лет назад
Родитель
Сommit
e1b62dc4b4
3 измененных файлов с 17 добавлено и 10 удалено
  1. 9 7
      lib.go
  2. 2 2
      style.go
  3. 6 1
      workbook.go

+ 9 - 7
lib.go

@@ -94,8 +94,8 @@ type Border struct {
 // Fill is a high level structure intended to provide user access to
 // the contents of background and foreground color index within an Sheet.
 type Fill struct {
-	BgColorIndex  string
-	FgColorIndex  string
+	BgColorIndex string
+	FgColorIndex string
 }
 
 // File is a high level structure providing a slice of Sheet structs
@@ -249,7 +249,7 @@ func makeRowFromSpan(spans string) *Row {
 	return row
 }
 
-// get the max column 
+// get the max column
 // return the cells of columns
 func makeRowFromRaw(rawrow xlsxRow) *Row {
 	var upper int
@@ -338,12 +338,14 @@ func readRowsFromSheet(Worksheet *xlsxWorksheet, file *File) ([]*Row, int, int)
 		rowno := 0
 		for _, rawcell := range rawrow.C {
 			x, y, _ := getCoordsFromCellIDString(rawcell.R)
-			if y != 0 && rowno == 0{
+			if y != 0 && rowno == 0 {
 				rowno = y
 			}
-			row.Cells[x].Value = getValueFromCellData(rawcell, reftable)
-			row.Cells[x].styleIndex = rawcell.S
-			row.Cells[x].styles = file.styles
+			if x < len(row.Cells) {
+				row.Cells[x].Value = getValueFromCellData(rawcell, reftable)
+				row.Cells[x].styleIndex = rawcell.S
+				row.Cells[x].styles = file.styles
+			}
 		}
 		rows[rowno] = row
 	}

+ 2 - 2
style.go

@@ -80,6 +80,6 @@ type xlsxLine struct {
 type xlsxXf struct {
 	ApplyBorder string `xml:"applyBorder,attr"`
 	BorderId    int    `xml:"borderId,attr"`
-	ApplyFill string `xml:"applyFill,attr"`
-	FillId int `xml:"fillId,attr"`
+	ApplyFill   string `xml:"applyFill,attr"`
+	FillId      int    `xml:"fillId,attr"`
 }

+ 6 - 1
workbook.go

@@ -108,8 +108,13 @@ func getWorksheetFromSheet(sheet xlsxSheet, worksheets map[string]*zip.File) (*x
 	var decoder *xml.Decoder
 	var worksheet *xlsxWorksheet
 	var error error
+	var sheetName string
 	worksheet = new(xlsxWorksheet)
-	sheetName := fmt.Sprintf("sheet%s", sheet.Id[3:])
+	if sheet.SheetId != "" {
+		sheetName = fmt.Sprintf("sheet%s", sheet.SheetId)
+	} else {
+		sheetName = fmt.Sprintf("sheet%s", sheet.Id)
+	}
 	f := worksheets[sheetName]
 	rc, error = f.Open()
 	if error != nil {