summaryrefslogtreecommitdiff
path: root/sheet_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'sheet_test.go')
-rw-r--r--sheet_test.go24
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())
+}