forked from p30928647/excelize
This closes #1508, support SST index which contains blank characters
This commit is contained in:
parent
60b9d029a6
commit
9dbba9f34a
2
cell.go
2
cell.go
|
@ -564,7 +564,7 @@ func (c *xlsxC) getValueFrom(f *File, d *xlsxSST, raw bool) (string, error) {
|
||||||
case "s":
|
case "s":
|
||||||
if c.V != "" {
|
if c.V != "" {
|
||||||
xlsxSI := 0
|
xlsxSI := 0
|
||||||
xlsxSI, _ = strconv.Atoi(c.V)
|
xlsxSI, _ = strconv.Atoi(strings.TrimSpace(c.V))
|
||||||
if _, ok := f.tempFiles.Load(defaultXMLPathSharedStrings); ok {
|
if _, ok := f.tempFiles.Load(defaultXMLPathSharedStrings); ok {
|
||||||
return f.formattedValue(c.S, f.getFromStringItem(xlsxSI), raw)
|
return f.formattedValue(c.S, f.getFromStringItem(xlsxSI), raw)
|
||||||
}
|
}
|
||||||
|
|
|
@ -432,6 +432,11 @@ func TestGetValueFrom(t *testing.T) {
|
||||||
value, err := c.getValueFrom(f, sst, false)
|
value, err := c.getValueFrom(f, sst, false)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "", value)
|
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) {
|
func TestGetCellFormula(t *testing.T) {
|
||||||
|
|
30
stream.go
30
stream.go
|
@ -47,23 +47,23 @@ type StreamWriter struct {
|
||||||
// 16MB. For example, set data for worksheet of size 102400 rows x 50 columns
|
// 16MB. For example, set data for worksheet of size 102400 rows x 50 columns
|
||||||
// with numbers and style:
|
// with numbers and style:
|
||||||
//
|
//
|
||||||
// file := excelize.NewFile()
|
// f := excelize.NewFile()
|
||||||
// defer func() {
|
// defer func() {
|
||||||
// if err := file.Close(); err != nil {
|
// if err := f.Close(); err != nil {
|
||||||
// fmt.Println(err)
|
// fmt.Println(err)
|
||||||
// }
|
// }
|
||||||
// }()
|
// }()
|
||||||
// streamWriter, err := file.NewStreamWriter("Sheet1")
|
// sw, err := f.NewStreamWriter("Sheet1")
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
// fmt.Println(err)
|
// fmt.Println(err)
|
||||||
// return
|
// 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 {
|
// if err != nil {
|
||||||
// fmt.Println(err)
|
// fmt.Println(err)
|
||||||
// return
|
// return
|
||||||
// }
|
// }
|
||||||
// if err := streamWriter.SetRow("A1",
|
// if err := sw.SetRow("A1",
|
||||||
// []interface{}{
|
// []interface{}{
|
||||||
// excelize.Cell{StyleID: styleID, Value: "Data"},
|
// excelize.Cell{StyleID: styleID, Value: "Data"},
|
||||||
// []excelize.RichTextRun{
|
// []excelize.RichTextRun{
|
||||||
|
@ -80,30 +80,34 @@ type StreamWriter struct {
|
||||||
// for colID := 0; colID < 50; colID++ {
|
// for colID := 0; colID < 50; colID++ {
|
||||||
// row[colID] = rand.Intn(640000)
|
// row[colID] = rand.Intn(640000)
|
||||||
// }
|
// }
|
||||||
// cell, _ := excelize.CoordinatesToCellName(1, rowID)
|
// cell, err := excelize.CoordinatesToCellName(1, rowID)
|
||||||
// if err := streamWriter.SetRow(cell, row); err != nil {
|
// if err != nil {
|
||||||
// fmt.Println(err)
|
// 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)
|
// fmt.Println(err)
|
||||||
// return
|
// return
|
||||||
// }
|
// }
|
||||||
// if err := file.SaveAs("Book1.xlsx"); err != nil {
|
// if err := f.SaveAs("Book1.xlsx"); err != nil {
|
||||||
// fmt.Println(err)
|
// fmt.Println(err)
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// Set cell value and cell formula for a worksheet with stream writer:
|
// 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: 1},
|
||||||
// excelize.Cell{Value: 2},
|
// excelize.Cell{Value: 2},
|
||||||
// excelize.Cell{Formula: "SUM(A1,B1)"}});
|
// excelize.Cell{Formula: "SUM(A1,B1)"}});
|
||||||
//
|
//
|
||||||
// Set cell value and rows style for a worksheet with stream writer:
|
// 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.Cell{Value: 1}},
|
||||||
// excelize.RowOpts{StyleID: styleID, Height: 20, Hidden: false});
|
// excelize.RowOpts{StyleID: styleID, Height: 20, Hidden: false});
|
||||||
func (f *File) NewStreamWriter(sheet string) (*StreamWriter, error) {
|
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 'SetColWidth' function before the 'SetRow' function. For example set
|
||||||
// the width column B:C as 20:
|
// 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 {
|
func (sw *StreamWriter) SetColWidth(min, max int, width float64) error {
|
||||||
if sw.sheetWritten {
|
if sw.sheetWritten {
|
||||||
return ErrStreamSetColWidth
|
return ErrStreamSetColWidth
|
||||||
|
|
Loading…
Reference in New Issue