Browse Source

Merge pull request #117 from tealeg/nil_formula_fix

Fix for a nil formula when the raw cell type is error (e).
Geoffrey J. Teale 10 years ago
parent
commit
fa6af7b37b
2 changed files with 14 additions and 7 deletions
  1. 3 7
      lib.go
  2. 11 0
      lib_test.go

+ 3 - 7
lib.go

@@ -320,6 +320,9 @@ func formulaForCell(rawcell xlsxC, sharedFormulas map[int]sharedFormula) string
 	var res string
 
 	f := rawcell.F
+	if f == nil {
+		return ""
+	}
 	if f.T == "shared" {
 		x, y, err := getCoordsFromCellIDString(rawcell.R)
 		if err != nil {
@@ -605,13 +608,6 @@ func readSheetsFromZipFile(f *zip.File, file *File, sheetXMLMap map[string]strin
 	defer close(sheetChan)
 
 	go func() {
-		defer func() {
-			if e := recover(); e != nil {
-				err = fmt.Errorf("%v", e)
-				result := &indexedSheet{Index: -1, Sheet: nil, Error: err}
-				sheetChan <- result
-			}
-		}()
 		err = nil
 		for i, rawsheet := range workbookSheets {
 			readSheetFromFile(sheetChan, i, rawsheet, file, sheetXMLMap)

+ 11 - 0
lib_test.go

@@ -894,3 +894,14 @@ func (l *LibSuite) TestSharedFormulas(c *C) {
 	c.Assert(row.Cells[1].Formula(), Equals, "2*B1")
 	c.Assert(row.Cells[2].Formula(), Equals, "2*C1")
 }
+
+// Avoid panic when cell.F.T is "e" (for error)
+func (l *LibSuite) TestFormulaForCellPanic(c *C) {
+	cell := xlsxC{R: "A1"}
+	// This line would panic before the fix.
+	sharedFormulas := make(map[int]sharedFormula)
+
+	// Not really an important test; getting here without a
+	// panic is the real win.
+	c.Assert(formulaForCell(cell, sharedFormulas), Equals, "")
+}