Skip to content

Commit ce4f7a2

Browse files
BayzetTlyupovBM
and
TlyupovBM
authored
This closes qax-os#1416, support set row outline level to stream (qax-os#1422)
Co-authored-by: TlyupovBM <bajjzet.tlyupov@vseinstrumenti.ru>
1 parent 61fda0b commit ce4f7a2

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

stream.go

+13-3
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,10 @@ type Cell struct {
310310
// RowOpts define the options for the set row, it can be used directly in
311311
// StreamWriter.SetRow to specify the style and properties of the row.
312312
type RowOpts struct {
313-
Height float64
314-
Hidden bool
315-
StyleID int
313+
Height float64
314+
Hidden bool
315+
StyleID int
316+
OutlineLevel int
316317
}
317318

318319
// marshalAttrs prepare attributes of the row.
@@ -328,6 +329,10 @@ func (r *RowOpts) marshalAttrs() (strings.Builder, error) {
328329
err = ErrMaxRowHeight
329330
return attrs, err
330331
}
332+
if r.OutlineLevel > 7 {
333+
err = ErrOutlineLevel
334+
return attrs, err
335+
}
331336
if r.StyleID > 0 {
332337
attrs.WriteString(` s="`)
333338
attrs.WriteString(strconv.Itoa(r.StyleID))
@@ -338,6 +343,11 @@ func (r *RowOpts) marshalAttrs() (strings.Builder, error) {
338343
attrs.WriteString(strconv.FormatFloat(r.Height, 'f', -1, 64))
339344
attrs.WriteString(`" customHeight="1"`)
340345
}
346+
if r.OutlineLevel > 0 {
347+
attrs.WriteString(` outlineLevel="`)
348+
attrs.WriteString(strconv.Itoa(r.OutlineLevel))
349+
attrs.WriteString(`"`)
350+
}
341351
if r.Hidden {
342352
attrs.WriteString(` hidden="1"`)
343353
}

stream_test.go

+28
Original file line numberDiff line numberDiff line change
@@ -358,3 +358,31 @@ func TestStreamSetCellValFunc(t *testing.T) {
358358
assert.NoError(t, sw.setCellValFunc(c, nil))
359359
assert.NoError(t, sw.setCellValFunc(c, complex64(5+10i)))
360360
}
361+
362+
func TestStreamWriterOutlineLevel(t *testing.T) {
363+
file := NewFile()
364+
streamWriter, err := file.NewStreamWriter("Sheet1")
365+
assert.NoError(t, err)
366+
367+
// Test set outlineLevel in row.
368+
assert.NoError(t, streamWriter.SetRow("A1", nil, RowOpts{OutlineLevel: 1}))
369+
assert.NoError(t, streamWriter.SetRow("A2", nil, RowOpts{OutlineLevel: 7}))
370+
assert.ErrorIs(t, ErrOutlineLevel, streamWriter.SetRow("A3", nil, RowOpts{OutlineLevel: 8}))
371+
372+
assert.NoError(t, streamWriter.Flush())
373+
// Save spreadsheet by the given path.
374+
assert.NoError(t, file.SaveAs(filepath.Join("test", "TestStreamWriterSetRowOutlineLevel.xlsx")))
375+
376+
file, err = OpenFile(filepath.Join("test", "TestStreamWriterSetRowOutlineLevel.xlsx"))
377+
assert.NoError(t, err)
378+
level, err := file.GetRowOutlineLevel("Sheet1", 1)
379+
assert.NoError(t, err)
380+
assert.Equal(t, uint8(1), level)
381+
level, err = file.GetRowOutlineLevel("Sheet1", 2)
382+
assert.NoError(t, err)
383+
assert.Equal(t, uint8(7), level)
384+
level, err = file.GetRowOutlineLevel("Sheet1", 3)
385+
assert.NoError(t, err)
386+
assert.Equal(t, uint8(0), level)
387+
assert.NoError(t, file.Close())
388+
}

0 commit comments

Comments
 (0)