未验证 提交 ce4f7a25 编写于 作者: B Bayzet Tlyupov 提交者: GitHub

This closes #1416, support set row outline level to stream (#1422)

Co-authored-by: NTlyupovBM <bajjzet.tlyupov@vseinstrumenti.ru>
上级 61fda0b1
......@@ -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())
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册