summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--README_zh.md2
-rw-r--r--chart.go2
-rw-r--r--excelize_test.go8
-rw-r--r--picture.go11
-rw-r--r--shape.go2
-rw-r--r--sheet.go6
-rw-r--r--xmlDrawing.go1
8 files changed, 20 insertions, 14 deletions
diff --git a/README.md b/README.md
index 9a7f058..d9c70df 100644
--- a/README.md
+++ b/README.md
@@ -11,7 +11,7 @@
## Introduction
-Excelize is a library written in pure Golang and providing a set of functions that allow you to write to and read from XLSX files. Support reads and writes XLSX file generated by Microsoft Excel™ 2007 and later. Support save file without losing original charts of XLSX. This library needs Go version 1.8 or later. The full API docs can be seen using go's built-in documentation tool, or online at [godoc.org](https://godoc.org/github.com/360EntSecGroup-Skylar/excelize) or [Chinese translation](https://xuri.me/excelize/zh_cn).
+Excelize is a library written in pure Golang and providing a set of functions that allow you to write to and read from XLSX files. Support reads and writes XLSX file generated by Microsoft Excel™ 2007 and later. Support save file without losing original charts of XLSX. This library needs Go version 1.8 or later. The full API docs can be seen using go's built-in documentation tool, or online at [godoc.org](https://godoc.org/github.com/360EntSecGroup-Skylar/excelize) and [Chinese translation](https://xuri.me/excelize/zh_cn).
## Basic Usage
diff --git a/README_zh.md b/README_zh.md
index fc3651a..ef149b0 100644
--- a/README_zh.md
+++ b/README_zh.md
@@ -11,7 +11,7 @@
## 简介
-Excelize 是 Go 语言编写的用于操作 Office Excel 文档类库,基于 ECMA-376 Office OpenXML 标准。可以使用它来读取、写入由 Microsoft Excel™ 2007 及以上版本创建的 XLSX 文档。相比较其他的开源类库,Excelize 支持写入原本带有图片(表)、透视表和切片器等复杂样式的文档,还支持向 Excel 文档中插入图片与图表,并且在保存后不会丢失文档原有样式,可以应用于各类报表系统中。使用本类库要求使用的 Go 语言为 1.8 或更高版本,完整的 API 使用文档请访问 [godoc.org](https://godoc.org/github.com/360EntSecGroup-Skylar/excelize) 或 [中文翻译](https://xuri.me/excelize/zh_cn)。
+Excelize 是 Go 语言编写的用于操作 Office Excel 文档类库,基于 ECMA-376 Office OpenXML 标准。可以使用它来读取、写入由 Microsoft Excel™ 2007 及以上版本创建的 XLSX 文档。相比较其他的开源类库,Excelize 支持写入原本带有图片(表)、透视表和切片器等复杂样式的文档,还支持向 Excel 文档中插入图片与图表,并且在保存后不会丢失文档原有样式,可以应用于各类报表系统中。使用本类库要求使用的 Go 语言为 1.8 或更高版本,完整的 API 使用文档请访问 [godoc.org](https://godoc.org/github.com/360EntSecGroup-Skylar/excelize) 或查看 [中文翻译](https://xuri.me/excelize/zh_cn)。
## 快速上手
diff --git a/chart.go b/chart.go
index 4a2774c..6168553 100644
--- a/chart.go
+++ b/chart.go
@@ -1111,7 +1111,7 @@ func (f *File) addDrawingChart(sheet, drawingXML, cell string, width, height, rI
content.Xdr = NameSpaceDrawingMLSpreadSheet
cNvPrID := f.drawingParser(drawingXML, &content)
twoCellAnchor := xdrCellAnchor{}
- twoCellAnchor.EditAs = "oneCell"
+ twoCellAnchor.EditAs = formatSet.Positioning
from := xlsxFrom{}
from.Col = colStart
from.ColOff = formatSet.OffsetX * EMU
diff --git a/excelize_test.go b/excelize_test.go
index b5fa0d1..f2dd0d0 100644
--- a/excelize_test.go
+++ b/excelize_test.go
@@ -137,8 +137,8 @@ func TestAddPicture(t *testing.T) {
if err != nil {
t.Log(err)
}
- // Test add picture to worksheet with offset and external hyperlink.
- err = xlsx.AddPicture("Sheet1", "F21", "./test/images/excel.png", `{"x_offset": 10, "y_offset": 10, "hyperlink": "https://github.com/360EntSecGroup-Skylar/excelize", "hyperlink_type": "External"}`)
+ // Test add picture to worksheet with offset, external hyperlink and positioning.
+ err = xlsx.AddPicture("Sheet1", "F21", "./test/images/excel.png", `{"x_offset": 10, "y_offset": 10, "hyperlink": "https://github.com/360EntSecGroup-Skylar/excelize", "hyperlink_type": "External", "positioning": "oneCell"}`)
if err != nil {
t.Log(err)
}
@@ -196,8 +196,8 @@ func TestNewFile(t *testing.T) {
xlsx.SetCellInt("XLSXSheet2", "A23", 56)
xlsx.SetCellStr("Sheet1", "B20", "42")
xlsx.SetActiveSheet(0)
- // Test add picture to sheet with scaling.
- err := xlsx.AddPicture("Sheet1", "H2", "./test/images/excel.gif", `{"x_scale": 0.5, "y_scale": 0.5}`)
+ // Test add picture to sheet with scaling and positioning.
+ err := xlsx.AddPicture("Sheet1", "H2", "./test/images/excel.gif", `{"x_scale": 0.5, "y_scale": 0.5, "positioning": "absolute"}`)
if err != nil {
t.Log(err)
}
diff --git a/picture.go b/picture.go
index 1f556c4..a7f48d1 100644
--- a/picture.go
+++ b/picture.go
@@ -57,8 +57,8 @@ func parseFormatPictureSet(formatSet string) *formatPicture {
// if err != nil {
// fmt.Println(err)
// }
-// // Insert a picture offset in the cell with external hyperlink and printing support.
-// err = xlsx.AddPicture("Sheet1", "H2", "./image3.gif", `{"x_offset": 15, "y_offset": 10, "hyperlink": "https://github.com/360EntSecGroup-Skylar/excelize", "hyperlink_type": "External", "print_obj": true, "lock_aspect_ratio": false, "locked": false}`)
+// // Insert a picture offset in the cell with external hyperlink, printing and positioning support.
+// err = xlsx.AddPicture("Sheet1", "H2", "./image3.gif", `{"x_offset": 15, "y_offset": 10, "hyperlink": "https://github.com/360EntSecGroup-Skylar/excelize", "hyperlink_type": "External", "print_obj": true, "lock_aspect_ratio": false, "locked": false, "positioning": "oneCell"}`)
// if err != nil {
// fmt.Println(err)
// }
@@ -71,6 +71,11 @@ func parseFormatPictureSet(formatSet string) *formatPicture {
// LinkType defines two types of hyperlink "External" for web site or
// "Location" for moving to one of cell in this workbook. When the
// "hyperlink_type" is "Location", coordinates need to start with "#".
+//
+// Positioning defines two types of the position of a picture in an Excel
+// spreadsheet, "oneCell" (Move but don't size with cells) or "absolute"
+// (Don't move or size with cells). If you don't set this parameter, default
+// positioning is move and size with cells.
func (f *File) AddPicture(sheet, cell, picture, format string) error {
var err error
var drawingHyperlinkRID int
@@ -217,7 +222,7 @@ func (f *File) addDrawingPicture(sheet, drawingXML, cell, file string, width, he
content.Xdr = NameSpaceDrawingMLSpreadSheet
cNvPrID := f.drawingParser(drawingXML, &content)
twoCellAnchor := xdrCellAnchor{}
- twoCellAnchor.EditAs = "oneCell"
+ twoCellAnchor.EditAs = formatSet.Positioning
from := xlsxFrom{}
from.Col = colStart
from.ColOff = formatSet.OffsetX * EMU
diff --git a/shape.go b/shape.go
index 1c9039b..f1328f7 100644
--- a/shape.go
+++ b/shape.go
@@ -285,7 +285,7 @@ func (f *File) addDrawingShape(sheet, drawingXML, cell string, formatSet *format
content.Xdr = NameSpaceDrawingMLSpreadSheet
cNvPrID := f.drawingParser(drawingXML, &content)
twoCellAnchor := xdrCellAnchor{}
- twoCellAnchor.EditAs = "oneCell"
+ twoCellAnchor.EditAs = formatSet.Format.Positioning
from := xlsxFrom{}
from.Col = colStart
from.ColOff = formatSet.Format.OffsetX * EMU
diff --git a/sheet.go b/sheet.go
index bc7cb75..f2b6e17 100644
--- a/sheet.go
+++ b/sheet.go
@@ -12,9 +12,9 @@ import (
"unicode/utf8"
)
-// NewSheet provides function to create a new sheet by given index, when
-// creating a new XLSX file, the default sheet will be create, when you create
-// a new file.
+// NewSheet provides function to create a new sheet by given worksheet name,
+// when creating a new XLSX file, the default sheet will be create, when you
+// create a new file.
func (f *File) NewSheet(name string) int {
// Check if the worksheet already exists
if f.GetSheetIndex(name) != 0 {
diff --git a/xmlDrawing.go b/xmlDrawing.go
index 600d83a..beb6bc9 100644
--- a/xmlDrawing.go
+++ b/xmlDrawing.go
@@ -360,6 +360,7 @@ type formatPicture struct {
YScale float64 `json:"y_scale"`
Hyperlink string `json:"hyperlink"`
HyperlinkType string `json:"hyperlink_type"`
+ Positioning string `json:"positioning"`
}
// formatShape directly maps the format settings of the shape.