diff options
author | jianxinhou <51222175+jianxinhou@users.noreply.github.com> | 2022-12-01 10:44:28 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-01 10:44:28 +0800 |
commit | 5e0953d7783ce65707fa89f5a773697b69e82e96 (patch) | |
tree | 8d5ff97b90a74b0db70a316151e51f3ed7e8c5d0 /sheet_test.go | |
parent | c0713951c8d95fba3a23da39bfb5c85d858d2338 (diff) |
This closes #1405, add new function SetSheetBackgroundFromBytes (#1406)
Co-authored-by: houjianxin.rupert <houjianxin.rupert@bytedance.com>
Diffstat (limited to 'sheet_test.go')
-rw-r--r-- | sheet_test.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/sheet_test.go b/sheet_test.go index 08c7c1a..2494cfb 100644 --- a/sheet_test.go +++ b/sheet_test.go @@ -3,6 +3,8 @@ package excelize import ( "encoding/xml" "fmt" + "io" + "os" "path/filepath" "strconv" "strings" @@ -463,3 +465,25 @@ func TestAttrValToFloat(t *testing.T) { assert.NoError(t, err) assert.Equal(t, 42.1, got) } + +func TestSetSheetBackgroundFromBytes(t *testing.T) { + f := NewFile() + f.SetSheetName("Sheet1", ".svg") + for i, imageTypes := range []string{".svg", ".emf", ".emz", ".gif", ".jpg", ".png", ".tif", ".wmf", ".wmz"} { + file := fmt.Sprintf("excelize%s", imageTypes) + if i > 0 { + file = filepath.Join("test", "images", fmt.Sprintf("excel%s", imageTypes)) + f.NewSheet(imageTypes) + } + img, err := os.Open(file) + assert.NoError(t, err) + content, err := io.ReadAll(img) + assert.NoError(t, err) + assert.NoError(t, img.Close()) + assert.NoError(t, f.SetSheetBackgroundFromBytes(imageTypes, imageTypes, content)) + } + assert.NoError(t, f.SaveAs(filepath.Join("test", "TestSetSheetBackgroundFromBytes.xlsx"))) + assert.NoError(t, f.Close()) + + assert.EqualError(t, f.SetSheetBackgroundFromBytes("Sheet1", ".svg", nil), ErrParameterInvalid.Error()) +} |