Skip to content

Commit 9dbba9f

Browse files
committed
This closes #1508, support SST index which contains blank characters
1 parent 60b9d02 commit 9dbba9f

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

cell.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ func (c *xlsxC) getValueFrom(f *File, d *xlsxSST, raw bool) (string, error) {
564564
case "s":
565565
if c.V != "" {
566566
xlsxSI := 0
567-
xlsxSI, _ = strconv.Atoi(c.V)
567+
xlsxSI, _ = strconv.Atoi(strings.TrimSpace(c.V))
568568
if _, ok := f.tempFiles.Load(defaultXMLPathSharedStrings); ok {
569569
return f.formattedValue(c.S, f.getFromStringItem(xlsxSI), raw)
570570
}

cell_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,11 @@ func TestGetValueFrom(t *testing.T) {
432432
value, err := c.getValueFrom(f, sst, false)
433433
assert.NoError(t, err)
434434
assert.Equal(t, "", value)
435+
436+
c = xlsxC{T: "s", V: " 1 "}
437+
value, err = c.getValueFrom(f, &xlsxSST{Count: 1, SI: []xlsxSI{{}, {T: &xlsxT{Val: "s"}}}}, false)
438+
assert.NoError(t, err)
439+
assert.Equal(t, "s", value)
435440
}
436441

437442
func TestGetCellFormula(t *testing.T) {

stream.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,23 @@ type StreamWriter struct {
4747
// 16MB. For example, set data for worksheet of size 102400 rows x 50 columns
4848
// with numbers and style:
4949
//
50-
// file := excelize.NewFile()
50+
// f := excelize.NewFile()
5151
// defer func() {
52-
// if err := file.Close(); err != nil {
52+
// if err := f.Close(); err != nil {
5353
// fmt.Println(err)
5454
// }
5555
// }()
56-
// streamWriter, err := file.NewStreamWriter("Sheet1")
56+
// sw, err := f.NewStreamWriter("Sheet1")
5757
// if err != nil {
5858
// fmt.Println(err)
5959
// return
6060
// }
61-
// styleID, err := file.NewStyle(&excelize.Style{Font: &excelize.Font{Color: "777777"}})
61+
// styleID, err := f.NewStyle(&excelize.Style{Font: &excelize.Font{Color: "777777"}})
6262
// if err != nil {
6363
// fmt.Println(err)
6464
// return
6565
// }
66-
// if err := streamWriter.SetRow("A1",
66+
// if err := sw.SetRow("A1",
6767
// []interface{}{
6868
// excelize.Cell{StyleID: styleID, Value: "Data"},
6969
// []excelize.RichTextRun{
@@ -80,30 +80,34 @@ type StreamWriter struct {
8080
// for colID := 0; colID < 50; colID++ {
8181
// row[colID] = rand.Intn(640000)
8282
// }
83-
// cell, _ := excelize.CoordinatesToCellName(1, rowID)
84-
// if err := streamWriter.SetRow(cell, row); err != nil {
83+
// cell, err := excelize.CoordinatesToCellName(1, rowID)
84+
// if err != nil {
8585
// fmt.Println(err)
86-
// return
86+
// break
87+
// }
88+
// if err := sw.SetRow(cell, row); err != nil {
89+
// fmt.Println(err)
90+
// break
8791
// }
8892
// }
89-
// if err := streamWriter.Flush(); err != nil {
93+
// if err := sw.Flush(); err != nil {
9094
// fmt.Println(err)
9195
// return
9296
// }
93-
// if err := file.SaveAs("Book1.xlsx"); err != nil {
97+
// if err := f.SaveAs("Book1.xlsx"); err != nil {
9498
// fmt.Println(err)
9599
// }
96100
//
97101
// Set cell value and cell formula for a worksheet with stream writer:
98102
//
99-
// err := streamWriter.SetRow("A1", []interface{}{
103+
// err := sw.SetRow("A1", []interface{}{
100104
// excelize.Cell{Value: 1},
101105
// excelize.Cell{Value: 2},
102106
// excelize.Cell{Formula: "SUM(A1,B1)"}});
103107
//
104108
// Set cell value and rows style for a worksheet with stream writer:
105109
//
106-
// err := streamWriter.SetRow("A1", []interface{}{
110+
// err := sw.SetRow("A1", []interface{}{
107111
// excelize.Cell{Value: 1}},
108112
// excelize.RowOpts{StyleID: styleID, Height: 20, Hidden: false});
109113
func (f *File) NewStreamWriter(sheet string) (*StreamWriter, error) {
@@ -432,7 +436,7 @@ func (sw *StreamWriter) SetRow(cell string, values []interface{}, opts ...RowOpt
432436
// the 'SetColWidth' function before the 'SetRow' function. For example set
433437
// the width column B:C as 20:
434438
//
435-
// err := streamWriter.SetColWidth(2, 3, 20)
439+
// err := sw.SetColWidth(2, 3, 20)
436440
func (sw *StreamWriter) SetColWidth(min, max int, width float64) error {
437441
if sw.sheetWritten {
438442
return ErrStreamSetColWidth

0 commit comments

Comments
 (0)