代码拉取完成,页面将自动刷新
package excelize
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestSetView(t *testing.T) {
f := NewFile()
assert.NoError(t, f.SetSheetView("Sheet1", -1, nil))
ws, ok := f.Sheet.Load("xl/worksheets/sheet1.xml")
assert.True(t, ok)
ws.(*xlsxWorksheet).SheetViews = nil
expected := ViewOptions{
DefaultGridColor: boolPtr(false),
RightToLeft: boolPtr(false),
ShowFormulas: boolPtr(false),
ShowGridLines: boolPtr(false),
ShowRowColHeaders: boolPtr(false),
ShowRuler: boolPtr(false),
ShowZeros: boolPtr(false),
TopLeftCell: stringPtr("A1"),
View: stringPtr("normal"),
ZoomScale: float64Ptr(120),
}
assert.NoError(t, f.SetSheetView("Sheet1", 0, &expected))
opts, err := f.GetSheetView("Sheet1", 0)
assert.NoError(t, err)
assert.Equal(t, expected, opts)
// Test set sheet view options with invalid view index
assert.EqualError(t, f.SetSheetView("Sheet1", 1, nil), "view index 1 out of range")
assert.EqualError(t, f.SetSheetView("Sheet1", -2, nil), "view index -2 out of range")
// Test set sheet view options on not exists worksheet
assert.EqualError(t, f.SetSheetView("SheetN", 0, nil), "sheet SheetN does not exist")
}
func TestGetView(t *testing.T) {
f := NewFile()
_, err := f.getSheetView("SheetN", 0)
assert.EqualError(t, err, "sheet SheetN does not exist")
// Test get sheet view options with invalid view index
_, err = f.GetSheetView("Sheet1", 1)
assert.EqualError(t, err, "view index 1 out of range")
_, err = f.GetSheetView("Sheet1", -2)
assert.EqualError(t, err, "view index -2 out of range")
// Test get sheet view options on not exists worksheet
_, err = f.GetSheetView("SheetN", 0)
assert.EqualError(t, err, "sheet SheetN does not exist")
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。