summaryrefslogtreecommitdiff
path: root/sheet.go
diff options
context:
space:
mode:
authorxuri <xuri.me@gmail.com>2018-09-14 00:24:49 +0800
committerxuri <xuri.me@gmail.com>2018-09-14 00:24:49 +0800
commit6ced438f39030e8a9a521548d4112dd002dc2ebe (patch)
treeef5f2d12a849d68085a7286a2b983f3ad4369d11 /sheet.go
parent4f47737d64fc9d9108675cbc1e73ae93c2d723a9 (diff)
New function `AddPictureFromBytes()` has been added, this resolve #259 and close #271.
Diffstat (limited to 'sheet.go')
-rw-r--r--sheet.go6
1 files changed, 4 insertions, 2 deletions
diff --git a/sheet.go b/sheet.go
index b5c3e6c..ef2b6f4 100644
--- a/sheet.go
+++ b/sheet.go
@@ -13,6 +13,7 @@ import (
"encoding/json"
"encoding/xml"
"errors"
+ "io/ioutil"
"os"
"path"
"strconv"
@@ -370,7 +371,7 @@ func (f *File) getSheetMap() map[string]string {
}
// SetSheetBackground provides a function to set background picture by given
-// worksheet name.
+// worksheet name and file path.
func (f *File) SetSheetBackground(sheet, picture string) error {
var err error
// Check picture exists first.
@@ -384,7 +385,8 @@ func (f *File) SetSheetBackground(sheet, picture string) error {
pictureID := f.countMedia() + 1
rID := f.addSheetRelationships(sheet, SourceRelationshipImage, "../media/image"+strconv.Itoa(pictureID)+ext, "")
f.addSheetPicture(sheet, rID)
- f.addMedia(picture, ext)
+ file, _ := ioutil.ReadFile(picture)
+ f.addMedia(file, ext)
f.setContentTypePartImageExtensions()
return err
}