- Support to set the positioning of a picture, relate issue #214;
- go test and godoc has been updated
This commit is contained in:
parent
9ee57fdb38
commit
a9c7d6637c
|
@ -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
|
||||
|
||||
|
|
|
@ -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)。
|
||||
|
||||
## 快速上手
|
||||
|
||||
|
|
2
chart.go
2
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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
11
picture.go
11
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
|
||||
|
|
2
shape.go
2
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
|
||||
|
|
6
sheet.go
6
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 {
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue