forked from p30928647/excelize
Co-authored-by: TlyupovBM <bajjzet.tlyupov@vseinstrumenti.ru>
This commit is contained in:
parent
61fda0b1ca
commit
ce4f7a25c9
16
stream.go
16
stream.go
|
@ -310,9 +310,10 @@ type Cell struct {
|
|||
// RowOpts define the options for the set row, it can be used directly in
|
||||
// StreamWriter.SetRow to specify the style and properties of the row.
|
||||
type RowOpts struct {
|
||||
Height float64
|
||||
Hidden bool
|
||||
StyleID int
|
||||
Height float64
|
||||
Hidden bool
|
||||
StyleID int
|
||||
OutlineLevel int
|
||||
}
|
||||
|
||||
// marshalAttrs prepare attributes of the row.
|
||||
|
@ -328,6 +329,10 @@ func (r *RowOpts) marshalAttrs() (strings.Builder, error) {
|
|||
err = ErrMaxRowHeight
|
||||
return attrs, err
|
||||
}
|
||||
if r.OutlineLevel > 7 {
|
||||
err = ErrOutlineLevel
|
||||
return attrs, err
|
||||
}
|
||||
if r.StyleID > 0 {
|
||||
attrs.WriteString(` s="`)
|
||||
attrs.WriteString(strconv.Itoa(r.StyleID))
|
||||
|
@ -338,6 +343,11 @@ func (r *RowOpts) marshalAttrs() (strings.Builder, error) {
|
|||
attrs.WriteString(strconv.FormatFloat(r.Height, 'f', -1, 64))
|
||||
attrs.WriteString(`" customHeight="1"`)
|
||||
}
|
||||
if r.OutlineLevel > 0 {
|
||||
attrs.WriteString(` outlineLevel="`)
|
||||
attrs.WriteString(strconv.Itoa(r.OutlineLevel))
|
||||
attrs.WriteString(`"`)
|
||||
}
|
||||
if r.Hidden {
|
||||
attrs.WriteString(` hidden="1"`)
|
||||
}
|
||||
|
|
|
@ -358,3 +358,31 @@ func TestStreamSetCellValFunc(t *testing.T) {
|
|||
assert.NoError(t, sw.setCellValFunc(c, nil))
|
||||
assert.NoError(t, sw.setCellValFunc(c, complex64(5+10i)))
|
||||
}
|
||||
|
||||
func TestStreamWriterOutlineLevel(t *testing.T) {
|
||||
file := NewFile()
|
||||
streamWriter, err := file.NewStreamWriter("Sheet1")
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Test set outlineLevel in row.
|
||||
assert.NoError(t, streamWriter.SetRow("A1", nil, RowOpts{OutlineLevel: 1}))
|
||||
assert.NoError(t, streamWriter.SetRow("A2", nil, RowOpts{OutlineLevel: 7}))
|
||||
assert.ErrorIs(t, ErrOutlineLevel, streamWriter.SetRow("A3", nil, RowOpts{OutlineLevel: 8}))
|
||||
|
||||
assert.NoError(t, streamWriter.Flush())
|
||||
// Save spreadsheet by the given path.
|
||||
assert.NoError(t, file.SaveAs(filepath.Join("test", "TestStreamWriterSetRowOutlineLevel.xlsx")))
|
||||
|
||||
file, err = OpenFile(filepath.Join("test", "TestStreamWriterSetRowOutlineLevel.xlsx"))
|
||||
assert.NoError(t, err)
|
||||
level, err := file.GetRowOutlineLevel("Sheet1", 1)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, uint8(1), level)
|
||||
level, err = file.GetRowOutlineLevel("Sheet1", 2)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, uint8(7), level)
|
||||
level, err = file.GetRowOutlineLevel("Sheet1", 3)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, uint8(0), level)
|
||||
assert.NoError(t, file.Close())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue