diff --git a/cell.go b/cell.go index 5ebcefe..5fcadce 100644 --- a/cell.go +++ b/cell.go @@ -564,7 +564,7 @@ func (c *xlsxC) getValueFrom(f *File, d *xlsxSST, raw bool) (string, error) { case "s": if c.V != "" { xlsxSI := 0 - xlsxSI, _ = strconv.Atoi(c.V) + xlsxSI, _ = strconv.Atoi(strings.TrimSpace(c.V)) if _, ok := f.tempFiles.Load(defaultXMLPathSharedStrings); ok { return f.formattedValue(c.S, f.getFromStringItem(xlsxSI), raw) } diff --git a/cell_test.go b/cell_test.go index 58a4bee..565c1c9 100644 --- a/cell_test.go +++ b/cell_test.go @@ -432,6 +432,11 @@ func TestGetValueFrom(t *testing.T) { value, err := c.getValueFrom(f, sst, false) assert.NoError(t, err) assert.Equal(t, "", value) + + c = xlsxC{T: "s", V: " 1 "} + value, err = c.getValueFrom(f, &xlsxSST{Count: 1, SI: []xlsxSI{{}, {T: &xlsxT{Val: "s"}}}}, false) + assert.NoError(t, err) + assert.Equal(t, "s", value) } func TestGetCellFormula(t *testing.T) { diff --git a/stream.go b/stream.go index 55a2268..82d7129 100644 --- a/stream.go +++ b/stream.go @@ -47,23 +47,23 @@ type StreamWriter struct { // 16MB. For example, set data for worksheet of size 102400 rows x 50 columns // with numbers and style: // -// file := excelize.NewFile() +// f := excelize.NewFile() // defer func() { -// if err := file.Close(); err != nil { +// if err := f.Close(); err != nil { // fmt.Println(err) // } // }() -// streamWriter, err := file.NewStreamWriter("Sheet1") +// sw, err := f.NewStreamWriter("Sheet1") // if err != nil { // fmt.Println(err) // return // } -// styleID, err := file.NewStyle(&excelize.Style{Font: &excelize.Font{Color: "777777"}}) +// styleID, err := f.NewStyle(&excelize.Style{Font: &excelize.Font{Color: "777777"}}) // if err != nil { // fmt.Println(err) // return // } -// if err := streamWriter.SetRow("A1", +// if err := sw.SetRow("A1", // []interface{}{ // excelize.Cell{StyleID: styleID, Value: "Data"}, // []excelize.RichTextRun{ @@ -80,30 +80,34 @@ type StreamWriter struct { // for colID := 0; colID < 50; colID++ { // row[colID] = rand.Intn(640000) // } -// cell, _ := excelize.CoordinatesToCellName(1, rowID) -// if err := streamWriter.SetRow(cell, row); err != nil { +// cell, err := excelize.CoordinatesToCellName(1, rowID) +// if err != nil { // fmt.Println(err) -// return +// break +// } +// if err := sw.SetRow(cell, row); err != nil { +// fmt.Println(err) +// break // } // } -// if err := streamWriter.Flush(); err != nil { +// if err := sw.Flush(); err != nil { // fmt.Println(err) // return // } -// if err := file.SaveAs("Book1.xlsx"); err != nil { +// if err := f.SaveAs("Book1.xlsx"); err != nil { // fmt.Println(err) // } // // Set cell value and cell formula for a worksheet with stream writer: // -// err := streamWriter.SetRow("A1", []interface{}{ +// err := sw.SetRow("A1", []interface{}{ // excelize.Cell{Value: 1}, // excelize.Cell{Value: 2}, // excelize.Cell{Formula: "SUM(A1,B1)"}}); // // Set cell value and rows style for a worksheet with stream writer: // -// err := streamWriter.SetRow("A1", []interface{}{ +// err := sw.SetRow("A1", []interface{}{ // excelize.Cell{Value: 1}}, // excelize.RowOpts{StyleID: styleID, Height: 20, Hidden: false}); func (f *File) NewStreamWriter(sheet string) (*StreamWriter, error) { @@ -432,7 +436,7 @@ func (sw *StreamWriter) SetRow(cell string, values []interface{}, opts ...RowOpt // the 'SetColWidth' function before the 'SetRow' function. For example set // the width column B:C as 20: // -// err := streamWriter.SetColWidth(2, 3, 20) +// err := sw.SetColWidth(2, 3, 20) func (sw *StreamWriter) SetColWidth(min, max int, width float64) error { if sw.sheetWritten { return ErrStreamSetColWidth