Просмотр исходного кода

Fixes #191.

This was a minor change; the offending function was just wrapping
another function that already properly returned an error value.

Just deleted the "bad" function and renamed the better one.

This is the fix only. The test updates will be in a different
commit to make this change easier to review.
Shawn Milochik 9 лет назад
Родитель
Сommit
2ce4db766a
2 измененных файлов с 8 добавлено и 15 удалено
  1. 3 14
      cell.go
  2. 5 1
      file.go

+ 3 - 14
cell.go

@@ -68,7 +68,7 @@ func (c *Cell) SetString(s string) {
 }
 }
 
 
 // String returns the value of a Cell as a string.
 // String returns the value of a Cell as a string.
-func (c *Cell) String() string {
+func (c *Cell) String() (string, error) {
 	return c.FormattedValue()
 	return c.FormattedValue()
 }
 }
 
 
@@ -291,11 +291,11 @@ func (c *Cell) formatToInt(format string) (string, error) {
 	return fmt.Sprintf(format, int(f)), nil
 	return fmt.Sprintf(format, int(f)), nil
 }
 }
 
 
-// SafeFormattedValue returns a value, and possibly an error condition
+// FormattedValue returns a value, and possibly an error condition
 // from a Cell.  If it is possible to apply a format to the cell
 // from a Cell.  If it is possible to apply a format to the cell
 // value, it will do so, if not then an error will be returned, along
 // value, it will do so, if not then an error will be returned, along
 // with the raw value of the Cell.
 // with the raw value of the Cell.
-func (c *Cell) SafeFormattedValue() (string, error) {
+func (c *Cell) FormattedValue() (string, error) {
 	var numberFormat = c.GetNumberFormat()
 	var numberFormat = c.GetNumberFormat()
 	if isTimeFormat(numberFormat) {
 	if isTimeFormat(numberFormat) {
 		return parseTime(c)
 		return parseTime(c)
@@ -348,17 +348,6 @@ func (c *Cell) SafeFormattedValue() (string, error) {
 
 
 }
 }
 
 
-// FormattedValue returns the formatted version of the value.
-// If it's a string type, c.Value will just be returned. Otherwise,
-// it will attempt to apply Excel formatting to the value.
-func (c *Cell) FormattedValue() string {
-	value, err := c.SafeFormattedValue()
-	if err != nil {
-		return err.Error()
-	}
-	return value
-}
-
 // parseTime returns a string parsed using time.Time
 // parseTime returns a string parsed using time.Time
 func parseTime(c *Cell) (string, error) {
 func parseTime(c *Cell) (string, error) {
 	f, err := strconv.ParseFloat(c.Value, 64)
 	f, err := strconv.ParseFloat(c.Value, 64)

+ 5 - 1
file.go

@@ -312,7 +312,11 @@ func (file *File) ToSlice() (output [][][]string, err error) {
 			}
 			}
 			r := []string{}
 			r := []string{}
 			for _, cell := range row.Cells {
 			for _, cell := range row.Cells {
-				r = append(r, cell.String())
+				str, err := cell.String()
+				if err != nil {
+					return output, err
+				}
+				r = append(r, str)
 			}
 			}
 			s = append(s, r)
 			s = append(s, r)
 		}
 		}