代码拉取完成,页面将自动刷新
同步操作将从 xuri/excelize 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
package excelize
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestSetPageMargins(t *testing.T) {
f := NewFile()
assert.NoError(t, f.SetPageMargins("Sheet1", nil))
ws, ok := f.Sheet.Load("xl/worksheets/sheet1.xml")
assert.True(t, ok)
ws.(*xlsxWorksheet).PageMargins = nil
ws.(*xlsxWorksheet).PrintOptions = nil
expected := PageLayoutMarginsOptions{
Bottom: float64Ptr(1.0),
Footer: float64Ptr(1.0),
Header: float64Ptr(1.0),
Left: float64Ptr(1.0),
Right: float64Ptr(1.0),
Top: float64Ptr(1.0),
Horizontally: boolPtr(true),
Vertically: boolPtr(true),
}
assert.NoError(t, f.SetPageMargins("Sheet1", &expected))
opts, err := f.GetPageMargins("Sheet1")
assert.NoError(t, err)
assert.Equal(t, expected, opts)
// Test set page margins on not exists worksheet
assert.EqualError(t, f.SetPageMargins("SheetN", nil), "sheet SheetN does not exist")
// Test set page margins with invalid sheet name
assert.Equal(t, ErrSheetNameInvalid, f.SetPageMargins("Sheet:1", nil))
}
func TestGetPageMargins(t *testing.T) {
f := NewFile()
// Test get page margins on not exists worksheet
_, err := f.GetPageMargins("SheetN")
assert.EqualError(t, err, "sheet SheetN does not exist")
// Test get page margins with invalid sheet name
_, err = f.GetPageMargins("Sheet:1")
assert.Equal(t, ErrSheetNameInvalid, err)
}
func TestSetSheetProps(t *testing.T) {
f := NewFile()
assert.NoError(t, f.SetSheetProps("Sheet1", nil))
ws, ok := f.Sheet.Load("xl/worksheets/sheet1.xml")
assert.True(t, ok)
ws.(*xlsxWorksheet).SheetPr = nil
ws.(*xlsxWorksheet).SheetFormatPr = nil
baseColWidth, enable := uint8(8), boolPtr(true)
expected := SheetPropsOptions{
CodeName: stringPtr("code"),
EnableFormatConditionsCalculation: enable,
Published: enable,
AutoPageBreaks: enable,
FitToPage: enable,
TabColorIndexed: intPtr(1),
TabColorRGB: stringPtr("FFFF00"),
TabColorTheme: intPtr(1),
TabColorTint: float64Ptr(1),
OutlineSummaryBelow: enable,
OutlineSummaryRight: enable,
BaseColWidth: &baseColWidth,
DefaultColWidth: float64Ptr(10),
DefaultRowHeight: float64Ptr(10),
CustomHeight: enable,
ZeroHeight: enable,
ThickTop: enable,
ThickBottom: enable,
}
assert.NoError(t, f.SetSheetProps("Sheet1", &expected))
opts, err := f.GetSheetProps("Sheet1")
assert.NoError(t, err)
assert.Equal(t, expected, opts)
ws.(*xlsxWorksheet).SheetPr = nil
assert.NoError(t, f.SetSheetProps("Sheet1", &SheetPropsOptions{FitToPage: enable}))
ws.(*xlsxWorksheet).SheetPr = nil
assert.NoError(t, f.SetSheetProps("Sheet1", &SheetPropsOptions{TabColorRGB: stringPtr("FFFF00")}))
ws.(*xlsxWorksheet).SheetPr = nil
assert.NoError(t, f.SetSheetProps("Sheet1", &SheetPropsOptions{TabColorTheme: intPtr(1)}))
ws.(*xlsxWorksheet).SheetPr = nil
assert.NoError(t, f.SetSheetProps("Sheet1", &SheetPropsOptions{TabColorTint: float64Ptr(1)}))
// Test set worksheet properties on not exists worksheet
assert.EqualError(t, f.SetSheetProps("SheetN", nil), "sheet SheetN does not exist")
// Test set worksheet properties with invalid sheet name
assert.Equal(t, ErrSheetNameInvalid, f.SetSheetProps("Sheet:1", nil))
}
func TestGetSheetProps(t *testing.T) {
f := NewFile()
// Test get worksheet properties on not exists worksheet
_, err := f.GetSheetProps("SheetN")
assert.EqualError(t, err, "sheet SheetN does not exist")
// Test get worksheet properties with invalid sheet name
_, err = f.GetSheetProps("Sheet:1")
assert.Equal(t, ErrSheetNameInvalid, err)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。