Skip to content

Commit

Permalink
This closes qax-os#1508, support SST index which contains blank chara…
Browse files Browse the repository at this point in the history
…cters
  • Loading branch information
xuri committed Mar 27, 2023
1 parent 0d253df commit b564528
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cell.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
5 changes: 5 additions & 0 deletions cell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
30 changes: 17 additions & 13 deletions stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b564528

Please sign in to comment.