代码拉取完成,页面将自动刷新
同步操作将从 xuri/excelize 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
package excelize_test
import (
"fmt"
"testing"
"github.com/360EntSecGroup-Skylar/excelize"
"github.com/mohae/deepcopy"
"github.com/stretchr/testify/assert"
)
func ExampleFile_SetPageLayout() {
xl := excelize.NewFile()
const sheet = "Sheet1"
if err := xl.SetPageLayout(
"Sheet1",
excelize.PageLayoutOrientation(excelize.OrientationLandscape),
); err != nil {
panic(err)
}
if err := xl.SetPageLayout(
"Sheet1",
excelize.PageLayoutPaperSize(10),
); err != nil {
panic(err)
}
// Output:
}
func ExampleFile_GetPageLayout() {
xl := excelize.NewFile()
const sheet = "Sheet1"
var (
orientation excelize.PageLayoutOrientation
paperSize excelize.PageLayoutPaperSize
)
if err := xl.GetPageLayout("Sheet1", &orientation); err != nil {
panic(err)
}
if err := xl.GetPageLayout("Sheet1", &paperSize); err != nil {
panic(err)
}
fmt.Println("Defaults:")
fmt.Printf("- orientation: %q\n", orientation)
fmt.Printf("- paper size: %d\n", paperSize)
// Output:
// Defaults:
// - orientation: "portrait"
// - paper size: 1
}
func TestPageLayoutOption(t *testing.T) {
const sheet = "Sheet1"
testData := []struct {
container excelize.PageLayoutOptionPtr
nonDefault excelize.PageLayoutOption
}{
{new(excelize.PageLayoutOrientation), excelize.PageLayoutOrientation(excelize.OrientationLandscape)},
{new(excelize.PageLayoutPaperSize), excelize.PageLayoutPaperSize(10)},
}
for i, test := range testData {
t.Run(fmt.Sprintf("TestData%d", i), func(t *testing.T) {
opt := test.nonDefault
t.Logf("option %T", opt)
def := deepcopy.Copy(test.container).(excelize.PageLayoutOptionPtr)
val1 := deepcopy.Copy(def).(excelize.PageLayoutOptionPtr)
val2 := deepcopy.Copy(def).(excelize.PageLayoutOptionPtr)
xl := excelize.NewFile()
// Get the default value
if !assert.NoError(t, xl.GetPageLayout(sheet, def), opt) {
t.FailNow()
}
// Get again and check
if !assert.NoError(t, xl.GetPageLayout(sheet, val1), opt) {
t.FailNow()
}
if !assert.Equal(t, val1, def, opt) {
t.FailNow()
}
// Set the same value
if !assert.NoError(t, xl.SetPageLayout(sheet, val1), opt) {
t.FailNow()
}
// Get again and check
if !assert.NoError(t, xl.GetPageLayout(sheet, val1), opt) {
t.FailNow()
}
if !assert.Equal(t, val1, def, "%T: value should not have changed", opt) {
t.FailNow()
}
// Set a different value
if !assert.NoError(t, xl.SetPageLayout(sheet, test.nonDefault), opt) {
t.FailNow()
}
if !assert.NoError(t, xl.GetPageLayout(sheet, val1), opt) {
t.FailNow()
}
// Get again and compare
if !assert.NoError(t, xl.GetPageLayout(sheet, val2), opt) {
t.FailNow()
}
if !assert.Equal(t, val1, val2, "%T: value should not have changed", opt) {
t.FailNow()
}
// Value should not be the same as the default
if !assert.NotEqual(t, def, val1, "%T: value should have changed from default", opt) {
t.FailNow()
}
// Restore the default value
if !assert.NoError(t, xl.SetPageLayout(sheet, def), opt) {
t.FailNow()
}
if !assert.NoError(t, xl.GetPageLayout(sheet, val1), opt) {
t.FailNow()
}
if !assert.Equal(t, def, val1) {
t.FailNow()
}
})
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。