summaryrefslogtreecommitdiff
path: root/picture.go
diff options
context:
space:
mode:
Diffstat (limited to 'picture.go')
-rw-r--r--picture.go129
1 files changed, 63 insertions, 66 deletions
diff --git a/picture.go b/picture.go
index c3d0df7..c78df93 100644
--- a/picture.go
+++ b/picture.go
@@ -42,34 +42,34 @@ func parseFormatPictureSet(formatSet string) (*formatPicture, error) {
// format set (such as offset, scale, aspect ratio setting and print settings)
// and file path. For example:
//
-// package main
+// package main
//
-// import (
-// _ "image/gif"
-// _ "image/jpeg"
-// _ "image/png"
+// import (
+// _ "image/gif"
+// _ "image/jpeg"
+// _ "image/png"
//
-// "github.com/xuri/excelize/v2"
-// )
+// "github.com/xuri/excelize/v2"
+// )
//
-// func main() {
-// f := excelize.NewFile()
-// // Insert a picture.
-// if err := f.AddPicture("Sheet1", "A2", "image.jpg", ""); err != nil {
-// fmt.Println(err)
-// }
-// // Insert a picture scaling in the cell with location hyperlink.
-// if err := f.AddPicture("Sheet1", "D2", "image.png", `{"x_scale": 0.5, "y_scale": 0.5, "hyperlink": "#Sheet2!D8", "hyperlink_type": "Location"}`); err != nil {
-// fmt.Println(err)
-// }
-// // Insert a picture offset in the cell with external hyperlink, printing and positioning support.
-// if err := f.AddPicture("Sheet1", "H2", "image.gif", `{"x_offset": 15, "y_offset": 10, "hyperlink": "https://github.com/xuri/excelize", "hyperlink_type": "External", "print_obj": true, "lock_aspect_ratio": false, "locked": false, "positioning": "oneCell"}`); err != nil {
-// fmt.Println(err)
-// }
-// if err := f.SaveAs("Book1.xlsx"); err != nil {
-// fmt.Println(err)
-// }
-// }
+// func main() {
+// f := excelize.NewFile()
+// // Insert a picture.
+// if err := f.AddPicture("Sheet1", "A2", "image.jpg", ""); err != nil {
+// fmt.Println(err)
+// }
+// // Insert a picture scaling in the cell with location hyperlink.
+// if err := f.AddPicture("Sheet1", "D2", "image.png", `{"x_scale": 0.5, "y_scale": 0.5, "hyperlink": "#Sheet2!D8", "hyperlink_type": "Location"}`); err != nil {
+// fmt.Println(err)
+// }
+// // Insert a picture offset in the cell with external hyperlink, printing and positioning support.
+// if err := f.AddPicture("Sheet1", "H2", "image.gif", `{"x_offset": 15, "y_offset": 10, "hyperlink": "https://github.com/xuri/excelize", "hyperlink_type": "External", "print_obj": true, "lock_aspect_ratio": false, "locked": false, "positioning": "oneCell"}`); err != nil {
+// fmt.Println(err)
+// }
+// if err := f.SaveAs("Book1.xlsx"); err != nil {
+// fmt.Println(err)
+// }
+// }
//
// The optional parameter "autofit" specifies if you make image size auto-fits the
// cell, the default value of that is 'false'.
@@ -106,7 +106,6 @@ func parseFormatPictureSet(formatSet string) (*formatPicture, error) {
//
// The optional parameter "y_scale" specifies the vertical scale of images,
// the default value of that is 1.0 which presents 100%.
-//
func (f *File) AddPicture(sheet, cell, picture, format string) error {
var err error
// Check picture exists first.
@@ -126,31 +125,30 @@ func (f *File) AddPicture(sheet, cell, picture, format string) error {
// picture format set (such as offset, scale, aspect ratio setting and print
// settings), file base name, extension name and file bytes. For example:
//
-// package main
-//
-// import (
-// "fmt"
-// _ "image/jpeg"
-// "io/ioutil"
+// package main
//
-// "github.com/xuri/excelize/v2"
-// )
+// import (
+// "fmt"
+// _ "image/jpeg"
+// "io/ioutil"
//
-// func main() {
-// f := excelize.NewFile()
+// "github.com/xuri/excelize/v2"
+// )
//
-// file, err := ioutil.ReadFile("image.jpg")
-// if err != nil {
-// fmt.Println(err)
-// }
-// if err := f.AddPictureFromBytes("Sheet1", "A2", "", "Excel Logo", ".jpg", file); err != nil {
-// fmt.Println(err)
-// }
-// if err := f.SaveAs("Book1.xlsx"); err != nil {
-// fmt.Println(err)
-// }
-// }
+// func main() {
+// f := excelize.NewFile()
//
+// file, err := ioutil.ReadFile("image.jpg")
+// if err != nil {
+// fmt.Println(err)
+// }
+// if err := f.AddPictureFromBytes("Sheet1", "A2", "", "Excel Logo", ".jpg", file); err != nil {
+// fmt.Println(err)
+// }
+// if err := f.SaveAs("Book1.xlsx"); err != nil {
+// fmt.Println(err)
+// }
+// }
func (f *File) AddPictureFromBytes(sheet, cell, format, name, extension string, file []byte) error {
var drawingHyperlinkRID int
var hyperlinkType string
@@ -474,25 +472,24 @@ func (f *File) getSheetRelationshipsTargetByID(sheet, rID string) string {
// returns the file name in spreadsheet and file contents as []byte data
// types. For example:
//
-// f, err := excelize.OpenFile("Book1.xlsx")
-// if err != nil {
-// fmt.Println(err)
-// return
-// }
-// defer func() {
-// if err := f.Close(); err != nil {
-// fmt.Println(err)
-// }
-// }()
-// file, raw, err := f.GetPicture("Sheet1", "A2")
-// if err != nil {
-// fmt.Println(err)
-// return
-// }
-// if err := ioutil.WriteFile(file, raw, 0644); err != nil {
-// fmt.Println(err)
-// }
-//
+// f, err := excelize.OpenFile("Book1.xlsx")
+// if err != nil {
+// fmt.Println(err)
+// return
+// }
+// defer func() {
+// if err := f.Close(); err != nil {
+// fmt.Println(err)
+// }
+// }()
+// file, raw, err := f.GetPicture("Sheet1", "A2")
+// if err != nil {
+// fmt.Println(err)
+// return
+// }
+// if err := ioutil.WriteFile(file, raw, 0644); err != nil {
+// fmt.Println(err)
+// }
func (f *File) GetPicture(sheet, cell string) (string, []byte, error) {
col, row, err := CellNameToCoordinates(cell)
if err != nil {