MCPcopy
hub / github.com/qax-os/excelize / TestStreamWriter

Function TestStreamWriter

stream_test.go:41–155  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

39}
40
41func TestStreamWriter(t *testing.T) {
42 file := NewFile()
43 streamWriter, err := file.NewStreamWriter("Sheet1")
44 assert.NoError(t, err)
45
46 // Test max characters in a cell
47 row := make([]interface{}, 1)
48 row[0] = strings.Repeat("c", TotalCellChars+2)
49 assert.NoError(t, streamWriter.SetRow("A1", row))
50
51 // Test leading and ending space(s) character characters in a cell
52 row = make([]interface{}, 1)
53 row[0] = " characters"
54 assert.NoError(t, streamWriter.SetRow("A2", row))
55
56 row = make([]interface{}, 1)
57 row[0] = []byte("Word")
58 assert.NoError(t, streamWriter.SetRow("A3", row))
59
60 // Test set cell with style and rich text
61 styleID, err := file.NewStyle(&Style{Font: &Font{Color: "777777"}})
62 assert.NoError(t, err)
63 assert.NoError(t, streamWriter.SetRow("A4", []interface{}{
64 Cell{StyleID: styleID},
65 Cell{Formula: "SUM(A10,B10)", Value: " preserve space "},
66 },
67 RowOpts{Height: 45, StyleID: styleID}))
68 assert.NoError(t, streamWriter.SetRow("A5", []interface{}{
69 &Cell{StyleID: styleID, Value: "cell <>&'\""},
70 &Cell{Formula: "SUM(A10,B10)"},
71 []RichTextRun{
72 {Text: "Rich ", Font: &Font{Color: "2354E8"}},
73 {Text: "Text", Font: &Font{Color: "E83723"}},
74 },
75 }))
76 assert.NoError(t, streamWriter.SetRow("A6", []interface{}{time.Now()}))
77 assert.NoError(t, streamWriter.SetRow("A7", nil, RowOpts{Height: 20, Hidden: true, StyleID: styleID}))
78 assert.Equal(t, ErrMaxRowHeight, streamWriter.SetRow("A8", nil, RowOpts{Height: MaxRowHeight + 1}))
79
80 assert.NoError(t, streamWriter.SetRow("A9", []interface{}{math.NaN(), math.Inf(0), math.Inf(-1)}))
81
82 for rowID := 10; rowID <= 51200; rowID++ {
83 row := make([]interface{}, 50)
84 for colID := 0; colID < 50; colID++ {
85 row[colID] = rand.Intn(640000)
86 }
87 cell, _ := CoordinatesToCellName(1, rowID)
88 assert.NoError(t, streamWriter.SetRow(cell, row))
89 }
90
91 assert.NoError(t, streamWriter.Flush())
92 // Save spreadsheet by the given path
93 assert.NoError(t, file.SaveAs(filepath.Join("test", "TestStreamWriter.xlsx")))
94
95 // Test set cell column overflow
96 assert.ErrorIs(t, streamWriter.SetRow("XFD51201", []interface{}{"A", "B", "C"}), ErrColumnNumber)
97 assert.NoError(t, file.Close())
98

Callers

nothing calls this directly

Calls 15

NewStreamWriterMethod · 0.95
SetRowMethod · 0.95
NewStyleMethod · 0.95
FlushMethod · 0.95
SaveAsMethod · 0.95
CloseMethod · 0.95
GetCellValueMethod · 0.95
RowsMethod · 0.95
NewFileFunction · 0.85
CoordinatesToCellNameFunction · 0.85
OpenFileFunction · 0.85
ReaderMethod · 0.80

Tested by

no test coverage detected