2024-01-09 20:56:20 +08:00
|
|
|
// Copyright 2016 - 2024 The excelize Authors. All rights reserved. Use of
|
2018-09-14 00:44:23 +08:00
|
|
|
// this source code is governed by a BSD-style license that can be found in
|
|
|
|
// the LICENSE file.
|
|
|
|
//
|
2022-02-17 00:09:11 +08:00
|
|
|
// Package excelize providing a set of functions that allow you to write to and
|
|
|
|
// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and
|
|
|
|
// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later.
|
|
|
|
// Supports complex components by high compatibility, and provided streaming
|
|
|
|
// API for generating or reading data from a worksheet with huge amounts of
|
2024-01-18 15:31:43 +08:00
|
|
|
// data. This library needs Go version 1.18 or later.
|
2018-09-14 00:58:48 +08:00
|
|
|
|
2017-01-17 19:06:42 +08:00
|
|
|
package excelize
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/xml"
|
2017-01-22 16:16:03 +08:00
|
|
|
"image"
|
2023-12-15 13:09:42 +08:00
|
|
|
"io"
|
2017-01-17 19:06:42 +08:00
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
"path/filepath"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2024-03-27 15:50:51 +08:00
|
|
|
// PictureInsertType defines the type of the picture has been inserted into the
|
|
|
|
// worksheet.
|
|
|
|
type PictureInsertType int
|
|
|
|
|
|
|
|
// Insert picture types.
|
|
|
|
const (
|
|
|
|
PictureInsertTypePlaceOverCells PictureInsertType = iota
|
|
|
|
PictureInsertTypePlaceInCell
|
2024-04-02 08:47:57 +08:00
|
|
|
PictureInsertTypeIMAGE
|
2024-03-27 15:50:51 +08:00
|
|
|
PictureInsertTypeDISPIMG
|
|
|
|
)
|
|
|
|
|
2023-01-02 11:47:31 +08:00
|
|
|
// parseGraphicOptions provides a function to parse the format settings of
|
2018-08-06 10:21:24 +08:00
|
|
|
// the picture with default value.
|
2023-01-02 11:47:31 +08:00
|
|
|
func parseGraphicOptions(opts *GraphicOptions) *GraphicOptions {
|
Breaking change: changed the function signature for 11 exported functions
* Change
`func (f *File) NewConditionalStyle(style string) (int, error)`
to
`func (f *File) NewConditionalStyle(style *Style) (int, error)`
* Change
`func (f *File) NewStyle(style interface{}) (int, error)`
to
`func (f *File) NewStyle(style *Style) (int, error)`
* Change
`func (f *File) AddChart(sheet, cell, opts string, combo ...string) error`
to
`func (f *File) AddChart(sheet, cell string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddChartSheet(sheet, opts string, combo ...string) error`
to
`func (f *File) AddChartSheet(sheet string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddShape(sheet, cell, opts string) error`
to
`func (f *File) AddShape(sheet, cell string, opts *Shape) error`
* Change
`func (f *File) AddPictureFromBytes(sheet, cell, opts, name, extension string, file []byte) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *PictureOptions) error`
* Change
`func (f *File) AddTable(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AddTable(sheet, reference string, opts *TableOptions) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) AutoFilter(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AutoFilter(sheet, reference string, opts *AutoFilterOptions) error`
* Change
`func (f *File) SetPanes(sheet, panes string) error`
to
`func (f *File) SetPanes(sheet string, panes *Panes) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) SetConditionalFormat(sheet, reference, opts string) error`
to
`func (f *File) SetConditionalFormat(sheet, reference string, opts []ConditionalFormatOptions) error`
* Add exported types:
* AutoFilterListOptions
* AutoFilterOptions
* Chart
* ChartAxis
* ChartDimension
* ChartLegend
* ChartLine
* ChartMarker
* ChartPlotArea
* ChartSeries
* ChartTitle
* ConditionalFormatOptions
* PaneOptions
* Panes
* PictureOptions
* Shape
* ShapeColor
* ShapeLine
* ShapeParagraph
* TableOptions
* This added support for set sheet visible as very hidden
* Return error when missing required parameters for set defined name
* Update unit test and comments
2022-12-30 00:50:08 +08:00
|
|
|
if opts == nil {
|
2023-01-02 11:47:31 +08:00
|
|
|
return &GraphicOptions{
|
Breaking change: changed the function signature for 11 exported functions
* Change
`func (f *File) NewConditionalStyle(style string) (int, error)`
to
`func (f *File) NewConditionalStyle(style *Style) (int, error)`
* Change
`func (f *File) NewStyle(style interface{}) (int, error)`
to
`func (f *File) NewStyle(style *Style) (int, error)`
* Change
`func (f *File) AddChart(sheet, cell, opts string, combo ...string) error`
to
`func (f *File) AddChart(sheet, cell string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddChartSheet(sheet, opts string, combo ...string) error`
to
`func (f *File) AddChartSheet(sheet string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddShape(sheet, cell, opts string) error`
to
`func (f *File) AddShape(sheet, cell string, opts *Shape) error`
* Change
`func (f *File) AddPictureFromBytes(sheet, cell, opts, name, extension string, file []byte) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *PictureOptions) error`
* Change
`func (f *File) AddTable(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AddTable(sheet, reference string, opts *TableOptions) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) AutoFilter(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AutoFilter(sheet, reference string, opts *AutoFilterOptions) error`
* Change
`func (f *File) SetPanes(sheet, panes string) error`
to
`func (f *File) SetPanes(sheet string, panes *Panes) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) SetConditionalFormat(sheet, reference, opts string) error`
to
`func (f *File) SetConditionalFormat(sheet, reference string, opts []ConditionalFormatOptions) error`
* Add exported types:
* AutoFilterListOptions
* AutoFilterOptions
* Chart
* ChartAxis
* ChartDimension
* ChartLegend
* ChartLine
* ChartMarker
* ChartPlotArea
* ChartSeries
* ChartTitle
* ConditionalFormatOptions
* PaneOptions
* Panes
* PictureOptions
* Shape
* ShapeColor
* ShapeLine
* ShapeParagraph
* TableOptions
* This added support for set sheet visible as very hidden
* Return error when missing required parameters for set defined name
* Update unit test and comments
2022-12-30 00:50:08 +08:00
|
|
|
PrintObject: boolPtr(true),
|
2023-01-02 11:47:31 +08:00
|
|
|
Locked: boolPtr(true),
|
2023-09-16 12:21:11 +08:00
|
|
|
ScaleX: defaultDrawingScale,
|
|
|
|
ScaleY: defaultDrawingScale,
|
Breaking change: changed the function signature for 11 exported functions
* Change
`func (f *File) NewConditionalStyle(style string) (int, error)`
to
`func (f *File) NewConditionalStyle(style *Style) (int, error)`
* Change
`func (f *File) NewStyle(style interface{}) (int, error)`
to
`func (f *File) NewStyle(style *Style) (int, error)`
* Change
`func (f *File) AddChart(sheet, cell, opts string, combo ...string) error`
to
`func (f *File) AddChart(sheet, cell string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddChartSheet(sheet, opts string, combo ...string) error`
to
`func (f *File) AddChartSheet(sheet string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddShape(sheet, cell, opts string) error`
to
`func (f *File) AddShape(sheet, cell string, opts *Shape) error`
* Change
`func (f *File) AddPictureFromBytes(sheet, cell, opts, name, extension string, file []byte) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *PictureOptions) error`
* Change
`func (f *File) AddTable(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AddTable(sheet, reference string, opts *TableOptions) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) AutoFilter(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AutoFilter(sheet, reference string, opts *AutoFilterOptions) error`
* Change
`func (f *File) SetPanes(sheet, panes string) error`
to
`func (f *File) SetPanes(sheet string, panes *Panes) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) SetConditionalFormat(sheet, reference, opts string) error`
to
`func (f *File) SetConditionalFormat(sheet, reference string, opts []ConditionalFormatOptions) error`
* Add exported types:
* AutoFilterListOptions
* AutoFilterOptions
* Chart
* ChartAxis
* ChartDimension
* ChartLegend
* ChartLine
* ChartMarker
* ChartPlotArea
* ChartSeries
* ChartTitle
* ConditionalFormatOptions
* PaneOptions
* Panes
* PictureOptions
* Shape
* ShapeColor
* ShapeLine
* ShapeParagraph
* TableOptions
* This added support for set sheet visible as very hidden
* Return error when missing required parameters for set defined name
* Update unit test and comments
2022-12-30 00:50:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if opts.PrintObject == nil {
|
|
|
|
opts.PrintObject = boolPtr(true)
|
|
|
|
}
|
|
|
|
if opts.Locked == nil {
|
2023-01-02 11:47:31 +08:00
|
|
|
opts.Locked = boolPtr(true)
|
Breaking change: changed the function signature for 11 exported functions
* Change
`func (f *File) NewConditionalStyle(style string) (int, error)`
to
`func (f *File) NewConditionalStyle(style *Style) (int, error)`
* Change
`func (f *File) NewStyle(style interface{}) (int, error)`
to
`func (f *File) NewStyle(style *Style) (int, error)`
* Change
`func (f *File) AddChart(sheet, cell, opts string, combo ...string) error`
to
`func (f *File) AddChart(sheet, cell string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddChartSheet(sheet, opts string, combo ...string) error`
to
`func (f *File) AddChartSheet(sheet string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddShape(sheet, cell, opts string) error`
to
`func (f *File) AddShape(sheet, cell string, opts *Shape) error`
* Change
`func (f *File) AddPictureFromBytes(sheet, cell, opts, name, extension string, file []byte) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *PictureOptions) error`
* Change
`func (f *File) AddTable(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AddTable(sheet, reference string, opts *TableOptions) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) AutoFilter(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AutoFilter(sheet, reference string, opts *AutoFilterOptions) error`
* Change
`func (f *File) SetPanes(sheet, panes string) error`
to
`func (f *File) SetPanes(sheet string, panes *Panes) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) SetConditionalFormat(sheet, reference, opts string) error`
to
`func (f *File) SetConditionalFormat(sheet, reference string, opts []ConditionalFormatOptions) error`
* Add exported types:
* AutoFilterListOptions
* AutoFilterOptions
* Chart
* ChartAxis
* ChartDimension
* ChartLegend
* ChartLine
* ChartMarker
* ChartPlotArea
* ChartSeries
* ChartTitle
* ConditionalFormatOptions
* PaneOptions
* Panes
* PictureOptions
* Shape
* ShapeColor
* ShapeLine
* ShapeParagraph
* TableOptions
* This added support for set sheet visible as very hidden
* Return error when missing required parameters for set defined name
* Update unit test and comments
2022-12-30 00:50:08 +08:00
|
|
|
}
|
2023-01-02 11:47:31 +08:00
|
|
|
if opts.ScaleX == 0 {
|
2023-09-16 12:21:11 +08:00
|
|
|
opts.ScaleX = defaultDrawingScale
|
Breaking change: changed the function signature for 11 exported functions
* Change
`func (f *File) NewConditionalStyle(style string) (int, error)`
to
`func (f *File) NewConditionalStyle(style *Style) (int, error)`
* Change
`func (f *File) NewStyle(style interface{}) (int, error)`
to
`func (f *File) NewStyle(style *Style) (int, error)`
* Change
`func (f *File) AddChart(sheet, cell, opts string, combo ...string) error`
to
`func (f *File) AddChart(sheet, cell string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddChartSheet(sheet, opts string, combo ...string) error`
to
`func (f *File) AddChartSheet(sheet string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddShape(sheet, cell, opts string) error`
to
`func (f *File) AddShape(sheet, cell string, opts *Shape) error`
* Change
`func (f *File) AddPictureFromBytes(sheet, cell, opts, name, extension string, file []byte) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *PictureOptions) error`
* Change
`func (f *File) AddTable(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AddTable(sheet, reference string, opts *TableOptions) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) AutoFilter(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AutoFilter(sheet, reference string, opts *AutoFilterOptions) error`
* Change
`func (f *File) SetPanes(sheet, panes string) error`
to
`func (f *File) SetPanes(sheet string, panes *Panes) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) SetConditionalFormat(sheet, reference, opts string) error`
to
`func (f *File) SetConditionalFormat(sheet, reference string, opts []ConditionalFormatOptions) error`
* Add exported types:
* AutoFilterListOptions
* AutoFilterOptions
* Chart
* ChartAxis
* ChartDimension
* ChartLegend
* ChartLine
* ChartMarker
* ChartPlotArea
* ChartSeries
* ChartTitle
* ConditionalFormatOptions
* PaneOptions
* Panes
* PictureOptions
* Shape
* ShapeColor
* ShapeLine
* ShapeParagraph
* TableOptions
* This added support for set sheet visible as very hidden
* Return error when missing required parameters for set defined name
* Update unit test and comments
2022-12-30 00:50:08 +08:00
|
|
|
}
|
2023-01-02 11:47:31 +08:00
|
|
|
if opts.ScaleY == 0 {
|
2023-09-16 12:21:11 +08:00
|
|
|
opts.ScaleY = defaultDrawingScale
|
Breaking change: changed the function signature for 11 exported functions
* Change
`func (f *File) NewConditionalStyle(style string) (int, error)`
to
`func (f *File) NewConditionalStyle(style *Style) (int, error)`
* Change
`func (f *File) NewStyle(style interface{}) (int, error)`
to
`func (f *File) NewStyle(style *Style) (int, error)`
* Change
`func (f *File) AddChart(sheet, cell, opts string, combo ...string) error`
to
`func (f *File) AddChart(sheet, cell string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddChartSheet(sheet, opts string, combo ...string) error`
to
`func (f *File) AddChartSheet(sheet string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddShape(sheet, cell, opts string) error`
to
`func (f *File) AddShape(sheet, cell string, opts *Shape) error`
* Change
`func (f *File) AddPictureFromBytes(sheet, cell, opts, name, extension string, file []byte) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *PictureOptions) error`
* Change
`func (f *File) AddTable(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AddTable(sheet, reference string, opts *TableOptions) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) AutoFilter(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AutoFilter(sheet, reference string, opts *AutoFilterOptions) error`
* Change
`func (f *File) SetPanes(sheet, panes string) error`
to
`func (f *File) SetPanes(sheet string, panes *Panes) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) SetConditionalFormat(sheet, reference, opts string) error`
to
`func (f *File) SetConditionalFormat(sheet, reference string, opts []ConditionalFormatOptions) error`
* Add exported types:
* AutoFilterListOptions
* AutoFilterOptions
* Chart
* ChartAxis
* ChartDimension
* ChartLegend
* ChartLine
* ChartMarker
* ChartPlotArea
* ChartSeries
* ChartTitle
* ConditionalFormatOptions
* PaneOptions
* Panes
* PictureOptions
* Shape
* ShapeColor
* ShapeLine
* ShapeParagraph
* TableOptions
* This added support for set sheet visible as very hidden
* Return error when missing required parameters for set defined name
* Update unit test and comments
2022-12-30 00:50:08 +08:00
|
|
|
}
|
|
|
|
return opts
|
2017-02-28 12:59:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// AddPicture provides the method to add picture in a sheet by given picture
|
|
|
|
// format set (such as offset, scale, aspect ratio setting and print settings)
|
2023-02-05 00:21:23 +08:00
|
|
|
// and file path, supported image types: BMP, EMF, EMZ, GIF, JPEG, JPG, PNG,
|
2024-03-27 15:50:51 +08:00
|
|
|
// SVG, TIF, TIFF, WMF, and WMZ. This function is concurrency-safe. Note that
|
|
|
|
// this function only supports adding pictures placed over the cells currently,
|
|
|
|
// and doesn't support adding pictures placed in cells or creating the Kingsoft
|
|
|
|
// WPS Office embedded image cells. For example:
|
2017-01-17 19:06:42 +08:00
|
|
|
//
|
2022-08-13 11:21:59 +08:00
|
|
|
// package main
|
2017-01-22 16:16:03 +08:00
|
|
|
//
|
2022-08-13 11:21:59 +08:00
|
|
|
// import (
|
Breaking change: changed the function signature for 11 exported functions
* Change
`func (f *File) NewConditionalStyle(style string) (int, error)`
to
`func (f *File) NewConditionalStyle(style *Style) (int, error)`
* Change
`func (f *File) NewStyle(style interface{}) (int, error)`
to
`func (f *File) NewStyle(style *Style) (int, error)`
* Change
`func (f *File) AddChart(sheet, cell, opts string, combo ...string) error`
to
`func (f *File) AddChart(sheet, cell string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddChartSheet(sheet, opts string, combo ...string) error`
to
`func (f *File) AddChartSheet(sheet string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddShape(sheet, cell, opts string) error`
to
`func (f *File) AddShape(sheet, cell string, opts *Shape) error`
* Change
`func (f *File) AddPictureFromBytes(sheet, cell, opts, name, extension string, file []byte) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *PictureOptions) error`
* Change
`func (f *File) AddTable(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AddTable(sheet, reference string, opts *TableOptions) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) AutoFilter(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AutoFilter(sheet, reference string, opts *AutoFilterOptions) error`
* Change
`func (f *File) SetPanes(sheet, panes string) error`
to
`func (f *File) SetPanes(sheet string, panes *Panes) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) SetConditionalFormat(sheet, reference, opts string) error`
to
`func (f *File) SetConditionalFormat(sheet, reference string, opts []ConditionalFormatOptions) error`
* Add exported types:
* AutoFilterListOptions
* AutoFilterOptions
* Chart
* ChartAxis
* ChartDimension
* ChartLegend
* ChartLine
* ChartMarker
* ChartPlotArea
* ChartSeries
* ChartTitle
* ConditionalFormatOptions
* PaneOptions
* Panes
* PictureOptions
* Shape
* ShapeColor
* ShapeLine
* ShapeParagraph
* TableOptions
* This added support for set sheet visible as very hidden
* Return error when missing required parameters for set defined name
* Update unit test and comments
2022-12-30 00:50:08 +08:00
|
|
|
// "fmt"
|
2022-08-13 11:21:59 +08:00
|
|
|
// _ "image/gif"
|
|
|
|
// _ "image/jpeg"
|
|
|
|
// _ "image/png"
|
2017-01-22 16:16:03 +08:00
|
|
|
//
|
2022-08-13 11:21:59 +08:00
|
|
|
// "github.com/xuri/excelize/v2"
|
|
|
|
// )
|
2017-01-22 16:16:03 +08:00
|
|
|
//
|
2022-08-13 11:21:59 +08:00
|
|
|
// func main() {
|
|
|
|
// f := excelize.NewFile()
|
2023-01-02 11:47:31 +08:00
|
|
|
// defer func() {
|
|
|
|
// if err := f.Close(); err != nil {
|
|
|
|
// fmt.Println(err)
|
|
|
|
// }
|
|
|
|
// }()
|
2022-08-13 11:21:59 +08:00
|
|
|
// // Insert a picture.
|
Breaking change: changed the function signature for 11 exported functions
* Change
`func (f *File) NewConditionalStyle(style string) (int, error)`
to
`func (f *File) NewConditionalStyle(style *Style) (int, error)`
* Change
`func (f *File) NewStyle(style interface{}) (int, error)`
to
`func (f *File) NewStyle(style *Style) (int, error)`
* Change
`func (f *File) AddChart(sheet, cell, opts string, combo ...string) error`
to
`func (f *File) AddChart(sheet, cell string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddChartSheet(sheet, opts string, combo ...string) error`
to
`func (f *File) AddChartSheet(sheet string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddShape(sheet, cell, opts string) error`
to
`func (f *File) AddShape(sheet, cell string, opts *Shape) error`
* Change
`func (f *File) AddPictureFromBytes(sheet, cell, opts, name, extension string, file []byte) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *PictureOptions) error`
* Change
`func (f *File) AddTable(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AddTable(sheet, reference string, opts *TableOptions) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) AutoFilter(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AutoFilter(sheet, reference string, opts *AutoFilterOptions) error`
* Change
`func (f *File) SetPanes(sheet, panes string) error`
to
`func (f *File) SetPanes(sheet string, panes *Panes) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) SetConditionalFormat(sheet, reference, opts string) error`
to
`func (f *File) SetConditionalFormat(sheet, reference string, opts []ConditionalFormatOptions) error`
* Add exported types:
* AutoFilterListOptions
* AutoFilterOptions
* Chart
* ChartAxis
* ChartDimension
* ChartLegend
* ChartLine
* ChartMarker
* ChartPlotArea
* ChartSeries
* ChartTitle
* ConditionalFormatOptions
* PaneOptions
* Panes
* PictureOptions
* Shape
* ShapeColor
* ShapeLine
* ShapeParagraph
* TableOptions
* This added support for set sheet visible as very hidden
* Return error when missing required parameters for set defined name
* Update unit test and comments
2022-12-30 00:50:08 +08:00
|
|
|
// if err := f.AddPicture("Sheet1", "A2", "image.jpg", nil); err != nil {
|
2022-08-13 11:21:59 +08:00
|
|
|
// fmt.Println(err)
|
2023-01-02 11:47:31 +08:00
|
|
|
// return
|
2022-08-13 11:21:59 +08:00
|
|
|
// }
|
|
|
|
// // Insert a picture scaling in the cell with location hyperlink.
|
2023-01-02 11:47:31 +08:00
|
|
|
// enable := true
|
Breaking change: changed the function signature for 11 exported functions
* Change
`func (f *File) NewConditionalStyle(style string) (int, error)`
to
`func (f *File) NewConditionalStyle(style *Style) (int, error)`
* Change
`func (f *File) NewStyle(style interface{}) (int, error)`
to
`func (f *File) NewStyle(style *Style) (int, error)`
* Change
`func (f *File) AddChart(sheet, cell, opts string, combo ...string) error`
to
`func (f *File) AddChart(sheet, cell string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddChartSheet(sheet, opts string, combo ...string) error`
to
`func (f *File) AddChartSheet(sheet string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddShape(sheet, cell, opts string) error`
to
`func (f *File) AddShape(sheet, cell string, opts *Shape) error`
* Change
`func (f *File) AddPictureFromBytes(sheet, cell, opts, name, extension string, file []byte) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *PictureOptions) error`
* Change
`func (f *File) AddTable(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AddTable(sheet, reference string, opts *TableOptions) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) AutoFilter(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AutoFilter(sheet, reference string, opts *AutoFilterOptions) error`
* Change
`func (f *File) SetPanes(sheet, panes string) error`
to
`func (f *File) SetPanes(sheet string, panes *Panes) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) SetConditionalFormat(sheet, reference, opts string) error`
to
`func (f *File) SetConditionalFormat(sheet, reference string, opts []ConditionalFormatOptions) error`
* Add exported types:
* AutoFilterListOptions
* AutoFilterOptions
* Chart
* ChartAxis
* ChartDimension
* ChartLegend
* ChartLine
* ChartMarker
* ChartPlotArea
* ChartSeries
* ChartTitle
* ConditionalFormatOptions
* PaneOptions
* Panes
* PictureOptions
* Shape
* ShapeColor
* ShapeLine
* ShapeParagraph
* TableOptions
* This added support for set sheet visible as very hidden
* Return error when missing required parameters for set defined name
* Update unit test and comments
2022-12-30 00:50:08 +08:00
|
|
|
// if err := f.AddPicture("Sheet1", "D2", "image.png",
|
2023-01-02 11:47:31 +08:00
|
|
|
// &excelize.GraphicOptions{
|
|
|
|
// ScaleX: 0.5,
|
|
|
|
// ScaleY: 0.5,
|
Breaking change: changed the function signature for 11 exported functions
* Change
`func (f *File) NewConditionalStyle(style string) (int, error)`
to
`func (f *File) NewConditionalStyle(style *Style) (int, error)`
* Change
`func (f *File) NewStyle(style interface{}) (int, error)`
to
`func (f *File) NewStyle(style *Style) (int, error)`
* Change
`func (f *File) AddChart(sheet, cell, opts string, combo ...string) error`
to
`func (f *File) AddChart(sheet, cell string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddChartSheet(sheet, opts string, combo ...string) error`
to
`func (f *File) AddChartSheet(sheet string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddShape(sheet, cell, opts string) error`
to
`func (f *File) AddShape(sheet, cell string, opts *Shape) error`
* Change
`func (f *File) AddPictureFromBytes(sheet, cell, opts, name, extension string, file []byte) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *PictureOptions) error`
* Change
`func (f *File) AddTable(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AddTable(sheet, reference string, opts *TableOptions) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) AutoFilter(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AutoFilter(sheet, reference string, opts *AutoFilterOptions) error`
* Change
`func (f *File) SetPanes(sheet, panes string) error`
to
`func (f *File) SetPanes(sheet string, panes *Panes) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) SetConditionalFormat(sheet, reference, opts string) error`
to
`func (f *File) SetConditionalFormat(sheet, reference string, opts []ConditionalFormatOptions) error`
* Add exported types:
* AutoFilterListOptions
* AutoFilterOptions
* Chart
* ChartAxis
* ChartDimension
* ChartLegend
* ChartLine
* ChartMarker
* ChartPlotArea
* ChartSeries
* ChartTitle
* ConditionalFormatOptions
* PaneOptions
* Panes
* PictureOptions
* Shape
* ShapeColor
* ShapeLine
* ShapeParagraph
* TableOptions
* This added support for set sheet visible as very hidden
* Return error when missing required parameters for set defined name
* Update unit test and comments
2022-12-30 00:50:08 +08:00
|
|
|
// Hyperlink: "#Sheet2!D8",
|
|
|
|
// HyperlinkType: "Location",
|
|
|
|
// },
|
|
|
|
// ); err != nil {
|
2022-08-13 11:21:59 +08:00
|
|
|
// fmt.Println(err)
|
2023-01-02 11:47:31 +08:00
|
|
|
// return
|
2022-08-13 11:21:59 +08:00
|
|
|
// }
|
|
|
|
// // Insert a picture offset in the cell with external hyperlink, printing and positioning support.
|
Breaking change: changed the function signature for 11 exported functions
* Change
`func (f *File) NewConditionalStyle(style string) (int, error)`
to
`func (f *File) NewConditionalStyle(style *Style) (int, error)`
* Change
`func (f *File) NewStyle(style interface{}) (int, error)`
to
`func (f *File) NewStyle(style *Style) (int, error)`
* Change
`func (f *File) AddChart(sheet, cell, opts string, combo ...string) error`
to
`func (f *File) AddChart(sheet, cell string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddChartSheet(sheet, opts string, combo ...string) error`
to
`func (f *File) AddChartSheet(sheet string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddShape(sheet, cell, opts string) error`
to
`func (f *File) AddShape(sheet, cell string, opts *Shape) error`
* Change
`func (f *File) AddPictureFromBytes(sheet, cell, opts, name, extension string, file []byte) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *PictureOptions) error`
* Change
`func (f *File) AddTable(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AddTable(sheet, reference string, opts *TableOptions) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) AutoFilter(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AutoFilter(sheet, reference string, opts *AutoFilterOptions) error`
* Change
`func (f *File) SetPanes(sheet, panes string) error`
to
`func (f *File) SetPanes(sheet string, panes *Panes) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) SetConditionalFormat(sheet, reference, opts string) error`
to
`func (f *File) SetConditionalFormat(sheet, reference string, opts []ConditionalFormatOptions) error`
* Add exported types:
* AutoFilterListOptions
* AutoFilterOptions
* Chart
* ChartAxis
* ChartDimension
* ChartLegend
* ChartLine
* ChartMarker
* ChartPlotArea
* ChartSeries
* ChartTitle
* ConditionalFormatOptions
* PaneOptions
* Panes
* PictureOptions
* Shape
* ShapeColor
* ShapeLine
* ShapeParagraph
* TableOptions
* This added support for set sheet visible as very hidden
* Return error when missing required parameters for set defined name
* Update unit test and comments
2022-12-30 00:50:08 +08:00
|
|
|
// if err := f.AddPicture("Sheet1", "H2", "image.gif",
|
2023-01-02 11:47:31 +08:00
|
|
|
// &excelize.GraphicOptions{
|
Breaking change: changed the function signature for 11 exported functions
* Change
`func (f *File) NewConditionalStyle(style string) (int, error)`
to
`func (f *File) NewConditionalStyle(style *Style) (int, error)`
* Change
`func (f *File) NewStyle(style interface{}) (int, error)`
to
`func (f *File) NewStyle(style *Style) (int, error)`
* Change
`func (f *File) AddChart(sheet, cell, opts string, combo ...string) error`
to
`func (f *File) AddChart(sheet, cell string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddChartSheet(sheet, opts string, combo ...string) error`
to
`func (f *File) AddChartSheet(sheet string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddShape(sheet, cell, opts string) error`
to
`func (f *File) AddShape(sheet, cell string, opts *Shape) error`
* Change
`func (f *File) AddPictureFromBytes(sheet, cell, opts, name, extension string, file []byte) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *PictureOptions) error`
* Change
`func (f *File) AddTable(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AddTable(sheet, reference string, opts *TableOptions) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) AutoFilter(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AutoFilter(sheet, reference string, opts *AutoFilterOptions) error`
* Change
`func (f *File) SetPanes(sheet, panes string) error`
to
`func (f *File) SetPanes(sheet string, panes *Panes) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) SetConditionalFormat(sheet, reference, opts string) error`
to
`func (f *File) SetConditionalFormat(sheet, reference string, opts []ConditionalFormatOptions) error`
* Add exported types:
* AutoFilterListOptions
* AutoFilterOptions
* Chart
* ChartAxis
* ChartDimension
* ChartLegend
* ChartLine
* ChartMarker
* ChartPlotArea
* ChartSeries
* ChartTitle
* ConditionalFormatOptions
* PaneOptions
* Panes
* PictureOptions
* Shape
* ShapeColor
* ShapeLine
* ShapeParagraph
* TableOptions
* This added support for set sheet visible as very hidden
* Return error when missing required parameters for set defined name
* Update unit test and comments
2022-12-30 00:50:08 +08:00
|
|
|
// PrintObject: &enable,
|
|
|
|
// LockAspectRatio: false,
|
|
|
|
// OffsetX: 15,
|
|
|
|
// OffsetY: 10,
|
|
|
|
// Hyperlink: "https://github.com/xuri/excelize",
|
|
|
|
// HyperlinkType: "External",
|
|
|
|
// Positioning: "oneCell",
|
|
|
|
// },
|
|
|
|
// ); err != nil {
|
2022-08-13 11:21:59 +08:00
|
|
|
// fmt.Println(err)
|
2023-01-02 11:47:31 +08:00
|
|
|
// return
|
2022-08-13 11:21:59 +08:00
|
|
|
// }
|
|
|
|
// if err := f.SaveAs("Book1.xlsx"); err != nil {
|
|
|
|
// fmt.Println(err)
|
|
|
|
// }
|
|
|
|
// }
|
2017-01-17 19:06:42 +08:00
|
|
|
//
|
2023-07-21 00:03:37 +08:00
|
|
|
// The optional parameter "AltText" is used to add alternative text to a graph
|
|
|
|
// object.
|
2021-08-26 00:48:18 +08:00
|
|
|
//
|
2023-07-21 00:03:37 +08:00
|
|
|
// The optional parameter "PrintObject" indicates whether the graph object is
|
|
|
|
// printed when the worksheet is printed, the default value of that is 'true'.
|
2021-08-26 00:48:18 +08:00
|
|
|
//
|
2023-07-21 00:03:37 +08:00
|
|
|
// The optional parameter "Locked" indicates whether lock the graph object.
|
|
|
|
// Locking an object has no effect unless the sheet is protected.
|
2021-08-26 00:48:18 +08:00
|
|
|
//
|
2023-07-21 00:03:37 +08:00
|
|
|
// The optional parameter "LockAspectRatio" indicates whether lock aspect ratio
|
|
|
|
// for the graph object, the default value of that is 'false'.
|
2021-08-26 00:48:18 +08:00
|
|
|
//
|
2023-07-21 00:03:37 +08:00
|
|
|
// The optional parameter "AutoFit" specifies if you make graph object size
|
|
|
|
// auto-fits the cell, the default value of that is 'false'.
|
2021-08-26 00:48:18 +08:00
|
|
|
//
|
2024-06-19 20:45:25 +08:00
|
|
|
// The optional parameter "AutoFitIgnoreAspect" specifies if fill the cell with
|
|
|
|
// the image and ignore its aspect ratio, the default value of that is 'false'.
|
|
|
|
// This option only works when the "AutoFit" is enabled.
|
|
|
|
//
|
2023-07-21 00:03:37 +08:00
|
|
|
// The optional parameter "OffsetX" specifies the horizontal offset of the graph
|
|
|
|
// object with the cell, the default value of that is 0.
|
2021-08-26 00:48:18 +08:00
|
|
|
//
|
2023-07-21 00:03:37 +08:00
|
|
|
// The optional parameter "OffsetY" specifies the vertical offset of the graph
|
|
|
|
// object with the cell, the default value of that is 0.
|
2021-08-26 00:48:18 +08:00
|
|
|
//
|
2023-07-21 00:03:37 +08:00
|
|
|
// The optional parameter "ScaleX" specifies the horizontal scale of graph
|
|
|
|
// object, the default value of that is 1.0 which presents 100%.
|
2021-08-26 00:48:18 +08:00
|
|
|
//
|
2023-07-21 00:03:37 +08:00
|
|
|
// The optional parameter "ScaleY" specifies the vertical scale of graph object,
|
2021-08-26 00:48:18 +08:00
|
|
|
// the default value of that is 1.0 which presents 100%.
|
|
|
|
//
|
2023-07-21 00:03:37 +08:00
|
|
|
// The optional parameter "Hyperlink" specifies the hyperlink of the graph
|
|
|
|
// object.
|
2021-08-26 00:48:18 +08:00
|
|
|
//
|
2023-07-21 00:03:37 +08:00
|
|
|
// The optional parameter "HyperlinkType" defines two types of
|
|
|
|
// hyperlink "External" for website or "Location" for moving to one of the
|
|
|
|
// cells in this workbook. When the "HyperlinkType" is "Location",
|
|
|
|
// coordinates need to start with "#".
|
|
|
|
//
|
|
|
|
// The optional parameter "Positioning" defines 3 types of the position of a
|
|
|
|
// graph object in a spreadsheet: "oneCell" (Move but don't size with
|
|
|
|
// cells), "twoCell" (Move and size with cells), and "absolute" (Don't move or
|
|
|
|
// size with cells). If you don't set this parameter, the default positioning
|
|
|
|
// is to move and size with cells.
|
Breaking changes: changed the function signature for 2 exported functions
- Change
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *GraphicOptions) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell string, pic *Picture) error`
- Change
`func (f *File) GetPicture(sheet, cell string) (string, []byte, error)`
to
`func (f *File) GetPictures(sheet, cell string) ([]Picture, error)`
Co-authored-by: huangsk <645636204@qq.com>
2023-03-19 20:23:33 +08:00
|
|
|
func (f *File) AddPicture(sheet, cell, name string, opts *GraphicOptions) error {
|
2017-01-17 19:06:42 +08:00
|
|
|
var err error
|
|
|
|
// Check picture exists first.
|
Breaking changes: changed the function signature for 2 exported functions
- Change
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *GraphicOptions) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell string, pic *Picture) error`
- Change
`func (f *File) GetPicture(sheet, cell string) (string, []byte, error)`
to
`func (f *File) GetPictures(sheet, cell string) ([]Picture, error)`
Co-authored-by: huangsk <645636204@qq.com>
2023-03-19 20:23:33 +08:00
|
|
|
if _, err = os.Stat(name); os.IsNotExist(err) {
|
2017-01-17 19:06:42 +08:00
|
|
|
return err
|
|
|
|
}
|
2023-03-23 00:06:10 +08:00
|
|
|
ext, ok := supportedImageTypes[strings.ToLower(path.Ext(name))]
|
2017-01-17 19:06:42 +08:00
|
|
|
if !ok {
|
2021-05-10 00:09:24 +08:00
|
|
|
return ErrImgExt
|
2017-01-17 19:06:42 +08:00
|
|
|
}
|
Breaking changes: changed the function signature for 2 exported functions
- Change
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *GraphicOptions) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell string, pic *Picture) error`
- Change
`func (f *File) GetPicture(sheet, cell string) (string, []byte, error)`
to
`func (f *File) GetPictures(sheet, cell string) ([]Picture, error)`
Co-authored-by: huangsk <645636204@qq.com>
2023-03-19 20:23:33 +08:00
|
|
|
file, _ := os.ReadFile(filepath.Clean(name))
|
|
|
|
return f.AddPictureFromBytes(sheet, cell, &Picture{Extension: ext, File: file, Format: opts})
|
2018-09-14 00:24:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// AddPictureFromBytes provides the method to add picture in a sheet by given
|
|
|
|
// picture format set (such as offset, scale, aspect ratio setting and print
|
2022-12-01 10:44:28 +08:00
|
|
|
// settings), file base name, extension name and file bytes, supported image
|
2024-03-27 15:50:51 +08:00
|
|
|
// types: EMF, EMZ, GIF, JPEG, JPG, PNG, SVG, TIF, TIFF, WMF, and WMZ. Note that
|
|
|
|
// this function only supports adding pictures placed over the cells currently,
|
|
|
|
// and doesn't support adding pictures placed in cells or creating the Kingsoft
|
2024-04-01 08:49:21 +08:00
|
|
|
// WPS Office embedded image cells. For example:
|
2018-09-14 00:24:49 +08:00
|
|
|
//
|
2022-08-13 11:21:59 +08:00
|
|
|
// package main
|
2018-09-14 00:24:49 +08:00
|
|
|
//
|
2022-08-13 11:21:59 +08:00
|
|
|
// import (
|
|
|
|
// "fmt"
|
|
|
|
// _ "image/jpeg"
|
2022-10-13 00:02:53 +08:00
|
|
|
// "os"
|
2018-09-14 00:24:49 +08:00
|
|
|
//
|
2022-08-13 11:21:59 +08:00
|
|
|
// "github.com/xuri/excelize/v2"
|
|
|
|
// )
|
2018-09-14 00:24:49 +08:00
|
|
|
//
|
2022-08-13 11:21:59 +08:00
|
|
|
// func main() {
|
|
|
|
// f := excelize.NewFile()
|
2023-01-02 11:47:31 +08:00
|
|
|
// defer func() {
|
|
|
|
// if err := f.Close(); err != nil {
|
|
|
|
// fmt.Println(err)
|
|
|
|
// }
|
|
|
|
// }()
|
2022-10-13 00:02:53 +08:00
|
|
|
// file, err := os.ReadFile("image.jpg")
|
2022-08-13 11:21:59 +08:00
|
|
|
// if err != nil {
|
|
|
|
// fmt.Println(err)
|
2023-01-02 11:47:31 +08:00
|
|
|
// return
|
2022-08-13 11:21:59 +08:00
|
|
|
// }
|
Breaking changes: changed the function signature for 2 exported functions
- Change
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *GraphicOptions) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell string, pic *Picture) error`
- Change
`func (f *File) GetPicture(sheet, cell string) (string, []byte, error)`
to
`func (f *File) GetPictures(sheet, cell string) ([]Picture, error)`
Co-authored-by: huangsk <645636204@qq.com>
2023-03-19 20:23:33 +08:00
|
|
|
// if err := f.AddPictureFromBytes("Sheet1", "A2", &excelize.Picture{
|
|
|
|
// Extension: ".jpg",
|
|
|
|
// File: file,
|
|
|
|
// Format: &excelize.GraphicOptions{AltText: "Excel Logo"},
|
|
|
|
// }); err != nil {
|
2022-08-13 11:21:59 +08:00
|
|
|
// fmt.Println(err)
|
2023-01-02 11:47:31 +08:00
|
|
|
// return
|
2022-08-13 11:21:59 +08:00
|
|
|
// }
|
|
|
|
// if err := f.SaveAs("Book1.xlsx"); err != nil {
|
|
|
|
// fmt.Println(err)
|
|
|
|
// }
|
|
|
|
// }
|
Breaking changes: changed the function signature for 2 exported functions
- Change
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *GraphicOptions) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell string, pic *Picture) error`
- Change
`func (f *File) GetPicture(sheet, cell string) (string, []byte, error)`
to
`func (f *File) GetPictures(sheet, cell string) ([]Picture, error)`
Co-authored-by: huangsk <645636204@qq.com>
2023-03-19 20:23:33 +08:00
|
|
|
func (f *File) AddPictureFromBytes(sheet, cell string, pic *Picture) error {
|
2018-09-14 00:24:49 +08:00
|
|
|
var drawingHyperlinkRID int
|
|
|
|
var hyperlinkType string
|
2023-03-23 00:06:10 +08:00
|
|
|
ext, ok := supportedImageTypes[strings.ToLower(pic.Extension)]
|
2018-09-14 00:24:49 +08:00
|
|
|
if !ok {
|
2021-05-10 00:09:24 +08:00
|
|
|
return ErrImgExt
|
2018-09-14 00:24:49 +08:00
|
|
|
}
|
2024-03-27 15:50:51 +08:00
|
|
|
if pic.InsertType != PictureInsertTypePlaceOverCells {
|
|
|
|
return ErrParameterInvalid
|
|
|
|
}
|
Breaking changes: changed the function signature for 2 exported functions
- Change
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *GraphicOptions) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell string, pic *Picture) error`
- Change
`func (f *File) GetPicture(sheet, cell string) (string, []byte, error)`
to
`func (f *File) GetPictures(sheet, cell string) ([]Picture, error)`
Co-authored-by: huangsk <645636204@qq.com>
2023-03-19 20:23:33 +08:00
|
|
|
options := parseGraphicOptions(pic.Format)
|
|
|
|
img, _, err := image.DecodeConfig(bytes.NewReader(pic.File))
|
2018-05-27 11:25:55 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-07-28 00:24:08 +08:00
|
|
|
// Read sheet data
|
2023-04-25 08:44:41 +08:00
|
|
|
f.mu.Lock()
|
2020-11-10 23:48:09 +08:00
|
|
|
ws, err := f.workSheetReader(sheet)
|
2019-04-15 11:22:57 +08:00
|
|
|
if err != nil {
|
2023-04-25 08:44:41 +08:00
|
|
|
f.mu.Unlock()
|
2019-04-15 11:22:57 +08:00
|
|
|
return err
|
|
|
|
}
|
2023-04-25 08:44:41 +08:00
|
|
|
f.mu.Unlock()
|
2023-04-24 00:02:13 +08:00
|
|
|
ws.mu.Lock()
|
2017-01-17 19:06:42 +08:00
|
|
|
// Add first picture for given sheet, create xl/drawings/ and xl/drawings/_rels/ folder.
|
|
|
|
drawingID := f.countDrawings() + 1
|
|
|
|
drawingXML := "xl/drawings/drawing" + strconv.Itoa(drawingID) + ".xml"
|
2020-11-10 23:48:09 +08:00
|
|
|
drawingID, drawingXML = f.prepareDrawing(ws, drawingID, sheet, drawingXML)
|
2019-09-16 01:17:35 +08:00
|
|
|
drawingRels := "xl/drawings/_rels/drawing" + strconv.Itoa(drawingID) + ".xml.rels"
|
Breaking changes: changed the function signature for 2 exported functions
- Change
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *GraphicOptions) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell string, pic *Picture) error`
- Change
`func (f *File) GetPicture(sheet, cell string) (string, []byte, error)`
to
`func (f *File) GetPictures(sheet, cell string) ([]Picture, error)`
Co-authored-by: huangsk <645636204@qq.com>
2023-03-19 20:23:33 +08:00
|
|
|
mediaStr := ".." + strings.TrimPrefix(f.addMedia(pic.File, ext), "xl")
|
2023-10-10 00:04:10 +08:00
|
|
|
var drawingRID int
|
|
|
|
if rels, _ := f.relsReader(drawingRels); rels != nil {
|
|
|
|
for _, rel := range rels.Relationships {
|
|
|
|
if rel.Type == SourceRelationshipImage && rel.Target == mediaStr {
|
|
|
|
drawingRID, _ = strconv.Atoi(strings.TrimPrefix(rel.ID, "rId"))
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if drawingRID == 0 {
|
|
|
|
drawingRID = f.addRels(drawingRels, SourceRelationshipImage, mediaStr, hyperlinkType)
|
|
|
|
}
|
2018-02-03 15:02:37 +08:00
|
|
|
// Add picture with hyperlink.
|
This closes #1358, made a refactor with breaking changes, see details:
This made a refactor with breaking changes:
Motivation and Context
When I decided to add set horizontal centered support for this library to resolve #1358, the reason I made this huge breaking change was:
- There are too many exported types for set sheet view, properties, and format properties, although a function using the functional options pattern can be optimized by returning an anonymous function, these types or property set or get function has no binding categorization, so I change these functions like `SetAppProps` to accept a pointer of options structure.
- Users can not easily find out which properties should be in the `SetSheetPrOptions` or `SetSheetFormatPr` categories
- Nested properties cannot proceed modify easily
Introduce 5 new export data types:
`HeaderFooterOptions`, `PageLayoutMarginsOptions`, `PageLayoutOptions`, `SheetPropsOptions`, and `ViewOptions`
Rename 4 exported data types:
- Rename `PivotTableOption` to `PivotTableOptions`
- Rename `FormatHeaderFooter` to `HeaderFooterOptions`
- Rename `FormatSheetProtection` to `SheetProtectionOptions`
- Rename `SparklineOption` to `SparklineOptions`
Remove 54 exported types:
`AutoPageBreaks`, `BaseColWidth`, `BlackAndWhite`, `CodeName`, `CustomHeight`, `Date1904`, `DefaultColWidth`, `DefaultGridColor`, `DefaultRowHeight`, `EnableFormatConditionsCalculation`, `FilterPrivacy`, `FirstPageNumber`, `FitToHeight`, `FitToPage`, `FitToWidth`, `OutlineSummaryBelow`, `PageLayoutOption`, `PageLayoutOptionPtr`, `PageLayoutOrientation`, `PageLayoutPaperSize`, `PageLayoutScale`, `PageMarginBottom`, `PageMarginFooter`, `PageMarginHeader`, `PageMarginLeft`, `PageMarginRight`, `PageMarginsOptions`, `PageMarginsOptionsPtr`, `PageMarginTop`, `Published`, `RightToLeft`, `SheetFormatPrOptions`, `SheetFormatPrOptionsPtr`, `SheetPrOption`, `SheetPrOptionPtr`, `SheetViewOption`, `SheetViewOptionPtr`, `ShowFormulas`, `ShowGridLines`, `ShowRowColHeaders`, `ShowRuler`, `ShowZeros`, `TabColorIndexed`, `TabColorRGB`, `TabColorTheme`, `TabColorTint`, `ThickBottom`, `ThickTop`, `TopLeftCell`, `View`, `WorkbookPrOption`, `WorkbookPrOptionPtr`, `ZeroHeight` and `ZoomScale`
Remove 2 exported constants:
`OrientationPortrait` and `OrientationLandscape`
Change 8 functions:
- Change the `func (f *File) SetPageLayout(sheet string, opts ...PageLayoutOption) error` to `func (f *File) SetPageLayout(sheet string, opts *PageLayoutOptions) error`
- Change the `func (f *File) GetPageLayout(sheet string, opts ...PageLayoutOptionPtr) error` to `func (f *File) GetPageLayout(sheet string) (PageLayoutOptions, error)`
- Change the `func (f *File) SetPageMargins(sheet string, opts ...PageMarginsOptions) error` to `func (f *File) SetPageMargins(sheet string, opts *PageLayoutMarginsOptions) error`
- Change the `func (f *File) GetPageMargins(sheet string, opts ...PageMarginsOptionsPtr) error` to `func (f *File) GetPageMargins(sheet string) (PageLayoutMarginsOptions, error)`
- Change the `func (f *File) SetSheetViewOptions(sheet string, viewIndex int, opts ...SheetViewOption) error` to `func (f *File) SetSheetView(sheet string, viewIndex int, opts *ViewOptions) error`
- Change the `func (f *File) GetSheetViewOptions(sheet string, viewIndex int, opts ...SheetViewOptionPtr) error` to `func (f *File) GetSheetView(sheet string, viewIndex int) (ViewOptions, error)`
- Change the `func (f *File) SetWorkbookPrOptions(opts ...WorkbookPrOption) error` to `func (f *File) SetWorkbookProps(opts *WorkbookPropsOptions) error`
- Change the `func (f *File) GetWorkbookPrOptions(opts ...WorkbookPrOptionPtr) error` to `func (f *File) GetWorkbookProps() (WorkbookPropsOptions, error)`
Introduce new function to instead of existing functions:
- New function `func (f *File) SetSheetProps(sheet string, opts *SheetPropsOptions) error` instead of `func (f *File) SetSheetPrOptions(sheet string, opts ...SheetPrOption) error` and `func (f *File) SetSheetFormatPr(sheet string, opts ...SheetFormatPrOption
2022-09-29 22:00:21 +08:00
|
|
|
if options.Hyperlink != "" && options.HyperlinkType != "" {
|
|
|
|
if options.HyperlinkType == "External" {
|
|
|
|
hyperlinkType = options.HyperlinkType
|
2018-02-03 15:02:37 +08:00
|
|
|
}
|
This closes #1358, made a refactor with breaking changes, see details:
This made a refactor with breaking changes:
Motivation and Context
When I decided to add set horizontal centered support for this library to resolve #1358, the reason I made this huge breaking change was:
- There are too many exported types for set sheet view, properties, and format properties, although a function using the functional options pattern can be optimized by returning an anonymous function, these types or property set or get function has no binding categorization, so I change these functions like `SetAppProps` to accept a pointer of options structure.
- Users can not easily find out which properties should be in the `SetSheetPrOptions` or `SetSheetFormatPr` categories
- Nested properties cannot proceed modify easily
Introduce 5 new export data types:
`HeaderFooterOptions`, `PageLayoutMarginsOptions`, `PageLayoutOptions`, `SheetPropsOptions`, and `ViewOptions`
Rename 4 exported data types:
- Rename `PivotTableOption` to `PivotTableOptions`
- Rename `FormatHeaderFooter` to `HeaderFooterOptions`
- Rename `FormatSheetProtection` to `SheetProtectionOptions`
- Rename `SparklineOption` to `SparklineOptions`
Remove 54 exported types:
`AutoPageBreaks`, `BaseColWidth`, `BlackAndWhite`, `CodeName`, `CustomHeight`, `Date1904`, `DefaultColWidth`, `DefaultGridColor`, `DefaultRowHeight`, `EnableFormatConditionsCalculation`, `FilterPrivacy`, `FirstPageNumber`, `FitToHeight`, `FitToPage`, `FitToWidth`, `OutlineSummaryBelow`, `PageLayoutOption`, `PageLayoutOptionPtr`, `PageLayoutOrientation`, `PageLayoutPaperSize`, `PageLayoutScale`, `PageMarginBottom`, `PageMarginFooter`, `PageMarginHeader`, `PageMarginLeft`, `PageMarginRight`, `PageMarginsOptions`, `PageMarginsOptionsPtr`, `PageMarginTop`, `Published`, `RightToLeft`, `SheetFormatPrOptions`, `SheetFormatPrOptionsPtr`, `SheetPrOption`, `SheetPrOptionPtr`, `SheetViewOption`, `SheetViewOptionPtr`, `ShowFormulas`, `ShowGridLines`, `ShowRowColHeaders`, `ShowRuler`, `ShowZeros`, `TabColorIndexed`, `TabColorRGB`, `TabColorTheme`, `TabColorTint`, `ThickBottom`, `ThickTop`, `TopLeftCell`, `View`, `WorkbookPrOption`, `WorkbookPrOptionPtr`, `ZeroHeight` and `ZoomScale`
Remove 2 exported constants:
`OrientationPortrait` and `OrientationLandscape`
Change 8 functions:
- Change the `func (f *File) SetPageLayout(sheet string, opts ...PageLayoutOption) error` to `func (f *File) SetPageLayout(sheet string, opts *PageLayoutOptions) error`
- Change the `func (f *File) GetPageLayout(sheet string, opts ...PageLayoutOptionPtr) error` to `func (f *File) GetPageLayout(sheet string) (PageLayoutOptions, error)`
- Change the `func (f *File) SetPageMargins(sheet string, opts ...PageMarginsOptions) error` to `func (f *File) SetPageMargins(sheet string, opts *PageLayoutMarginsOptions) error`
- Change the `func (f *File) GetPageMargins(sheet string, opts ...PageMarginsOptionsPtr) error` to `func (f *File) GetPageMargins(sheet string) (PageLayoutMarginsOptions, error)`
- Change the `func (f *File) SetSheetViewOptions(sheet string, viewIndex int, opts ...SheetViewOption) error` to `func (f *File) SetSheetView(sheet string, viewIndex int, opts *ViewOptions) error`
- Change the `func (f *File) GetSheetViewOptions(sheet string, viewIndex int, opts ...SheetViewOptionPtr) error` to `func (f *File) GetSheetView(sheet string, viewIndex int) (ViewOptions, error)`
- Change the `func (f *File) SetWorkbookPrOptions(opts ...WorkbookPrOption) error` to `func (f *File) SetWorkbookProps(opts *WorkbookPropsOptions) error`
- Change the `func (f *File) GetWorkbookPrOptions(opts ...WorkbookPrOptionPtr) error` to `func (f *File) GetWorkbookProps() (WorkbookPropsOptions, error)`
Introduce new function to instead of existing functions:
- New function `func (f *File) SetSheetProps(sheet string, opts *SheetPropsOptions) error` instead of `func (f *File) SetSheetPrOptions(sheet string, opts ...SheetPrOption) error` and `func (f *File) SetSheetFormatPr(sheet string, opts ...SheetFormatPrOption
2022-09-29 22:00:21 +08:00
|
|
|
drawingHyperlinkRID = f.addRels(drawingRels, SourceRelationshipHyperLink, options.Hyperlink, hyperlinkType)
|
2018-02-03 15:02:37 +08:00
|
|
|
}
|
2023-04-24 00:02:13 +08:00
|
|
|
ws.mu.Unlock()
|
Breaking changes: changed the function signature for 2 exported functions
- Change
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *GraphicOptions) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell string, pic *Picture) error`
- Change
`func (f *File) GetPicture(sheet, cell string) (string, []byte, error)`
to
`func (f *File) GetPictures(sheet, cell string) ([]Picture, error)`
Co-authored-by: huangsk <645636204@qq.com>
2023-03-19 20:23:33 +08:00
|
|
|
err = f.addDrawingPicture(sheet, drawingXML, cell, ext, drawingRID, drawingHyperlinkRID, img, options)
|
2019-03-23 20:08:06 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-11-13 00:40:04 +08:00
|
|
|
if err = f.addContentTypePart(drawingID, "drawings"); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-07-18 15:15:16 +08:00
|
|
|
f.addSheetNameSpace(sheet, SourceRelationship)
|
2017-01-17 19:06:42 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-08-06 10:21:24 +08:00
|
|
|
// addSheetLegacyDrawing provides a function to add legacy drawing element to
|
2017-09-13 22:00:33 +08:00
|
|
|
// xl/worksheets/sheet%d.xml by given worksheet name and relationship index.
|
2017-05-13 13:28:21 +08:00
|
|
|
func (f *File) addSheetLegacyDrawing(sheet string, rID int) {
|
2021-08-15 00:06:40 +08:00
|
|
|
ws, _ := f.workSheetReader(sheet)
|
|
|
|
ws.LegacyDrawing = &xlsxLegacyDrawing{
|
2017-05-13 13:28:21 +08:00
|
|
|
RID: "rId" + strconv.Itoa(rID),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-06 10:21:24 +08:00
|
|
|
// addSheetDrawing provides a function to add drawing element to
|
2017-09-13 22:00:33 +08:00
|
|
|
// xl/worksheets/sheet%d.xml by given worksheet name and relationship index.
|
2017-01-17 19:06:42 +08:00
|
|
|
func (f *File) addSheetDrawing(sheet string, rID int) {
|
2021-08-15 00:06:40 +08:00
|
|
|
ws, _ := f.workSheetReader(sheet)
|
|
|
|
ws.Drawing = &xlsxDrawing{
|
2017-01-17 19:06:42 +08:00
|
|
|
RID: "rId" + strconv.Itoa(rID),
|
|
|
|
}
|
2017-01-24 18:29:02 +08:00
|
|
|
}
|
|
|
|
|
2018-08-06 10:21:24 +08:00
|
|
|
// addSheetPicture provides a function to add picture element to
|
2017-09-13 22:00:33 +08:00
|
|
|
// xl/worksheets/sheet%d.xml by given worksheet name and relationship index.
|
2022-11-13 00:40:04 +08:00
|
|
|
func (f *File) addSheetPicture(sheet string, rID int) error {
|
|
|
|
ws, err := f.workSheetReader(sheet)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-08-15 00:06:40 +08:00
|
|
|
ws.Picture = &xlsxPicture{
|
2017-01-24 18:29:02 +08:00
|
|
|
RID: "rId" + strconv.Itoa(rID),
|
|
|
|
}
|
2022-11-13 00:40:04 +08:00
|
|
|
return err
|
2017-01-17 19:06:42 +08:00
|
|
|
}
|
|
|
|
|
2018-08-06 10:21:24 +08:00
|
|
|
// countDrawings provides a function to get drawing files count storage in the
|
2017-01-18 16:05:01 +08:00
|
|
|
// folder xl/drawings.
|
2022-11-29 00:03:49 +08:00
|
|
|
func (f *File) countDrawings() int {
|
2023-07-25 00:08:24 +08:00
|
|
|
drawings := map[string]struct{}{}
|
2021-07-05 00:03:56 +08:00
|
|
|
f.Pkg.Range(func(k, v interface{}) bool {
|
|
|
|
if strings.Contains(k.(string), "xl/drawings/drawing") {
|
2023-07-25 00:08:24 +08:00
|
|
|
drawings[k.(string)] = struct{}{}
|
2017-01-17 19:06:42 +08:00
|
|
|
}
|
2021-07-05 00:03:56 +08:00
|
|
|
return true
|
|
|
|
})
|
2021-07-04 12:13:06 +08:00
|
|
|
f.Drawings.Range(func(rel, value interface{}) bool {
|
|
|
|
if strings.Contains(rel.(string), "xl/drawings/drawing") {
|
2023-07-25 00:08:24 +08:00
|
|
|
drawings[rel.(string)] = struct{}{}
|
2019-03-22 14:26:43 +08:00
|
|
|
}
|
2021-07-04 12:13:06 +08:00
|
|
|
return true
|
|
|
|
})
|
2023-07-25 00:08:24 +08:00
|
|
|
return len(drawings)
|
2017-01-17 19:06:42 +08:00
|
|
|
}
|
|
|
|
|
2018-08-06 10:21:24 +08:00
|
|
|
// addDrawingPicture provides a function to add picture by given sheet,
|
2017-04-23 00:10:23 +08:00
|
|
|
// drawingXML, cell, file name, width, height relationship index and format
|
2017-05-24 14:17:35 +08:00
|
|
|
// sets.
|
Breaking changes: changed the function signature for 2 exported functions
- Change
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *GraphicOptions) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell string, pic *Picture) error`
- Change
`func (f *File) GetPicture(sheet, cell string) (string, []byte, error)`
to
`func (f *File) GetPictures(sheet, cell string) ([]Picture, error)`
Co-authored-by: huangsk <645636204@qq.com>
2023-03-19 20:23:33 +08:00
|
|
|
func (f *File) addDrawingPicture(sheet, drawingXML, cell, ext string, rID, hyperlinkRID int, img image.Config, opts *GraphicOptions) error {
|
2019-03-23 20:08:06 +08:00
|
|
|
col, row, err := CellNameToCoordinates(cell)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-07-21 00:03:37 +08:00
|
|
|
if opts.Positioning != "" && inStrSlice(supportedPositioning, opts.Positioning, true) == -1 {
|
|
|
|
return ErrParameterInvalid
|
|
|
|
}
|
2022-11-02 08:42:00 +08:00
|
|
|
width, height := img.Width, img.Height
|
Breaking change: changed the function signature for 11 exported functions
* Change
`func (f *File) NewConditionalStyle(style string) (int, error)`
to
`func (f *File) NewConditionalStyle(style *Style) (int, error)`
* Change
`func (f *File) NewStyle(style interface{}) (int, error)`
to
`func (f *File) NewStyle(style *Style) (int, error)`
* Change
`func (f *File) AddChart(sheet, cell, opts string, combo ...string) error`
to
`func (f *File) AddChart(sheet, cell string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddChartSheet(sheet, opts string, combo ...string) error`
to
`func (f *File) AddChartSheet(sheet string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddShape(sheet, cell, opts string) error`
to
`func (f *File) AddShape(sheet, cell string, opts *Shape) error`
* Change
`func (f *File) AddPictureFromBytes(sheet, cell, opts, name, extension string, file []byte) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *PictureOptions) error`
* Change
`func (f *File) AddTable(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AddTable(sheet, reference string, opts *TableOptions) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) AutoFilter(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AutoFilter(sheet, reference string, opts *AutoFilterOptions) error`
* Change
`func (f *File) SetPanes(sheet, panes string) error`
to
`func (f *File) SetPanes(sheet string, panes *Panes) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) SetConditionalFormat(sheet, reference, opts string) error`
to
`func (f *File) SetConditionalFormat(sheet, reference string, opts []ConditionalFormatOptions) error`
* Add exported types:
* AutoFilterListOptions
* AutoFilterOptions
* Chart
* ChartAxis
* ChartDimension
* ChartLegend
* ChartLine
* ChartMarker
* ChartPlotArea
* ChartSeries
* ChartTitle
* ConditionalFormatOptions
* PaneOptions
* Panes
* PictureOptions
* Shape
* ShapeColor
* ShapeLine
* ShapeParagraph
* TableOptions
* This added support for set sheet visible as very hidden
* Return error when missing required parameters for set defined name
* Update unit test and comments
2022-12-30 00:50:08 +08:00
|
|
|
if opts.AutoFit {
|
2023-06-14 22:49:40 +08:00
|
|
|
if width, height, col, row, err = f.drawingResize(sheet, cell, float64(width), float64(height), opts); err != nil {
|
2020-05-17 17:36:53 +08:00
|
|
|
return err
|
|
|
|
}
|
2020-08-18 16:30:32 +08:00
|
|
|
} else {
|
2023-01-02 11:47:31 +08:00
|
|
|
width = int(float64(width) * opts.ScaleX)
|
|
|
|
height = int(float64(height) * opts.ScaleY)
|
2020-05-17 17:36:53 +08:00
|
|
|
}
|
This closes #1358, made a refactor with breaking changes, see details:
This made a refactor with breaking changes:
Motivation and Context
When I decided to add set horizontal centered support for this library to resolve #1358, the reason I made this huge breaking change was:
- There are too many exported types for set sheet view, properties, and format properties, although a function using the functional options pattern can be optimized by returning an anonymous function, these types or property set or get function has no binding categorization, so I change these functions like `SetAppProps` to accept a pointer of options structure.
- Users can not easily find out which properties should be in the `SetSheetPrOptions` or `SetSheetFormatPr` categories
- Nested properties cannot proceed modify easily
Introduce 5 new export data types:
`HeaderFooterOptions`, `PageLayoutMarginsOptions`, `PageLayoutOptions`, `SheetPropsOptions`, and `ViewOptions`
Rename 4 exported data types:
- Rename `PivotTableOption` to `PivotTableOptions`
- Rename `FormatHeaderFooter` to `HeaderFooterOptions`
- Rename `FormatSheetProtection` to `SheetProtectionOptions`
- Rename `SparklineOption` to `SparklineOptions`
Remove 54 exported types:
`AutoPageBreaks`, `BaseColWidth`, `BlackAndWhite`, `CodeName`, `CustomHeight`, `Date1904`, `DefaultColWidth`, `DefaultGridColor`, `DefaultRowHeight`, `EnableFormatConditionsCalculation`, `FilterPrivacy`, `FirstPageNumber`, `FitToHeight`, `FitToPage`, `FitToWidth`, `OutlineSummaryBelow`, `PageLayoutOption`, `PageLayoutOptionPtr`, `PageLayoutOrientation`, `PageLayoutPaperSize`, `PageLayoutScale`, `PageMarginBottom`, `PageMarginFooter`, `PageMarginHeader`, `PageMarginLeft`, `PageMarginRight`, `PageMarginsOptions`, `PageMarginsOptionsPtr`, `PageMarginTop`, `Published`, `RightToLeft`, `SheetFormatPrOptions`, `SheetFormatPrOptionsPtr`, `SheetPrOption`, `SheetPrOptionPtr`, `SheetViewOption`, `SheetViewOptionPtr`, `ShowFormulas`, `ShowGridLines`, `ShowRowColHeaders`, `ShowRuler`, `ShowZeros`, `TabColorIndexed`, `TabColorRGB`, `TabColorTheme`, `TabColorTint`, `ThickBottom`, `ThickTop`, `TopLeftCell`, `View`, `WorkbookPrOption`, `WorkbookPrOptionPtr`, `ZeroHeight` and `ZoomScale`
Remove 2 exported constants:
`OrientationPortrait` and `OrientationLandscape`
Change 8 functions:
- Change the `func (f *File) SetPageLayout(sheet string, opts ...PageLayoutOption) error` to `func (f *File) SetPageLayout(sheet string, opts *PageLayoutOptions) error`
- Change the `func (f *File) GetPageLayout(sheet string, opts ...PageLayoutOptionPtr) error` to `func (f *File) GetPageLayout(sheet string) (PageLayoutOptions, error)`
- Change the `func (f *File) SetPageMargins(sheet string, opts ...PageMarginsOptions) error` to `func (f *File) SetPageMargins(sheet string, opts *PageLayoutMarginsOptions) error`
- Change the `func (f *File) GetPageMargins(sheet string, opts ...PageMarginsOptionsPtr) error` to `func (f *File) GetPageMargins(sheet string) (PageLayoutMarginsOptions, error)`
- Change the `func (f *File) SetSheetViewOptions(sheet string, viewIndex int, opts ...SheetViewOption) error` to `func (f *File) SetSheetView(sheet string, viewIndex int, opts *ViewOptions) error`
- Change the `func (f *File) GetSheetViewOptions(sheet string, viewIndex int, opts ...SheetViewOptionPtr) error` to `func (f *File) GetSheetView(sheet string, viewIndex int) (ViewOptions, error)`
- Change the `func (f *File) SetWorkbookPrOptions(opts ...WorkbookPrOption) error` to `func (f *File) SetWorkbookProps(opts *WorkbookPropsOptions) error`
- Change the `func (f *File) GetWorkbookPrOptions(opts ...WorkbookPrOptionPtr) error` to `func (f *File) GetWorkbookProps() (WorkbookPropsOptions, error)`
Introduce new function to instead of existing functions:
- New function `func (f *File) SetSheetProps(sheet string, opts *SheetPropsOptions) error` instead of `func (f *File) SetSheetPrOptions(sheet string, opts ...SheetPrOption) error` and `func (f *File) SetSheetFormatPr(sheet string, opts ...SheetFormatPrOption
2022-09-29 22:00:21 +08:00
|
|
|
colStart, rowStart, colEnd, rowEnd, x2, y2 := f.positionObjectPixels(sheet, col, row, opts.OffsetX, opts.OffsetY, width, height)
|
2022-11-12 00:02:11 +08:00
|
|
|
content, cNvPrID, err := f.drawingParser(drawingXML)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-04-30 20:03:43 +08:00
|
|
|
twoCellAnchor := xdrCellAnchor{}
|
This closes #1358, made a refactor with breaking changes, see details:
This made a refactor with breaking changes:
Motivation and Context
When I decided to add set horizontal centered support for this library to resolve #1358, the reason I made this huge breaking change was:
- There are too many exported types for set sheet view, properties, and format properties, although a function using the functional options pattern can be optimized by returning an anonymous function, these types or property set or get function has no binding categorization, so I change these functions like `SetAppProps` to accept a pointer of options structure.
- Users can not easily find out which properties should be in the `SetSheetPrOptions` or `SetSheetFormatPr` categories
- Nested properties cannot proceed modify easily
Introduce 5 new export data types:
`HeaderFooterOptions`, `PageLayoutMarginsOptions`, `PageLayoutOptions`, `SheetPropsOptions`, and `ViewOptions`
Rename 4 exported data types:
- Rename `PivotTableOption` to `PivotTableOptions`
- Rename `FormatHeaderFooter` to `HeaderFooterOptions`
- Rename `FormatSheetProtection` to `SheetProtectionOptions`
- Rename `SparklineOption` to `SparklineOptions`
Remove 54 exported types:
`AutoPageBreaks`, `BaseColWidth`, `BlackAndWhite`, `CodeName`, `CustomHeight`, `Date1904`, `DefaultColWidth`, `DefaultGridColor`, `DefaultRowHeight`, `EnableFormatConditionsCalculation`, `FilterPrivacy`, `FirstPageNumber`, `FitToHeight`, `FitToPage`, `FitToWidth`, `OutlineSummaryBelow`, `PageLayoutOption`, `PageLayoutOptionPtr`, `PageLayoutOrientation`, `PageLayoutPaperSize`, `PageLayoutScale`, `PageMarginBottom`, `PageMarginFooter`, `PageMarginHeader`, `PageMarginLeft`, `PageMarginRight`, `PageMarginsOptions`, `PageMarginsOptionsPtr`, `PageMarginTop`, `Published`, `RightToLeft`, `SheetFormatPrOptions`, `SheetFormatPrOptionsPtr`, `SheetPrOption`, `SheetPrOptionPtr`, `SheetViewOption`, `SheetViewOptionPtr`, `ShowFormulas`, `ShowGridLines`, `ShowRowColHeaders`, `ShowRuler`, `ShowZeros`, `TabColorIndexed`, `TabColorRGB`, `TabColorTheme`, `TabColorTint`, `ThickBottom`, `ThickTop`, `TopLeftCell`, `View`, `WorkbookPrOption`, `WorkbookPrOptionPtr`, `ZeroHeight` and `ZoomScale`
Remove 2 exported constants:
`OrientationPortrait` and `OrientationLandscape`
Change 8 functions:
- Change the `func (f *File) SetPageLayout(sheet string, opts ...PageLayoutOption) error` to `func (f *File) SetPageLayout(sheet string, opts *PageLayoutOptions) error`
- Change the `func (f *File) GetPageLayout(sheet string, opts ...PageLayoutOptionPtr) error` to `func (f *File) GetPageLayout(sheet string) (PageLayoutOptions, error)`
- Change the `func (f *File) SetPageMargins(sheet string, opts ...PageMarginsOptions) error` to `func (f *File) SetPageMargins(sheet string, opts *PageLayoutMarginsOptions) error`
- Change the `func (f *File) GetPageMargins(sheet string, opts ...PageMarginsOptionsPtr) error` to `func (f *File) GetPageMargins(sheet string) (PageLayoutMarginsOptions, error)`
- Change the `func (f *File) SetSheetViewOptions(sheet string, viewIndex int, opts ...SheetViewOption) error` to `func (f *File) SetSheetView(sheet string, viewIndex int, opts *ViewOptions) error`
- Change the `func (f *File) GetSheetViewOptions(sheet string, viewIndex int, opts ...SheetViewOptionPtr) error` to `func (f *File) GetSheetView(sheet string, viewIndex int) (ViewOptions, error)`
- Change the `func (f *File) SetWorkbookPrOptions(opts ...WorkbookPrOption) error` to `func (f *File) SetWorkbookProps(opts *WorkbookPropsOptions) error`
- Change the `func (f *File) GetWorkbookPrOptions(opts ...WorkbookPrOptionPtr) error` to `func (f *File) GetWorkbookProps() (WorkbookPropsOptions, error)`
Introduce new function to instead of existing functions:
- New function `func (f *File) SetSheetProps(sheet string, opts *SheetPropsOptions) error` instead of `func (f *File) SetSheetPrOptions(sheet string, opts ...SheetPrOption) error` and `func (f *File) SetSheetFormatPr(sheet string, opts ...SheetFormatPrOption
2022-09-29 22:00:21 +08:00
|
|
|
twoCellAnchor.EditAs = opts.Positioning
|
2017-01-17 19:06:42 +08:00
|
|
|
from := xlsxFrom{}
|
2017-01-22 16:16:03 +08:00
|
|
|
from.Col = colStart
|
This closes #1358, made a refactor with breaking changes, see details:
This made a refactor with breaking changes:
Motivation and Context
When I decided to add set horizontal centered support for this library to resolve #1358, the reason I made this huge breaking change was:
- There are too many exported types for set sheet view, properties, and format properties, although a function using the functional options pattern can be optimized by returning an anonymous function, these types or property set or get function has no binding categorization, so I change these functions like `SetAppProps` to accept a pointer of options structure.
- Users can not easily find out which properties should be in the `SetSheetPrOptions` or `SetSheetFormatPr` categories
- Nested properties cannot proceed modify easily
Introduce 5 new export data types:
`HeaderFooterOptions`, `PageLayoutMarginsOptions`, `PageLayoutOptions`, `SheetPropsOptions`, and `ViewOptions`
Rename 4 exported data types:
- Rename `PivotTableOption` to `PivotTableOptions`
- Rename `FormatHeaderFooter` to `HeaderFooterOptions`
- Rename `FormatSheetProtection` to `SheetProtectionOptions`
- Rename `SparklineOption` to `SparklineOptions`
Remove 54 exported types:
`AutoPageBreaks`, `BaseColWidth`, `BlackAndWhite`, `CodeName`, `CustomHeight`, `Date1904`, `DefaultColWidth`, `DefaultGridColor`, `DefaultRowHeight`, `EnableFormatConditionsCalculation`, `FilterPrivacy`, `FirstPageNumber`, `FitToHeight`, `FitToPage`, `FitToWidth`, `OutlineSummaryBelow`, `PageLayoutOption`, `PageLayoutOptionPtr`, `PageLayoutOrientation`, `PageLayoutPaperSize`, `PageLayoutScale`, `PageMarginBottom`, `PageMarginFooter`, `PageMarginHeader`, `PageMarginLeft`, `PageMarginRight`, `PageMarginsOptions`, `PageMarginsOptionsPtr`, `PageMarginTop`, `Published`, `RightToLeft`, `SheetFormatPrOptions`, `SheetFormatPrOptionsPtr`, `SheetPrOption`, `SheetPrOptionPtr`, `SheetViewOption`, `SheetViewOptionPtr`, `ShowFormulas`, `ShowGridLines`, `ShowRowColHeaders`, `ShowRuler`, `ShowZeros`, `TabColorIndexed`, `TabColorRGB`, `TabColorTheme`, `TabColorTint`, `ThickBottom`, `ThickTop`, `TopLeftCell`, `View`, `WorkbookPrOption`, `WorkbookPrOptionPtr`, `ZeroHeight` and `ZoomScale`
Remove 2 exported constants:
`OrientationPortrait` and `OrientationLandscape`
Change 8 functions:
- Change the `func (f *File) SetPageLayout(sheet string, opts ...PageLayoutOption) error` to `func (f *File) SetPageLayout(sheet string, opts *PageLayoutOptions) error`
- Change the `func (f *File) GetPageLayout(sheet string, opts ...PageLayoutOptionPtr) error` to `func (f *File) GetPageLayout(sheet string) (PageLayoutOptions, error)`
- Change the `func (f *File) SetPageMargins(sheet string, opts ...PageMarginsOptions) error` to `func (f *File) SetPageMargins(sheet string, opts *PageLayoutMarginsOptions) error`
- Change the `func (f *File) GetPageMargins(sheet string, opts ...PageMarginsOptionsPtr) error` to `func (f *File) GetPageMargins(sheet string) (PageLayoutMarginsOptions, error)`
- Change the `func (f *File) SetSheetViewOptions(sheet string, viewIndex int, opts ...SheetViewOption) error` to `func (f *File) SetSheetView(sheet string, viewIndex int, opts *ViewOptions) error`
- Change the `func (f *File) GetSheetViewOptions(sheet string, viewIndex int, opts ...SheetViewOptionPtr) error` to `func (f *File) GetSheetView(sheet string, viewIndex int) (ViewOptions, error)`
- Change the `func (f *File) SetWorkbookPrOptions(opts ...WorkbookPrOption) error` to `func (f *File) SetWorkbookProps(opts *WorkbookPropsOptions) error`
- Change the `func (f *File) GetWorkbookPrOptions(opts ...WorkbookPrOptionPtr) error` to `func (f *File) GetWorkbookProps() (WorkbookPropsOptions, error)`
Introduce new function to instead of existing functions:
- New function `func (f *File) SetSheetProps(sheet string, opts *SheetPropsOptions) error` instead of `func (f *File) SetSheetPrOptions(sheet string, opts ...SheetPrOption) error` and `func (f *File) SetSheetFormatPr(sheet string, opts ...SheetFormatPrOption
2022-09-29 22:00:21 +08:00
|
|
|
from.ColOff = opts.OffsetX * EMU
|
2017-01-22 16:16:03 +08:00
|
|
|
from.Row = rowStart
|
This closes #1358, made a refactor with breaking changes, see details:
This made a refactor with breaking changes:
Motivation and Context
When I decided to add set horizontal centered support for this library to resolve #1358, the reason I made this huge breaking change was:
- There are too many exported types for set sheet view, properties, and format properties, although a function using the functional options pattern can be optimized by returning an anonymous function, these types or property set or get function has no binding categorization, so I change these functions like `SetAppProps` to accept a pointer of options structure.
- Users can not easily find out which properties should be in the `SetSheetPrOptions` or `SetSheetFormatPr` categories
- Nested properties cannot proceed modify easily
Introduce 5 new export data types:
`HeaderFooterOptions`, `PageLayoutMarginsOptions`, `PageLayoutOptions`, `SheetPropsOptions`, and `ViewOptions`
Rename 4 exported data types:
- Rename `PivotTableOption` to `PivotTableOptions`
- Rename `FormatHeaderFooter` to `HeaderFooterOptions`
- Rename `FormatSheetProtection` to `SheetProtectionOptions`
- Rename `SparklineOption` to `SparklineOptions`
Remove 54 exported types:
`AutoPageBreaks`, `BaseColWidth`, `BlackAndWhite`, `CodeName`, `CustomHeight`, `Date1904`, `DefaultColWidth`, `DefaultGridColor`, `DefaultRowHeight`, `EnableFormatConditionsCalculation`, `FilterPrivacy`, `FirstPageNumber`, `FitToHeight`, `FitToPage`, `FitToWidth`, `OutlineSummaryBelow`, `PageLayoutOption`, `PageLayoutOptionPtr`, `PageLayoutOrientation`, `PageLayoutPaperSize`, `PageLayoutScale`, `PageMarginBottom`, `PageMarginFooter`, `PageMarginHeader`, `PageMarginLeft`, `PageMarginRight`, `PageMarginsOptions`, `PageMarginsOptionsPtr`, `PageMarginTop`, `Published`, `RightToLeft`, `SheetFormatPrOptions`, `SheetFormatPrOptionsPtr`, `SheetPrOption`, `SheetPrOptionPtr`, `SheetViewOption`, `SheetViewOptionPtr`, `ShowFormulas`, `ShowGridLines`, `ShowRowColHeaders`, `ShowRuler`, `ShowZeros`, `TabColorIndexed`, `TabColorRGB`, `TabColorTheme`, `TabColorTint`, `ThickBottom`, `ThickTop`, `TopLeftCell`, `View`, `WorkbookPrOption`, `WorkbookPrOptionPtr`, `ZeroHeight` and `ZoomScale`
Remove 2 exported constants:
`OrientationPortrait` and `OrientationLandscape`
Change 8 functions:
- Change the `func (f *File) SetPageLayout(sheet string, opts ...PageLayoutOption) error` to `func (f *File) SetPageLayout(sheet string, opts *PageLayoutOptions) error`
- Change the `func (f *File) GetPageLayout(sheet string, opts ...PageLayoutOptionPtr) error` to `func (f *File) GetPageLayout(sheet string) (PageLayoutOptions, error)`
- Change the `func (f *File) SetPageMargins(sheet string, opts ...PageMarginsOptions) error` to `func (f *File) SetPageMargins(sheet string, opts *PageLayoutMarginsOptions) error`
- Change the `func (f *File) GetPageMargins(sheet string, opts ...PageMarginsOptionsPtr) error` to `func (f *File) GetPageMargins(sheet string) (PageLayoutMarginsOptions, error)`
- Change the `func (f *File) SetSheetViewOptions(sheet string, viewIndex int, opts ...SheetViewOption) error` to `func (f *File) SetSheetView(sheet string, viewIndex int, opts *ViewOptions) error`
- Change the `func (f *File) GetSheetViewOptions(sheet string, viewIndex int, opts ...SheetViewOptionPtr) error` to `func (f *File) GetSheetView(sheet string, viewIndex int) (ViewOptions, error)`
- Change the `func (f *File) SetWorkbookPrOptions(opts ...WorkbookPrOption) error` to `func (f *File) SetWorkbookProps(opts *WorkbookPropsOptions) error`
- Change the `func (f *File) GetWorkbookPrOptions(opts ...WorkbookPrOptionPtr) error` to `func (f *File) GetWorkbookProps() (WorkbookPropsOptions, error)`
Introduce new function to instead of existing functions:
- New function `func (f *File) SetSheetProps(sheet string, opts *SheetPropsOptions) error` instead of `func (f *File) SetSheetPrOptions(sheet string, opts ...SheetPrOption) error` and `func (f *File) SetSheetFormatPr(sheet string, opts ...SheetFormatPrOption
2022-09-29 22:00:21 +08:00
|
|
|
from.RowOff = opts.OffsetY * EMU
|
2017-01-17 19:06:42 +08:00
|
|
|
to := xlsxTo{}
|
2017-01-22 16:16:03 +08:00
|
|
|
to.Col = colEnd
|
|
|
|
to.ColOff = x2 * EMU
|
|
|
|
to.Row = rowEnd
|
|
|
|
to.RowOff = y2 * EMU
|
2017-01-17 19:06:42 +08:00
|
|
|
twoCellAnchor.From = &from
|
|
|
|
twoCellAnchor.To = &to
|
|
|
|
pic := xlsxPic{}
|
Breaking change: changed the function signature for 11 exported functions
* Change
`func (f *File) NewConditionalStyle(style string) (int, error)`
to
`func (f *File) NewConditionalStyle(style *Style) (int, error)`
* Change
`func (f *File) NewStyle(style interface{}) (int, error)`
to
`func (f *File) NewStyle(style *Style) (int, error)`
* Change
`func (f *File) AddChart(sheet, cell, opts string, combo ...string) error`
to
`func (f *File) AddChart(sheet, cell string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddChartSheet(sheet, opts string, combo ...string) error`
to
`func (f *File) AddChartSheet(sheet string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddShape(sheet, cell, opts string) error`
to
`func (f *File) AddShape(sheet, cell string, opts *Shape) error`
* Change
`func (f *File) AddPictureFromBytes(sheet, cell, opts, name, extension string, file []byte) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *PictureOptions) error`
* Change
`func (f *File) AddTable(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AddTable(sheet, reference string, opts *TableOptions) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) AutoFilter(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AutoFilter(sheet, reference string, opts *AutoFilterOptions) error`
* Change
`func (f *File) SetPanes(sheet, panes string) error`
to
`func (f *File) SetPanes(sheet string, panes *Panes) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) SetConditionalFormat(sheet, reference, opts string) error`
to
`func (f *File) SetConditionalFormat(sheet, reference string, opts []ConditionalFormatOptions) error`
* Add exported types:
* AutoFilterListOptions
* AutoFilterOptions
* Chart
* ChartAxis
* ChartDimension
* ChartLegend
* ChartLine
* ChartMarker
* ChartPlotArea
* ChartSeries
* ChartTitle
* ConditionalFormatOptions
* PaneOptions
* Panes
* PictureOptions
* Shape
* ShapeColor
* ShapeLine
* ShapeParagraph
* TableOptions
* This added support for set sheet visible as very hidden
* Return error when missing required parameters for set defined name
* Update unit test and comments
2022-12-30 00:50:08 +08:00
|
|
|
pic.NvPicPr.CNvPicPr.PicLocks.NoChangeAspect = opts.LockAspectRatio
|
2019-09-26 22:28:14 +08:00
|
|
|
pic.NvPicPr.CNvPr.ID = cNvPrID
|
Breaking changes: changed the function signature for 2 exported functions
- Change
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *GraphicOptions) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell string, pic *Picture) error`
- Change
`func (f *File) GetPicture(sheet, cell string) (string, []byte, error)`
to
`func (f *File) GetPictures(sheet, cell string) ([]Picture, error)`
Co-authored-by: huangsk <645636204@qq.com>
2023-03-19 20:23:33 +08:00
|
|
|
pic.NvPicPr.CNvPr.Descr = opts.AltText
|
2017-01-17 19:06:42 +08:00
|
|
|
pic.NvPicPr.CNvPr.Name = "Picture " + strconv.Itoa(cNvPrID)
|
2018-02-03 15:02:37 +08:00
|
|
|
if hyperlinkRID != 0 {
|
|
|
|
pic.NvPicPr.CNvPr.HlinkClick = &xlsxHlinkClick{
|
2020-07-18 15:15:16 +08:00
|
|
|
R: SourceRelationship.Value,
|
2018-02-03 15:02:37 +08:00
|
|
|
RID: "rId" + strconv.Itoa(hyperlinkRID),
|
|
|
|
}
|
|
|
|
}
|
2020-07-18 15:15:16 +08:00
|
|
|
pic.BlipFill.Blip.R = SourceRelationship.Value
|
2017-01-17 19:06:42 +08:00
|
|
|
pic.BlipFill.Blip.Embed = "rId" + strconv.Itoa(rID)
|
2022-11-02 08:42:00 +08:00
|
|
|
if ext == ".svg" {
|
|
|
|
pic.BlipFill.Blip.ExtList = &xlsxEGOfficeArtExtensionList{
|
|
|
|
Ext: []xlsxCTOfficeArtExtension{
|
|
|
|
{
|
|
|
|
URI: ExtURISVG,
|
|
|
|
SVGBlip: xlsxCTSVGBlip{
|
|
|
|
XMLNSaAVG: NameSpaceDrawing2016SVG.Value,
|
|
|
|
Embed: pic.BlipFill.Blip.Embed,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2017-01-17 19:06:42 +08:00
|
|
|
pic.SpPr.PrstGeom.Prst = "rect"
|
|
|
|
|
|
|
|
twoCellAnchor.Pic = &pic
|
2017-04-30 20:03:43 +08:00
|
|
|
twoCellAnchor.ClientData = &xdrClientData{
|
Breaking change: changed the function signature for 11 exported functions
* Change
`func (f *File) NewConditionalStyle(style string) (int, error)`
to
`func (f *File) NewConditionalStyle(style *Style) (int, error)`
* Change
`func (f *File) NewStyle(style interface{}) (int, error)`
to
`func (f *File) NewStyle(style *Style) (int, error)`
* Change
`func (f *File) AddChart(sheet, cell, opts string, combo ...string) error`
to
`func (f *File) AddChart(sheet, cell string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddChartSheet(sheet, opts string, combo ...string) error`
to
`func (f *File) AddChartSheet(sheet string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddShape(sheet, cell, opts string) error`
to
`func (f *File) AddShape(sheet, cell string, opts *Shape) error`
* Change
`func (f *File) AddPictureFromBytes(sheet, cell, opts, name, extension string, file []byte) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *PictureOptions) error`
* Change
`func (f *File) AddTable(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AddTable(sheet, reference string, opts *TableOptions) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) AutoFilter(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AutoFilter(sheet, reference string, opts *AutoFilterOptions) error`
* Change
`func (f *File) SetPanes(sheet, panes string) error`
to
`func (f *File) SetPanes(sheet string, panes *Panes) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) SetConditionalFormat(sheet, reference, opts string) error`
to
`func (f *File) SetConditionalFormat(sheet, reference string, opts []ConditionalFormatOptions) error`
* Add exported types:
* AutoFilterListOptions
* AutoFilterOptions
* Chart
* ChartAxis
* ChartDimension
* ChartLegend
* ChartLine
* ChartMarker
* ChartPlotArea
* ChartSeries
* ChartTitle
* ConditionalFormatOptions
* PaneOptions
* Panes
* PictureOptions
* Shape
* ShapeColor
* ShapeLine
* ShapeParagraph
* TableOptions
* This added support for set sheet visible as very hidden
* Return error when missing required parameters for set defined name
* Update unit test and comments
2022-12-30 00:50:08 +08:00
|
|
|
FLocksWithSheet: *opts.Locked,
|
|
|
|
FPrintsWithSheet: *opts.PrintObject,
|
2017-01-17 19:06:42 +08:00
|
|
|
}
|
2023-04-24 00:02:13 +08:00
|
|
|
content.mu.Lock()
|
|
|
|
defer content.mu.Unlock()
|
2017-04-30 20:03:43 +08:00
|
|
|
content.TwoCellAnchor = append(content.TwoCellAnchor, &twoCellAnchor)
|
2021-07-04 12:13:06 +08:00
|
|
|
f.Drawings.Store(drawingXML, content)
|
2019-03-23 20:08:06 +08:00
|
|
|
return err
|
2017-01-17 19:06:42 +08:00
|
|
|
}
|
|
|
|
|
2018-08-06 10:21:24 +08:00
|
|
|
// countMedia provides a function to get media files count storage in the
|
|
|
|
// folder xl/media/image.
|
2017-01-17 19:06:42 +08:00
|
|
|
func (f *File) countMedia() int {
|
|
|
|
count := 0
|
2021-07-05 00:03:56 +08:00
|
|
|
f.Pkg.Range(func(k, v interface{}) bool {
|
|
|
|
if strings.Contains(k.(string), "xl/media/image") {
|
2017-01-17 19:06:42 +08:00
|
|
|
count++
|
|
|
|
}
|
2021-07-05 00:03:56 +08:00
|
|
|
return true
|
|
|
|
})
|
2017-01-17 19:06:42 +08:00
|
|
|
return count
|
|
|
|
}
|
|
|
|
|
2019-03-24 09:07:57 +08:00
|
|
|
// addMedia provides a function to add a picture into folder xl/media/image by
|
|
|
|
// given file and extension name. Duplicate images are only actually stored once
|
|
|
|
// and drawings that use it will reference the same image.
|
|
|
|
func (f *File) addMedia(file []byte, ext string) string {
|
2017-01-17 19:06:42 +08:00
|
|
|
count := f.countMedia()
|
2021-07-05 00:03:56 +08:00
|
|
|
var name string
|
|
|
|
f.Pkg.Range(func(k, existing interface{}) bool {
|
|
|
|
if !strings.HasPrefix(k.(string), "xl/media/image") {
|
|
|
|
return true
|
2019-03-24 09:07:57 +08:00
|
|
|
}
|
2021-07-05 00:03:56 +08:00
|
|
|
if bytes.Equal(file, existing.([]byte)) {
|
|
|
|
name = k.(string)
|
|
|
|
return false
|
2019-03-24 09:07:57 +08:00
|
|
|
}
|
2021-07-05 00:03:56 +08:00
|
|
|
return true
|
|
|
|
})
|
|
|
|
if name != "" {
|
|
|
|
return name
|
2019-03-24 09:07:57 +08:00
|
|
|
}
|
2017-01-17 19:06:42 +08:00
|
|
|
media := "xl/media/image" + strconv.Itoa(count+1) + ext
|
2021-07-05 00:03:56 +08:00
|
|
|
f.Pkg.Store(media, file)
|
2019-03-24 09:07:57 +08:00
|
|
|
return media
|
2017-01-17 19:06:42 +08:00
|
|
|
}
|
|
|
|
|
Breaking changes: changed the function signature for 2 exported functions
- Change
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *GraphicOptions) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell string, pic *Picture) error`
- Change
`func (f *File) GetPicture(sheet, cell string) (string, []byte, error)`
to
`func (f *File) GetPictures(sheet, cell string) ([]Picture, error)`
Co-authored-by: huangsk <645636204@qq.com>
2023-03-19 20:23:33 +08:00
|
|
|
// GetPictures provides a function to get picture meta info and raw content
|
2021-11-17 00:25:36 +08:00
|
|
|
// embed in spreadsheet by given worksheet and cell name. This function
|
Breaking changes: changed the function signature for 2 exported functions
- Change
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *GraphicOptions) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell string, pic *Picture) error`
- Change
`func (f *File) GetPicture(sheet, cell string) (string, []byte, error)`
to
`func (f *File) GetPictures(sheet, cell string) ([]Picture, error)`
Co-authored-by: huangsk <645636204@qq.com>
2023-03-19 20:23:33 +08:00
|
|
|
// returns the image contents as []byte data types. This function is
|
2024-04-02 08:47:57 +08:00
|
|
|
// concurrency safe. For example:
|
2017-03-28 21:18:06 +08:00
|
|
|
//
|
2022-08-13 11:21:59 +08:00
|
|
|
// f, err := excelize.OpenFile("Book1.xlsx")
|
|
|
|
// if err != nil {
|
|
|
|
// fmt.Println(err)
|
|
|
|
// return
|
|
|
|
// }
|
|
|
|
// defer func() {
|
|
|
|
// if err := f.Close(); err != nil {
|
|
|
|
// fmt.Println(err)
|
|
|
|
// }
|
|
|
|
// }()
|
Breaking changes: changed the function signature for 2 exported functions
- Change
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *GraphicOptions) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell string, pic *Picture) error`
- Change
`func (f *File) GetPicture(sheet, cell string) (string, []byte, error)`
to
`func (f *File) GetPictures(sheet, cell string) ([]Picture, error)`
Co-authored-by: huangsk <645636204@qq.com>
2023-03-19 20:23:33 +08:00
|
|
|
// pics, err := f.GetPictures("Sheet1", "A2")
|
2022-08-13 11:21:59 +08:00
|
|
|
// if err != nil {
|
Breaking changes: changed the function signature for 2 exported functions
- Change
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *GraphicOptions) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell string, pic *Picture) error`
- Change
`func (f *File) GetPicture(sheet, cell string) (string, []byte, error)`
to
`func (f *File) GetPictures(sheet, cell string) ([]Picture, error)`
Co-authored-by: huangsk <645636204@qq.com>
2023-03-19 20:23:33 +08:00
|
|
|
// fmt.Println(err)
|
2022-08-13 11:21:59 +08:00
|
|
|
// }
|
Breaking changes: changed the function signature for 2 exported functions
- Change
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *GraphicOptions) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell string, pic *Picture) error`
- Change
`func (f *File) GetPicture(sheet, cell string) (string, []byte, error)`
to
`func (f *File) GetPictures(sheet, cell string) ([]Picture, error)`
Co-authored-by: huangsk <645636204@qq.com>
2023-03-19 20:23:33 +08:00
|
|
|
// for idx, pic := range pics {
|
|
|
|
// name := fmt.Sprintf("image%d%s", idx+1, pic.Extension)
|
|
|
|
// if err := os.WriteFile(name, pic.File, 0644); err != nil {
|
|
|
|
// fmt.Println(err)
|
|
|
|
// }
|
2022-08-13 11:21:59 +08:00
|
|
|
// }
|
Breaking changes: changed the function signature for 2 exported functions
- Change
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *GraphicOptions) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell string, pic *Picture) error`
- Change
`func (f *File) GetPicture(sheet, cell string) (string, []byte, error)`
to
`func (f *File) GetPictures(sheet, cell string) ([]Picture, error)`
Co-authored-by: huangsk <645636204@qq.com>
2023-03-19 20:23:33 +08:00
|
|
|
func (f *File) GetPictures(sheet, cell string) ([]Picture, error) {
|
2019-03-23 20:08:06 +08:00
|
|
|
col, row, err := CellNameToCoordinates(cell)
|
|
|
|
if err != nil {
|
Breaking changes: changed the function signature for 2 exported functions
- Change
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *GraphicOptions) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell string, pic *Picture) error`
- Change
`func (f *File) GetPicture(sheet, cell string) (string, []byte, error)`
to
`func (f *File) GetPictures(sheet, cell string) ([]Picture, error)`
Co-authored-by: huangsk <645636204@qq.com>
2023-03-19 20:23:33 +08:00
|
|
|
return nil, err
|
2019-03-23 20:08:06 +08:00
|
|
|
}
|
2019-03-20 16:52:33 +08:00
|
|
|
col--
|
|
|
|
row--
|
2023-04-25 08:44:41 +08:00
|
|
|
f.mu.Lock()
|
2020-11-10 23:48:09 +08:00
|
|
|
ws, err := f.workSheetReader(sheet)
|
2019-04-15 11:22:57 +08:00
|
|
|
if err != nil {
|
2023-04-25 08:44:41 +08:00
|
|
|
f.mu.Unlock()
|
Breaking changes: changed the function signature for 2 exported functions
- Change
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *GraphicOptions) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell string, pic *Picture) error`
- Change
`func (f *File) GetPicture(sheet, cell string) (string, []byte, error)`
to
`func (f *File) GetPictures(sheet, cell string) ([]Picture, error)`
Co-authored-by: huangsk <645636204@qq.com>
2023-03-19 20:23:33 +08:00
|
|
|
return nil, err
|
2019-04-15 11:22:57 +08:00
|
|
|
}
|
2023-04-25 08:44:41 +08:00
|
|
|
f.mu.Unlock()
|
2020-11-10 23:48:09 +08:00
|
|
|
if ws.Drawing == nil {
|
2023-12-15 13:09:42 +08:00
|
|
|
return f.getCellImages(sheet, cell)
|
2017-03-28 21:18:06 +08:00
|
|
|
}
|
2020-11-10 23:48:09 +08:00
|
|
|
target := f.getSheetRelationshipsTargetByID(sheet, ws.Drawing.RID)
|
2023-11-06 09:51:19 +08:00
|
|
|
drawingXML := strings.TrimPrefix(strings.ReplaceAll(target, "..", "xl"), "/")
|
2022-06-12 00:19:12 +08:00
|
|
|
drawingRelationships := strings.ReplaceAll(
|
|
|
|
strings.ReplaceAll(target, "../drawings", "xl/drawings/_rels"), ".xml", ".xml.rels")
|
Huge refactorig for consistent col/row numbering (#356)
* Huge refactorig for consistent col/row numbering
Started from simply changing ToALphaString()/TitleToNumber() logic and related fixes.
But have to go deeper, do fixes, after do related fixes and again and again.
Major improvements:
1. Tests made stronger again (But still be weak).
2. "Empty" returns for incorrect input replaces with panic.
3. Check for correct col/row/cell naming & addressing by default.
4. Removed huge amount of duplicated code.
5. Removed ToALphaString(), TitleToNumber() and it helpers functions at all,
and replaced with SplitCellName(), JoinCellName(), ColumnNameToNumber(), ColumnNumberToName(), CellNameToCoordinates(), CoordinatesToCellName().
6. Minor fixes for internal variable naming for code readability (ex. col, row for input params, colIdx, rowIdx for slice indexes etc).
* Formatting fixes
2019-03-20 00:14:41 +08:00
|
|
|
|
2023-12-15 13:09:42 +08:00
|
|
|
imgs, err := f.getCellImages(sheet, cell)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
pics, err := f.getPicture(row, col, drawingXML, drawingRelationships)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return append(imgs, pics...), err
|
2019-06-20 00:00:40 +08:00
|
|
|
}
|
Huge refactorig for consistent col/row numbering (#356)
* Huge refactorig for consistent col/row numbering
Started from simply changing ToALphaString()/TitleToNumber() logic and related fixes.
But have to go deeper, do fixes, after do related fixes and again and again.
Major improvements:
1. Tests made stronger again (But still be weak).
2. "Empty" returns for incorrect input replaces with panic.
3. Check for correct col/row/cell naming & addressing by default.
4. Removed huge amount of duplicated code.
5. Removed ToALphaString(), TitleToNumber() and it helpers functions at all,
and replaced with SplitCellName(), JoinCellName(), ColumnNameToNumber(), ColumnNumberToName(), CellNameToCoordinates(), CoordinatesToCellName().
6. Minor fixes for internal variable naming for code readability (ex. col, row for input params, colIdx, rowIdx for slice indexes etc).
* Formatting fixes
2019-03-20 00:14:41 +08:00
|
|
|
|
2023-10-13 00:06:07 +08:00
|
|
|
// GetPictureCells returns all picture cell references in a worksheet by a
|
2024-04-02 08:47:57 +08:00
|
|
|
// specific worksheet name.
|
2023-10-13 00:06:07 +08:00
|
|
|
func (f *File) GetPictureCells(sheet string) ([]string, error) {
|
|
|
|
f.mu.Lock()
|
|
|
|
ws, err := f.workSheetReader(sheet)
|
|
|
|
if err != nil {
|
|
|
|
f.mu.Unlock()
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
f.mu.Unlock()
|
|
|
|
if ws.Drawing == nil {
|
2024-03-26 23:19:23 +08:00
|
|
|
return f.getImageCells(sheet)
|
2023-10-13 00:06:07 +08:00
|
|
|
}
|
|
|
|
target := f.getSheetRelationshipsTargetByID(sheet, ws.Drawing.RID)
|
2023-11-06 09:51:19 +08:00
|
|
|
drawingXML := strings.TrimPrefix(strings.ReplaceAll(target, "..", "xl"), "/")
|
2023-10-13 00:06:07 +08:00
|
|
|
drawingRelationships := strings.ReplaceAll(
|
|
|
|
strings.ReplaceAll(target, "../drawings", "xl/drawings/_rels"), ".xml", ".xml.rels")
|
2024-03-26 23:19:23 +08:00
|
|
|
embeddedImageCells, err := f.getImageCells(sheet)
|
2023-12-19 23:39:45 +08:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
imageCells, err := f.getPictureCells(drawingXML, drawingRelationships)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return append(embeddedImageCells, imageCells...), err
|
2023-10-13 00:06:07 +08:00
|
|
|
}
|
|
|
|
|
Breaking changes: changed the function signature for 2 exported functions
- Change
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *GraphicOptions) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell string, pic *Picture) error`
- Change
`func (f *File) GetPicture(sheet, cell string) (string, []byte, error)`
to
`func (f *File) GetPictures(sheet, cell string) ([]Picture, error)`
Co-authored-by: huangsk <645636204@qq.com>
2023-03-19 20:23:33 +08:00
|
|
|
// DeletePicture provides a function to delete all pictures in a cell by given
|
2023-10-09 00:14:56 +08:00
|
|
|
// worksheet name and cell reference.
|
This closes #1358, made a refactor with breaking changes, see details:
This made a refactor with breaking changes:
Motivation and Context
When I decided to add set horizontal centered support for this library to resolve #1358, the reason I made this huge breaking change was:
- There are too many exported types for set sheet view, properties, and format properties, although a function using the functional options pattern can be optimized by returning an anonymous function, these types or property set or get function has no binding categorization, so I change these functions like `SetAppProps` to accept a pointer of options structure.
- Users can not easily find out which properties should be in the `SetSheetPrOptions` or `SetSheetFormatPr` categories
- Nested properties cannot proceed modify easily
Introduce 5 new export data types:
`HeaderFooterOptions`, `PageLayoutMarginsOptions`, `PageLayoutOptions`, `SheetPropsOptions`, and `ViewOptions`
Rename 4 exported data types:
- Rename `PivotTableOption` to `PivotTableOptions`
- Rename `FormatHeaderFooter` to `HeaderFooterOptions`
- Rename `FormatSheetProtection` to `SheetProtectionOptions`
- Rename `SparklineOption` to `SparklineOptions`
Remove 54 exported types:
`AutoPageBreaks`, `BaseColWidth`, `BlackAndWhite`, `CodeName`, `CustomHeight`, `Date1904`, `DefaultColWidth`, `DefaultGridColor`, `DefaultRowHeight`, `EnableFormatConditionsCalculation`, `FilterPrivacy`, `FirstPageNumber`, `FitToHeight`, `FitToPage`, `FitToWidth`, `OutlineSummaryBelow`, `PageLayoutOption`, `PageLayoutOptionPtr`, `PageLayoutOrientation`, `PageLayoutPaperSize`, `PageLayoutScale`, `PageMarginBottom`, `PageMarginFooter`, `PageMarginHeader`, `PageMarginLeft`, `PageMarginRight`, `PageMarginsOptions`, `PageMarginsOptionsPtr`, `PageMarginTop`, `Published`, `RightToLeft`, `SheetFormatPrOptions`, `SheetFormatPrOptionsPtr`, `SheetPrOption`, `SheetPrOptionPtr`, `SheetViewOption`, `SheetViewOptionPtr`, `ShowFormulas`, `ShowGridLines`, `ShowRowColHeaders`, `ShowRuler`, `ShowZeros`, `TabColorIndexed`, `TabColorRGB`, `TabColorTheme`, `TabColorTint`, `ThickBottom`, `ThickTop`, `TopLeftCell`, `View`, `WorkbookPrOption`, `WorkbookPrOptionPtr`, `ZeroHeight` and `ZoomScale`
Remove 2 exported constants:
`OrientationPortrait` and `OrientationLandscape`
Change 8 functions:
- Change the `func (f *File) SetPageLayout(sheet string, opts ...PageLayoutOption) error` to `func (f *File) SetPageLayout(sheet string, opts *PageLayoutOptions) error`
- Change the `func (f *File) GetPageLayout(sheet string, opts ...PageLayoutOptionPtr) error` to `func (f *File) GetPageLayout(sheet string) (PageLayoutOptions, error)`
- Change the `func (f *File) SetPageMargins(sheet string, opts ...PageMarginsOptions) error` to `func (f *File) SetPageMargins(sheet string, opts *PageLayoutMarginsOptions) error`
- Change the `func (f *File) GetPageMargins(sheet string, opts ...PageMarginsOptionsPtr) error` to `func (f *File) GetPageMargins(sheet string) (PageLayoutMarginsOptions, error)`
- Change the `func (f *File) SetSheetViewOptions(sheet string, viewIndex int, opts ...SheetViewOption) error` to `func (f *File) SetSheetView(sheet string, viewIndex int, opts *ViewOptions) error`
- Change the `func (f *File) GetSheetViewOptions(sheet string, viewIndex int, opts ...SheetViewOptionPtr) error` to `func (f *File) GetSheetView(sheet string, viewIndex int) (ViewOptions, error)`
- Change the `func (f *File) SetWorkbookPrOptions(opts ...WorkbookPrOption) error` to `func (f *File) SetWorkbookProps(opts *WorkbookPropsOptions) error`
- Change the `func (f *File) GetWorkbookPrOptions(opts ...WorkbookPrOptionPtr) error` to `func (f *File) GetWorkbookProps() (WorkbookPropsOptions, error)`
Introduce new function to instead of existing functions:
- New function `func (f *File) SetSheetProps(sheet string, opts *SheetPropsOptions) error` instead of `func (f *File) SetSheetPrOptions(sheet string, opts ...SheetPrOption) error` and `func (f *File) SetSheetFormatPr(sheet string, opts ...SheetFormatPrOption
2022-09-29 22:00:21 +08:00
|
|
|
func (f *File) DeletePicture(sheet, cell string) error {
|
2020-01-22 01:08:18 +08:00
|
|
|
col, row, err := CellNameToCoordinates(cell)
|
|
|
|
if err != nil {
|
This closes #1358, made a refactor with breaking changes, see details:
This made a refactor with breaking changes:
Motivation and Context
When I decided to add set horizontal centered support for this library to resolve #1358, the reason I made this huge breaking change was:
- There are too many exported types for set sheet view, properties, and format properties, although a function using the functional options pattern can be optimized by returning an anonymous function, these types or property set or get function has no binding categorization, so I change these functions like `SetAppProps` to accept a pointer of options structure.
- Users can not easily find out which properties should be in the `SetSheetPrOptions` or `SetSheetFormatPr` categories
- Nested properties cannot proceed modify easily
Introduce 5 new export data types:
`HeaderFooterOptions`, `PageLayoutMarginsOptions`, `PageLayoutOptions`, `SheetPropsOptions`, and `ViewOptions`
Rename 4 exported data types:
- Rename `PivotTableOption` to `PivotTableOptions`
- Rename `FormatHeaderFooter` to `HeaderFooterOptions`
- Rename `FormatSheetProtection` to `SheetProtectionOptions`
- Rename `SparklineOption` to `SparklineOptions`
Remove 54 exported types:
`AutoPageBreaks`, `BaseColWidth`, `BlackAndWhite`, `CodeName`, `CustomHeight`, `Date1904`, `DefaultColWidth`, `DefaultGridColor`, `DefaultRowHeight`, `EnableFormatConditionsCalculation`, `FilterPrivacy`, `FirstPageNumber`, `FitToHeight`, `FitToPage`, `FitToWidth`, `OutlineSummaryBelow`, `PageLayoutOption`, `PageLayoutOptionPtr`, `PageLayoutOrientation`, `PageLayoutPaperSize`, `PageLayoutScale`, `PageMarginBottom`, `PageMarginFooter`, `PageMarginHeader`, `PageMarginLeft`, `PageMarginRight`, `PageMarginsOptions`, `PageMarginsOptionsPtr`, `PageMarginTop`, `Published`, `RightToLeft`, `SheetFormatPrOptions`, `SheetFormatPrOptionsPtr`, `SheetPrOption`, `SheetPrOptionPtr`, `SheetViewOption`, `SheetViewOptionPtr`, `ShowFormulas`, `ShowGridLines`, `ShowRowColHeaders`, `ShowRuler`, `ShowZeros`, `TabColorIndexed`, `TabColorRGB`, `TabColorTheme`, `TabColorTint`, `ThickBottom`, `ThickTop`, `TopLeftCell`, `View`, `WorkbookPrOption`, `WorkbookPrOptionPtr`, `ZeroHeight` and `ZoomScale`
Remove 2 exported constants:
`OrientationPortrait` and `OrientationLandscape`
Change 8 functions:
- Change the `func (f *File) SetPageLayout(sheet string, opts ...PageLayoutOption) error` to `func (f *File) SetPageLayout(sheet string, opts *PageLayoutOptions) error`
- Change the `func (f *File) GetPageLayout(sheet string, opts ...PageLayoutOptionPtr) error` to `func (f *File) GetPageLayout(sheet string) (PageLayoutOptions, error)`
- Change the `func (f *File) SetPageMargins(sheet string, opts ...PageMarginsOptions) error` to `func (f *File) SetPageMargins(sheet string, opts *PageLayoutMarginsOptions) error`
- Change the `func (f *File) GetPageMargins(sheet string, opts ...PageMarginsOptionsPtr) error` to `func (f *File) GetPageMargins(sheet string) (PageLayoutMarginsOptions, error)`
- Change the `func (f *File) SetSheetViewOptions(sheet string, viewIndex int, opts ...SheetViewOption) error` to `func (f *File) SetSheetView(sheet string, viewIndex int, opts *ViewOptions) error`
- Change the `func (f *File) GetSheetViewOptions(sheet string, viewIndex int, opts ...SheetViewOptionPtr) error` to `func (f *File) GetSheetView(sheet string, viewIndex int) (ViewOptions, error)`
- Change the `func (f *File) SetWorkbookPrOptions(opts ...WorkbookPrOption) error` to `func (f *File) SetWorkbookProps(opts *WorkbookPropsOptions) error`
- Change the `func (f *File) GetWorkbookPrOptions(opts ...WorkbookPrOptionPtr) error` to `func (f *File) GetWorkbookProps() (WorkbookPropsOptions, error)`
Introduce new function to instead of existing functions:
- New function `func (f *File) SetSheetProps(sheet string, opts *SheetPropsOptions) error` instead of `func (f *File) SetSheetPrOptions(sheet string, opts ...SheetPrOption) error` and `func (f *File) SetSheetFormatPr(sheet string, opts ...SheetFormatPrOption
2022-09-29 22:00:21 +08:00
|
|
|
return err
|
2020-01-22 01:08:18 +08:00
|
|
|
}
|
|
|
|
col--
|
|
|
|
row--
|
|
|
|
ws, err := f.workSheetReader(sheet)
|
|
|
|
if err != nil {
|
This closes #1358, made a refactor with breaking changes, see details:
This made a refactor with breaking changes:
Motivation and Context
When I decided to add set horizontal centered support for this library to resolve #1358, the reason I made this huge breaking change was:
- There are too many exported types for set sheet view, properties, and format properties, although a function using the functional options pattern can be optimized by returning an anonymous function, these types or property set or get function has no binding categorization, so I change these functions like `SetAppProps` to accept a pointer of options structure.
- Users can not easily find out which properties should be in the `SetSheetPrOptions` or `SetSheetFormatPr` categories
- Nested properties cannot proceed modify easily
Introduce 5 new export data types:
`HeaderFooterOptions`, `PageLayoutMarginsOptions`, `PageLayoutOptions`, `SheetPropsOptions`, and `ViewOptions`
Rename 4 exported data types:
- Rename `PivotTableOption` to `PivotTableOptions`
- Rename `FormatHeaderFooter` to `HeaderFooterOptions`
- Rename `FormatSheetProtection` to `SheetProtectionOptions`
- Rename `SparklineOption` to `SparklineOptions`
Remove 54 exported types:
`AutoPageBreaks`, `BaseColWidth`, `BlackAndWhite`, `CodeName`, `CustomHeight`, `Date1904`, `DefaultColWidth`, `DefaultGridColor`, `DefaultRowHeight`, `EnableFormatConditionsCalculation`, `FilterPrivacy`, `FirstPageNumber`, `FitToHeight`, `FitToPage`, `FitToWidth`, `OutlineSummaryBelow`, `PageLayoutOption`, `PageLayoutOptionPtr`, `PageLayoutOrientation`, `PageLayoutPaperSize`, `PageLayoutScale`, `PageMarginBottom`, `PageMarginFooter`, `PageMarginHeader`, `PageMarginLeft`, `PageMarginRight`, `PageMarginsOptions`, `PageMarginsOptionsPtr`, `PageMarginTop`, `Published`, `RightToLeft`, `SheetFormatPrOptions`, `SheetFormatPrOptionsPtr`, `SheetPrOption`, `SheetPrOptionPtr`, `SheetViewOption`, `SheetViewOptionPtr`, `ShowFormulas`, `ShowGridLines`, `ShowRowColHeaders`, `ShowRuler`, `ShowZeros`, `TabColorIndexed`, `TabColorRGB`, `TabColorTheme`, `TabColorTint`, `ThickBottom`, `ThickTop`, `TopLeftCell`, `View`, `WorkbookPrOption`, `WorkbookPrOptionPtr`, `ZeroHeight` and `ZoomScale`
Remove 2 exported constants:
`OrientationPortrait` and `OrientationLandscape`
Change 8 functions:
- Change the `func (f *File) SetPageLayout(sheet string, opts ...PageLayoutOption) error` to `func (f *File) SetPageLayout(sheet string, opts *PageLayoutOptions) error`
- Change the `func (f *File) GetPageLayout(sheet string, opts ...PageLayoutOptionPtr) error` to `func (f *File) GetPageLayout(sheet string) (PageLayoutOptions, error)`
- Change the `func (f *File) SetPageMargins(sheet string, opts ...PageMarginsOptions) error` to `func (f *File) SetPageMargins(sheet string, opts *PageLayoutMarginsOptions) error`
- Change the `func (f *File) GetPageMargins(sheet string, opts ...PageMarginsOptionsPtr) error` to `func (f *File) GetPageMargins(sheet string) (PageLayoutMarginsOptions, error)`
- Change the `func (f *File) SetSheetViewOptions(sheet string, viewIndex int, opts ...SheetViewOption) error` to `func (f *File) SetSheetView(sheet string, viewIndex int, opts *ViewOptions) error`
- Change the `func (f *File) GetSheetViewOptions(sheet string, viewIndex int, opts ...SheetViewOptionPtr) error` to `func (f *File) GetSheetView(sheet string, viewIndex int) (ViewOptions, error)`
- Change the `func (f *File) SetWorkbookPrOptions(opts ...WorkbookPrOption) error` to `func (f *File) SetWorkbookProps(opts *WorkbookPropsOptions) error`
- Change the `func (f *File) GetWorkbookPrOptions(opts ...WorkbookPrOptionPtr) error` to `func (f *File) GetWorkbookProps() (WorkbookPropsOptions, error)`
Introduce new function to instead of existing functions:
- New function `func (f *File) SetSheetProps(sheet string, opts *SheetPropsOptions) error` instead of `func (f *File) SetSheetPrOptions(sheet string, opts ...SheetPrOption) error` and `func (f *File) SetSheetFormatPr(sheet string, opts ...SheetFormatPrOption
2022-09-29 22:00:21 +08:00
|
|
|
return err
|
2020-01-22 01:08:18 +08:00
|
|
|
}
|
|
|
|
if ws.Drawing == nil {
|
This closes #1358, made a refactor with breaking changes, see details:
This made a refactor with breaking changes:
Motivation and Context
When I decided to add set horizontal centered support for this library to resolve #1358, the reason I made this huge breaking change was:
- There are too many exported types for set sheet view, properties, and format properties, although a function using the functional options pattern can be optimized by returning an anonymous function, these types or property set or get function has no binding categorization, so I change these functions like `SetAppProps` to accept a pointer of options structure.
- Users can not easily find out which properties should be in the `SetSheetPrOptions` or `SetSheetFormatPr` categories
- Nested properties cannot proceed modify easily
Introduce 5 new export data types:
`HeaderFooterOptions`, `PageLayoutMarginsOptions`, `PageLayoutOptions`, `SheetPropsOptions`, and `ViewOptions`
Rename 4 exported data types:
- Rename `PivotTableOption` to `PivotTableOptions`
- Rename `FormatHeaderFooter` to `HeaderFooterOptions`
- Rename `FormatSheetProtection` to `SheetProtectionOptions`
- Rename `SparklineOption` to `SparklineOptions`
Remove 54 exported types:
`AutoPageBreaks`, `BaseColWidth`, `BlackAndWhite`, `CodeName`, `CustomHeight`, `Date1904`, `DefaultColWidth`, `DefaultGridColor`, `DefaultRowHeight`, `EnableFormatConditionsCalculation`, `FilterPrivacy`, `FirstPageNumber`, `FitToHeight`, `FitToPage`, `FitToWidth`, `OutlineSummaryBelow`, `PageLayoutOption`, `PageLayoutOptionPtr`, `PageLayoutOrientation`, `PageLayoutPaperSize`, `PageLayoutScale`, `PageMarginBottom`, `PageMarginFooter`, `PageMarginHeader`, `PageMarginLeft`, `PageMarginRight`, `PageMarginsOptions`, `PageMarginsOptionsPtr`, `PageMarginTop`, `Published`, `RightToLeft`, `SheetFormatPrOptions`, `SheetFormatPrOptionsPtr`, `SheetPrOption`, `SheetPrOptionPtr`, `SheetViewOption`, `SheetViewOptionPtr`, `ShowFormulas`, `ShowGridLines`, `ShowRowColHeaders`, `ShowRuler`, `ShowZeros`, `TabColorIndexed`, `TabColorRGB`, `TabColorTheme`, `TabColorTint`, `ThickBottom`, `ThickTop`, `TopLeftCell`, `View`, `WorkbookPrOption`, `WorkbookPrOptionPtr`, `ZeroHeight` and `ZoomScale`
Remove 2 exported constants:
`OrientationPortrait` and `OrientationLandscape`
Change 8 functions:
- Change the `func (f *File) SetPageLayout(sheet string, opts ...PageLayoutOption) error` to `func (f *File) SetPageLayout(sheet string, opts *PageLayoutOptions) error`
- Change the `func (f *File) GetPageLayout(sheet string, opts ...PageLayoutOptionPtr) error` to `func (f *File) GetPageLayout(sheet string) (PageLayoutOptions, error)`
- Change the `func (f *File) SetPageMargins(sheet string, opts ...PageMarginsOptions) error` to `func (f *File) SetPageMargins(sheet string, opts *PageLayoutMarginsOptions) error`
- Change the `func (f *File) GetPageMargins(sheet string, opts ...PageMarginsOptionsPtr) error` to `func (f *File) GetPageMargins(sheet string) (PageLayoutMarginsOptions, error)`
- Change the `func (f *File) SetSheetViewOptions(sheet string, viewIndex int, opts ...SheetViewOption) error` to `func (f *File) SetSheetView(sheet string, viewIndex int, opts *ViewOptions) error`
- Change the `func (f *File) GetSheetViewOptions(sheet string, viewIndex int, opts ...SheetViewOptionPtr) error` to `func (f *File) GetSheetView(sheet string, viewIndex int) (ViewOptions, error)`
- Change the `func (f *File) SetWorkbookPrOptions(opts ...WorkbookPrOption) error` to `func (f *File) SetWorkbookProps(opts *WorkbookPropsOptions) error`
- Change the `func (f *File) GetWorkbookPrOptions(opts ...WorkbookPrOptionPtr) error` to `func (f *File) GetWorkbookProps() (WorkbookPropsOptions, error)`
Introduce new function to instead of existing functions:
- New function `func (f *File) SetSheetProps(sheet string, opts *SheetPropsOptions) error` instead of `func (f *File) SetSheetPrOptions(sheet string, opts ...SheetPrOption) error` and `func (f *File) SetSheetFormatPr(sheet string, opts ...SheetFormatPrOption
2022-09-29 22:00:21 +08:00
|
|
|
return err
|
2020-01-22 01:08:18 +08:00
|
|
|
}
|
2022-06-12 00:19:12 +08:00
|
|
|
drawingXML := strings.ReplaceAll(f.getSheetRelationshipsTargetByID(sheet, ws.Drawing.RID), "..", "xl")
|
2023-10-09 00:14:56 +08:00
|
|
|
drawingRels := "xl/drawings/_rels/" + filepath.Base(drawingXML) + ".rels"
|
|
|
|
rID, err := f.deleteDrawing(col, row, drawingXML, "Pic")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
rels := f.getDrawingRelationships(drawingRels, rID)
|
|
|
|
if rels == nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
var used bool
|
2023-10-10 00:04:10 +08:00
|
|
|
checkPicRef := func(k, v interface{}) bool {
|
|
|
|
if strings.Contains(k.(string), "xl/drawings/_rels/drawing") {
|
2023-10-09 00:14:56 +08:00
|
|
|
r, err := f.relsReader(k.(string))
|
|
|
|
if err != nil {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
for _, rel := range r.Relationships {
|
|
|
|
if rel.ID != rels.ID && rel.Type == SourceRelationshipImage &&
|
|
|
|
filepath.Base(rel.Target) == filepath.Base(rels.Target) {
|
|
|
|
used = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
2023-10-10 00:04:10 +08:00
|
|
|
}
|
|
|
|
f.Relationships.Range(checkPicRef)
|
|
|
|
f.Pkg.Range(checkPicRef)
|
2023-10-09 00:14:56 +08:00
|
|
|
if !used {
|
|
|
|
f.Pkg.Delete(strings.Replace(rels.Target, "../", "xl/", -1))
|
|
|
|
}
|
|
|
|
f.deleteDrawingRels(drawingRels, rID)
|
|
|
|
return err
|
2020-01-22 01:08:18 +08:00
|
|
|
}
|
|
|
|
|
2019-06-20 00:00:40 +08:00
|
|
|
// getPicture provides a function to get picture base name and raw content
|
2020-07-09 01:24:11 +08:00
|
|
|
// embed in spreadsheet by given coordinates and drawing relationships.
|
Breaking changes: changed the function signature for 2 exported functions
- Change
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *GraphicOptions) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell string, pic *Picture) error`
- Change
`func (f *File) GetPicture(sheet, cell string) (string, []byte, error)`
to
`func (f *File) GetPictures(sheet, cell string) ([]Picture, error)`
Co-authored-by: huangsk <645636204@qq.com>
2023-03-19 20:23:33 +08:00
|
|
|
func (f *File) getPicture(row, col int, drawingXML, drawingRelationships string) (pics []Picture, err error) {
|
2023-11-06 09:51:19 +08:00
|
|
|
var wsDr *xlsxWsDr
|
2022-11-12 00:02:11 +08:00
|
|
|
if wsDr, _, err = f.drawingParser(drawingXML); err != nil {
|
|
|
|
return
|
|
|
|
}
|
2023-11-06 09:51:19 +08:00
|
|
|
wsDr.mu.Lock()
|
|
|
|
defer wsDr.mu.Unlock()
|
|
|
|
cond := func(from *xlsxFrom) bool { return from.Col == col && from.Row == row }
|
|
|
|
cond2 := func(from *decodeFrom) bool { return from.Col == col && from.Row == row }
|
|
|
|
cb := func(a *xdrCellAnchor, r *xlsxRelationship) {
|
2024-03-27 15:50:51 +08:00
|
|
|
pic := Picture{Extension: filepath.Ext(r.Target), Format: &GraphicOptions{}, InsertType: PictureInsertTypePlaceOverCells}
|
2024-05-03 18:16:00 +08:00
|
|
|
if buffer, _ := f.Pkg.Load(filepath.ToSlash(filepath.Clean("xl/drawings/" + r.Target))); buffer != nil {
|
2023-10-13 00:06:07 +08:00
|
|
|
pic.File = buffer.([]byte)
|
|
|
|
pic.Format.AltText = a.Pic.NvPicPr.CNvPr.Descr
|
|
|
|
pics = append(pics, pic)
|
|
|
|
}
|
|
|
|
}
|
2023-11-06 09:51:19 +08:00
|
|
|
cb2 := func(a *decodeCellAnchor, r *xlsxRelationship) {
|
2024-03-27 15:50:51 +08:00
|
|
|
pic := Picture{Extension: filepath.Ext(r.Target), Format: &GraphicOptions{}, InsertType: PictureInsertTypePlaceOverCells}
|
2024-05-03 18:16:00 +08:00
|
|
|
if buffer, _ := f.Pkg.Load(filepath.ToSlash(filepath.Clean("xl/drawings/" + r.Target))); buffer != nil {
|
2023-10-13 00:06:07 +08:00
|
|
|
pic.File = buffer.([]byte)
|
|
|
|
pic.Format.AltText = a.Pic.NvPicPr.CNvPr.Descr
|
|
|
|
pics = append(pics, pic)
|
2017-03-28 21:18:06 +08:00
|
|
|
}
|
|
|
|
}
|
2023-11-06 09:51:19 +08:00
|
|
|
for _, anchor := range wsDr.TwoCellAnchor {
|
|
|
|
f.extractCellAnchor(anchor, drawingRelationships, cond, cb, cond2, cb2)
|
This ref #1585, support to read one cell anchor pictures and improve date and time number format
- Support apply date and time number format with 16 languages: Persian, Polish, Portuguese, Punjabi, Quechua, Romanian, Romansh, Sakha, Sami, Sanskrit, Scottish Gaelic, Serbian, Sesotho sa Leboa, Setswana, Sindhi, Sinhala and Slovak
- Update the unit test and dependencies modules
2023-08-09 00:11:06 +08:00
|
|
|
}
|
2023-11-06 09:51:19 +08:00
|
|
|
for _, anchor := range wsDr.OneCellAnchor {
|
|
|
|
f.extractCellAnchor(anchor, drawingRelationships, cond, cb, cond2, cb2)
|
This ref #1585, support to read one cell anchor pictures and improve date and time number format
- Support apply date and time number format with 16 languages: Persian, Polish, Portuguese, Punjabi, Quechua, Romanian, Romansh, Sakha, Sami, Sanskrit, Scottish Gaelic, Serbian, Sesotho sa Leboa, Setswana, Sindhi, Sinhala and Slovak
- Update the unit test and dependencies modules
2023-08-09 00:11:06 +08:00
|
|
|
}
|
2019-12-22 00:02:09 +08:00
|
|
|
return
|
|
|
|
}
|
2019-12-20 00:30:48 +08:00
|
|
|
|
2023-10-13 00:06:07 +08:00
|
|
|
// extractCellAnchor extract drawing object from cell anchor by giving drawing
|
|
|
|
// cell anchor, drawing relationships part path, conditional and callback
|
|
|
|
// function.
|
2023-11-06 09:51:19 +08:00
|
|
|
func (f *File) extractCellAnchor(anchor *xdrCellAnchor, drawingRelationships string,
|
|
|
|
cond func(from *xlsxFrom) bool, cb func(anchor *xdrCellAnchor, rels *xlsxRelationship),
|
|
|
|
cond2 func(from *decodeFrom) bool, cb2 func(anchor *decodeCellAnchor, rels *xlsxRelationship),
|
2023-10-13 00:06:07 +08:00
|
|
|
) {
|
2023-11-06 09:51:19 +08:00
|
|
|
var drawRel *xlsxRelationship
|
|
|
|
if anchor.GraphicFrame == "" {
|
2019-12-22 00:02:09 +08:00
|
|
|
if anchor.From != nil && anchor.Pic != nil {
|
2023-11-06 09:51:19 +08:00
|
|
|
if cond(anchor.From) {
|
2020-07-11 02:31:02 +08:00
|
|
|
if drawRel = f.getDrawingRelationships(drawingRelationships,
|
|
|
|
anchor.Pic.BlipFill.Blip.Embed); drawRel != nil {
|
2023-10-13 00:06:07 +08:00
|
|
|
if _, ok := supportedImageTypes[strings.ToLower(filepath.Ext(drawRel.Target))]; ok {
|
|
|
|
cb(anchor, drawRel)
|
2020-07-11 02:31:02 +08:00
|
|
|
}
|
2019-12-22 00:02:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-11-06 09:51:19 +08:00
|
|
|
return
|
2019-12-22 00:02:09 +08:00
|
|
|
}
|
2023-11-06 09:51:19 +08:00
|
|
|
f.extractDecodeCellAnchor(anchor, drawingRelationships, cond2, cb2)
|
2023-10-13 00:06:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// extractDecodeCellAnchor extract drawing object from cell anchor by giving
|
|
|
|
// decoded drawing cell anchor, drawing relationships part path, conditional and
|
|
|
|
// callback function.
|
2023-11-06 09:51:19 +08:00
|
|
|
func (f *File) extractDecodeCellAnchor(anchor *xdrCellAnchor, drawingRelationships string,
|
|
|
|
cond func(from *decodeFrom) bool, cb func(anchor *decodeCellAnchor, rels *xlsxRelationship),
|
2023-10-13 00:06:07 +08:00
|
|
|
) {
|
|
|
|
var (
|
|
|
|
drawRel *xlsxRelationship
|
|
|
|
deCellAnchor = new(decodeCellAnchor)
|
|
|
|
)
|
2023-11-06 09:51:19 +08:00
|
|
|
_ = f.xmlNewDecoder(strings.NewReader("<decodeCellAnchor>" + anchor.GraphicFrame + "</decodeCellAnchor>")).Decode(&deCellAnchor)
|
2023-10-13 00:06:07 +08:00
|
|
|
if deCellAnchor.From != nil && deCellAnchor.Pic != nil {
|
2023-11-06 09:51:19 +08:00
|
|
|
if cond(deCellAnchor.From) {
|
2023-11-16 09:34:37 +08:00
|
|
|
if drawRel = f.getDrawingRelationships(drawingRelationships, deCellAnchor.Pic.BlipFill.Blip.Embed); drawRel != nil {
|
|
|
|
if _, ok := supportedImageTypes[strings.ToLower(filepath.Ext(drawRel.Target))]; ok {
|
|
|
|
cb(deCellAnchor, drawRel)
|
|
|
|
}
|
2023-10-13 00:06:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-28 21:18:06 +08:00
|
|
|
}
|
|
|
|
|
2018-08-06 10:21:24 +08:00
|
|
|
// getDrawingRelationships provides a function to get drawing relationships
|
|
|
|
// from xl/drawings/_rels/drawing%s.xml.rels by given file name and
|
|
|
|
// relationship ID.
|
2019-09-16 01:17:35 +08:00
|
|
|
func (f *File) getDrawingRelationships(rels, rID string) *xlsxRelationship {
|
2022-11-13 00:40:04 +08:00
|
|
|
if drawingRels, _ := f.relsReader(rels); drawingRels != nil {
|
2023-04-24 00:02:13 +08:00
|
|
|
drawingRels.mu.Lock()
|
|
|
|
defer drawingRels.mu.Unlock()
|
2019-02-25 22:14:34 +08:00
|
|
|
for _, v := range drawingRels.Relationships {
|
|
|
|
if v.ID == rID {
|
|
|
|
return &v
|
|
|
|
}
|
2017-03-28 21:18:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2019-02-25 22:14:34 +08:00
|
|
|
|
|
|
|
// drawingsWriter provides a function to save xl/drawings/drawing%d.xml after
|
|
|
|
// serialize structure.
|
|
|
|
func (f *File) drawingsWriter() {
|
2021-07-04 12:13:06 +08:00
|
|
|
f.Drawings.Range(func(path, d interface{}) bool {
|
2019-02-25 22:14:34 +08:00
|
|
|
if d != nil {
|
2021-07-04 12:13:06 +08:00
|
|
|
v, _ := xml.Marshal(d.(*xlsxWsDr))
|
|
|
|
f.saveFileList(path.(string), v)
|
2019-02-25 22:14:34 +08:00
|
|
|
}
|
2021-07-04 12:13:06 +08:00
|
|
|
return true
|
|
|
|
})
|
2019-02-25 22:14:34 +08:00
|
|
|
}
|
2020-05-17 17:36:53 +08:00
|
|
|
|
|
|
|
// drawingResize calculate the height and width after resizing.
|
2023-01-02 11:47:31 +08:00
|
|
|
func (f *File) drawingResize(sheet, cell string, width, height float64, opts *GraphicOptions) (w, h, c, r int, err error) {
|
2020-05-17 17:36:53 +08:00
|
|
|
var mergeCells []MergeCell
|
|
|
|
mergeCells, err = f.GetMergeCells(sheet)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var rng []int
|
|
|
|
var inMergeCell bool
|
|
|
|
if c, r, err = CellNameToCoordinates(cell); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
cellWidth, cellHeight := f.getColWidth(sheet, c), f.getRowHeight(sheet, r)
|
|
|
|
for _, mergeCell := range mergeCells {
|
2020-12-14 20:56:51 +08:00
|
|
|
if inMergeCell {
|
|
|
|
continue
|
|
|
|
}
|
2023-10-13 00:06:07 +08:00
|
|
|
if inMergeCell, err = f.checkCellInRangeRef(cell, mergeCell[0]); err == nil {
|
2022-09-28 00:04:17 +08:00
|
|
|
rng, _ = cellRefsToCoordinates(mergeCell.GetStartAxis(), mergeCell.GetEndAxis())
|
2021-02-15 00:09:35 +08:00
|
|
|
_ = sortCoordinates(rng)
|
2020-05-17 17:36:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if inMergeCell {
|
2020-05-21 22:57:58 +08:00
|
|
|
cellWidth, cellHeight = 0, 0
|
2020-05-17 17:36:53 +08:00
|
|
|
c, r = rng[0], rng[1]
|
2021-06-13 14:38:01 +08:00
|
|
|
for col := rng[0]; col <= rng[2]; col++ {
|
2020-05-17 17:36:53 +08:00
|
|
|
cellWidth += f.getColWidth(sheet, col)
|
|
|
|
}
|
2021-06-13 14:38:01 +08:00
|
|
|
for row := rng[1]; row <= rng[3]; row++ {
|
2020-05-17 17:36:53 +08:00
|
|
|
cellHeight += f.getRowHeight(sheet, row)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if float64(cellWidth) < width {
|
|
|
|
asp := float64(cellWidth) / width
|
|
|
|
width, height = float64(cellWidth), height*asp
|
|
|
|
}
|
|
|
|
if float64(cellHeight) < height {
|
|
|
|
asp := float64(cellHeight) / height
|
|
|
|
height, width = float64(cellHeight), width*asp
|
|
|
|
}
|
2024-06-19 20:45:25 +08:00
|
|
|
if opts.AutoFitIgnoreAspect {
|
|
|
|
width, height = float64(cellWidth), float64(cellHeight)
|
|
|
|
}
|
This closes #1358, made a refactor with breaking changes, see details:
This made a refactor with breaking changes:
Motivation and Context
When I decided to add set horizontal centered support for this library to resolve #1358, the reason I made this huge breaking change was:
- There are too many exported types for set sheet view, properties, and format properties, although a function using the functional options pattern can be optimized by returning an anonymous function, these types or property set or get function has no binding categorization, so I change these functions like `SetAppProps` to accept a pointer of options structure.
- Users can not easily find out which properties should be in the `SetSheetPrOptions` or `SetSheetFormatPr` categories
- Nested properties cannot proceed modify easily
Introduce 5 new export data types:
`HeaderFooterOptions`, `PageLayoutMarginsOptions`, `PageLayoutOptions`, `SheetPropsOptions`, and `ViewOptions`
Rename 4 exported data types:
- Rename `PivotTableOption` to `PivotTableOptions`
- Rename `FormatHeaderFooter` to `HeaderFooterOptions`
- Rename `FormatSheetProtection` to `SheetProtectionOptions`
- Rename `SparklineOption` to `SparklineOptions`
Remove 54 exported types:
`AutoPageBreaks`, `BaseColWidth`, `BlackAndWhite`, `CodeName`, `CustomHeight`, `Date1904`, `DefaultColWidth`, `DefaultGridColor`, `DefaultRowHeight`, `EnableFormatConditionsCalculation`, `FilterPrivacy`, `FirstPageNumber`, `FitToHeight`, `FitToPage`, `FitToWidth`, `OutlineSummaryBelow`, `PageLayoutOption`, `PageLayoutOptionPtr`, `PageLayoutOrientation`, `PageLayoutPaperSize`, `PageLayoutScale`, `PageMarginBottom`, `PageMarginFooter`, `PageMarginHeader`, `PageMarginLeft`, `PageMarginRight`, `PageMarginsOptions`, `PageMarginsOptionsPtr`, `PageMarginTop`, `Published`, `RightToLeft`, `SheetFormatPrOptions`, `SheetFormatPrOptionsPtr`, `SheetPrOption`, `SheetPrOptionPtr`, `SheetViewOption`, `SheetViewOptionPtr`, `ShowFormulas`, `ShowGridLines`, `ShowRowColHeaders`, `ShowRuler`, `ShowZeros`, `TabColorIndexed`, `TabColorRGB`, `TabColorTheme`, `TabColorTint`, `ThickBottom`, `ThickTop`, `TopLeftCell`, `View`, `WorkbookPrOption`, `WorkbookPrOptionPtr`, `ZeroHeight` and `ZoomScale`
Remove 2 exported constants:
`OrientationPortrait` and `OrientationLandscape`
Change 8 functions:
- Change the `func (f *File) SetPageLayout(sheet string, opts ...PageLayoutOption) error` to `func (f *File) SetPageLayout(sheet string, opts *PageLayoutOptions) error`
- Change the `func (f *File) GetPageLayout(sheet string, opts ...PageLayoutOptionPtr) error` to `func (f *File) GetPageLayout(sheet string) (PageLayoutOptions, error)`
- Change the `func (f *File) SetPageMargins(sheet string, opts ...PageMarginsOptions) error` to `func (f *File) SetPageMargins(sheet string, opts *PageLayoutMarginsOptions) error`
- Change the `func (f *File) GetPageMargins(sheet string, opts ...PageMarginsOptionsPtr) error` to `func (f *File) GetPageMargins(sheet string) (PageLayoutMarginsOptions, error)`
- Change the `func (f *File) SetSheetViewOptions(sheet string, viewIndex int, opts ...SheetViewOption) error` to `func (f *File) SetSheetView(sheet string, viewIndex int, opts *ViewOptions) error`
- Change the `func (f *File) GetSheetViewOptions(sheet string, viewIndex int, opts ...SheetViewOptionPtr) error` to `func (f *File) GetSheetView(sheet string, viewIndex int) (ViewOptions, error)`
- Change the `func (f *File) SetWorkbookPrOptions(opts ...WorkbookPrOption) error` to `func (f *File) SetWorkbookProps(opts *WorkbookPropsOptions) error`
- Change the `func (f *File) GetWorkbookPrOptions(opts ...WorkbookPrOptionPtr) error` to `func (f *File) GetWorkbookProps() (WorkbookPropsOptions, error)`
Introduce new function to instead of existing functions:
- New function `func (f *File) SetSheetProps(sheet string, opts *SheetPropsOptions) error` instead of `func (f *File) SetSheetPrOptions(sheet string, opts ...SheetPrOption) error` and `func (f *File) SetSheetFormatPr(sheet string, opts ...SheetFormatPrOption
2022-09-29 22:00:21 +08:00
|
|
|
width, height = width-float64(opts.OffsetX), height-float64(opts.OffsetY)
|
2023-01-02 11:47:31 +08:00
|
|
|
w, h = int(width*opts.ScaleX), int(height*opts.ScaleY)
|
2020-05-17 17:36:53 +08:00
|
|
|
return
|
|
|
|
}
|
2023-10-13 00:06:07 +08:00
|
|
|
|
|
|
|
// getPictureCells provides a function to get all picture cell references in a
|
|
|
|
// worksheet by given drawing part path and drawing relationships path.
|
|
|
|
func (f *File) getPictureCells(drawingXML, drawingRelationships string) ([]string, error) {
|
|
|
|
var (
|
2023-11-06 09:51:19 +08:00
|
|
|
cells []string
|
|
|
|
err error
|
|
|
|
wsDr *xlsxWsDr
|
2023-10-13 00:06:07 +08:00
|
|
|
)
|
|
|
|
if wsDr, _, err = f.drawingParser(drawingXML); err != nil {
|
|
|
|
return cells, err
|
|
|
|
}
|
2023-11-06 09:51:19 +08:00
|
|
|
wsDr.mu.Lock()
|
|
|
|
defer wsDr.mu.Unlock()
|
|
|
|
cond := func(from *xlsxFrom) bool { return true }
|
|
|
|
cond2 := func(from *decodeFrom) bool { return true }
|
|
|
|
cb := func(a *xdrCellAnchor, r *xlsxRelationship) {
|
2024-05-03 18:16:00 +08:00
|
|
|
if _, ok := f.Pkg.Load(filepath.ToSlash(filepath.Clean("xl/drawings/" + r.Target))); ok {
|
2023-10-13 00:06:07 +08:00
|
|
|
if cell, err := CoordinatesToCellName(a.From.Col+1, a.From.Row+1); err == nil && inStrSlice(cells, cell, true) == -1 {
|
|
|
|
cells = append(cells, cell)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-11-06 09:51:19 +08:00
|
|
|
cb2 := func(a *decodeCellAnchor, r *xlsxRelationship) {
|
2024-05-03 18:16:00 +08:00
|
|
|
if _, ok := f.Pkg.Load(filepath.ToSlash(filepath.Clean("xl/drawings/" + r.Target))); ok {
|
2023-10-13 00:06:07 +08:00
|
|
|
if cell, err := CoordinatesToCellName(a.From.Col+1, a.From.Row+1); err == nil && inStrSlice(cells, cell, true) == -1 {
|
|
|
|
cells = append(cells, cell)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-11-06 09:51:19 +08:00
|
|
|
for _, anchor := range wsDr.TwoCellAnchor {
|
|
|
|
f.extractCellAnchor(anchor, drawingRelationships, cond, cb, cond2, cb2)
|
2023-10-13 00:06:07 +08:00
|
|
|
}
|
2023-11-06 09:51:19 +08:00
|
|
|
for _, anchor := range wsDr.OneCellAnchor {
|
|
|
|
f.extractCellAnchor(anchor, drawingRelationships, cond, cb, cond2, cb2)
|
2023-10-13 00:06:07 +08:00
|
|
|
}
|
|
|
|
return cells, err
|
|
|
|
}
|
2023-12-15 13:09:42 +08:00
|
|
|
|
|
|
|
// cellImagesReader provides a function to get the pointer to the structure
|
|
|
|
// after deserialization of xl/cellimages.xml.
|
|
|
|
func (f *File) cellImagesReader() (*decodeCellImages, error) {
|
|
|
|
if f.DecodeCellImages == nil {
|
|
|
|
f.DecodeCellImages = new(decodeCellImages)
|
|
|
|
if err := f.xmlNewDecoder(bytes.NewReader(namespaceStrictToTransitional(f.readXML(defaultXMLPathCellImages)))).
|
|
|
|
Decode(f.DecodeCellImages); err != nil && err != io.EOF {
|
|
|
|
return f.DecodeCellImages, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return f.DecodeCellImages, nil
|
|
|
|
}
|
|
|
|
|
2024-03-28 16:37:35 +08:00
|
|
|
// getImageCells returns all the cell images and the Kingsoft WPS
|
2024-03-26 23:19:23 +08:00
|
|
|
// Office embedded image cells reference by given worksheet name.
|
|
|
|
func (f *File) getImageCells(sheet string) ([]string, error) {
|
2023-12-19 23:39:45 +08:00
|
|
|
var (
|
|
|
|
err error
|
|
|
|
cells []string
|
|
|
|
)
|
|
|
|
ws, err := f.workSheetReader(sheet)
|
|
|
|
if err != nil {
|
|
|
|
return cells, err
|
|
|
|
}
|
|
|
|
for _, row := range ws.SheetData.Row {
|
|
|
|
for _, c := range row.C {
|
|
|
|
if c.F != nil && c.F.Content != "" &&
|
|
|
|
strings.HasPrefix(strings.TrimPrefix(strings.TrimPrefix(c.F.Content, "="), "_xlfn."), "DISPIMG") {
|
|
|
|
if _, err = f.CalcCellValue(sheet, c.R); err != nil {
|
|
|
|
return cells, err
|
|
|
|
}
|
|
|
|
cells = append(cells, c.R)
|
|
|
|
}
|
2024-04-02 08:47:57 +08:00
|
|
|
r, err := f.getImageCellRel(&c, &Picture{})
|
2024-03-26 23:19:23 +08:00
|
|
|
if err != nil {
|
|
|
|
return cells, err
|
|
|
|
}
|
|
|
|
if r != nil {
|
|
|
|
cells = append(cells, c.R)
|
|
|
|
}
|
|
|
|
|
2023-12-19 23:39:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return cells, err
|
|
|
|
}
|
|
|
|
|
2024-04-02 08:47:57 +08:00
|
|
|
// getRichDataRichValueRel returns relationship of the cell image by given meta
|
|
|
|
// blocks value.
|
|
|
|
func (f *File) getRichDataRichValueRel(val string) (*xlsxRelationship, error) {
|
|
|
|
var r *xlsxRelationship
|
|
|
|
idx, err := strconv.Atoi(val)
|
2024-03-28 16:37:35 +08:00
|
|
|
if err != nil {
|
2024-04-02 08:47:57 +08:00
|
|
|
return r, err
|
2024-03-28 16:37:35 +08:00
|
|
|
}
|
2024-04-02 08:47:57 +08:00
|
|
|
richValueRel, err := f.richValueRelReader()
|
|
|
|
if err != nil {
|
|
|
|
return r, err
|
2024-03-28 16:37:35 +08:00
|
|
|
}
|
2024-04-02 08:47:57 +08:00
|
|
|
if idx >= len(richValueRel.Rels) {
|
|
|
|
return r, err
|
|
|
|
}
|
|
|
|
rID := richValueRel.Rels[idx].ID
|
|
|
|
if r = f.getRichDataRichValueRelRelationships(rID); r != nil && r.Type != SourceRelationshipImage {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return r, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// getRichDataWebImagesRel returns relationship of a web image by given meta
|
|
|
|
// blocks value.
|
|
|
|
func (f *File) getRichDataWebImagesRel(val string) (*xlsxRelationship, error) {
|
|
|
|
var r *xlsxRelationship
|
|
|
|
idx, err := strconv.Atoi(val)
|
|
|
|
if err != nil {
|
|
|
|
return r, err
|
2024-03-28 16:37:35 +08:00
|
|
|
}
|
2024-04-02 08:47:57 +08:00
|
|
|
richValueWebImages, err := f.richValueWebImageReader()
|
2024-03-28 16:37:35 +08:00
|
|
|
if err != nil {
|
2024-04-02 08:47:57 +08:00
|
|
|
return r, err
|
|
|
|
}
|
|
|
|
if idx >= len(richValueWebImages.WebImageSrd) {
|
|
|
|
return r, err
|
2024-03-28 16:37:35 +08:00
|
|
|
}
|
2024-04-02 08:47:57 +08:00
|
|
|
rID := richValueWebImages.WebImageSrd[idx].Blip.RID
|
|
|
|
if r = f.getRichValueWebImageRelationships(rID); r != nil && r.Type != SourceRelationshipImage {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return r, err
|
2024-03-28 16:37:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// getImageCellRel returns the cell image relationship.
|
2024-04-02 08:47:57 +08:00
|
|
|
func (f *File) getImageCellRel(c *xlsxC, pic *Picture) (*xlsxRelationship, error) {
|
2024-03-26 23:19:23 +08:00
|
|
|
var r *xlsxRelationship
|
|
|
|
if c.Vm == nil || c.V != formulaErrorVALUE {
|
|
|
|
return r, nil
|
|
|
|
}
|
|
|
|
metaData, err := f.metadataReader()
|
|
|
|
if err != nil {
|
|
|
|
return r, err
|
|
|
|
}
|
|
|
|
vmd := metaData.ValueMetadata
|
|
|
|
if vmd == nil || int(*c.Vm) > len(vmd.Bk) || len(vmd.Bk[*c.Vm-1].Rc) == 0 {
|
|
|
|
return r, err
|
|
|
|
}
|
2024-04-02 08:47:57 +08:00
|
|
|
richValueIdx := vmd.Bk[*c.Vm-1].Rc[0].V
|
|
|
|
richValue, err := f.richValueReader()
|
2024-03-26 23:19:23 +08:00
|
|
|
if err != nil {
|
|
|
|
return r, err
|
|
|
|
}
|
2024-04-02 08:47:57 +08:00
|
|
|
if richValueIdx >= len(richValue.Rv) {
|
2024-03-26 23:19:23 +08:00
|
|
|
return r, err
|
|
|
|
}
|
2024-04-02 08:47:57 +08:00
|
|
|
rv := richValue.Rv[richValueIdx].V
|
|
|
|
if len(rv) == 2 && rv[1] == "5" {
|
|
|
|
pic.InsertType = PictureInsertTypePlaceInCell
|
|
|
|
return f.getRichDataRichValueRel(rv[0])
|
|
|
|
}
|
|
|
|
// cell image inserted by IMAGE formula function
|
|
|
|
if len(rv) > 3 && rv[1]+rv[2] == "10" {
|
|
|
|
pic.InsertType = PictureInsertTypeIMAGE
|
|
|
|
return f.getRichDataWebImagesRel(rv[0])
|
2024-03-26 23:19:23 +08:00
|
|
|
}
|
|
|
|
return r, err
|
|
|
|
}
|
|
|
|
|
2024-03-28 16:37:35 +08:00
|
|
|
// getCellImages provides a function to get the cell images and
|
2024-03-26 23:19:23 +08:00
|
|
|
// the Kingsoft WPS Office embedded cell images by given worksheet name and cell
|
|
|
|
// reference.
|
2023-12-15 13:09:42 +08:00
|
|
|
func (f *File) getCellImages(sheet, cell string) ([]Picture, error) {
|
2024-03-26 23:19:23 +08:00
|
|
|
pics, err := f.getDispImages(sheet, cell)
|
|
|
|
if err != nil {
|
|
|
|
return pics, err
|
|
|
|
}
|
|
|
|
_, err = f.getCellStringFunc(sheet, cell, func(x *xlsxWorksheet, c *xlsxC) (string, bool, error) {
|
2024-04-02 08:47:57 +08:00
|
|
|
pic := Picture{Format: &GraphicOptions{}, InsertType: PictureInsertTypePlaceInCell}
|
|
|
|
r, err := f.getImageCellRel(c, &pic)
|
2024-03-26 23:19:23 +08:00
|
|
|
if err != nil || r == nil {
|
|
|
|
return "", true, err
|
|
|
|
}
|
2024-04-02 08:47:57 +08:00
|
|
|
pic.Extension = filepath.Ext(r.Target)
|
2024-03-26 23:19:23 +08:00
|
|
|
if buffer, _ := f.Pkg.Load(strings.TrimPrefix(strings.ReplaceAll(r.Target, "..", "xl"), "/")); buffer != nil {
|
|
|
|
pic.File = buffer.([]byte)
|
|
|
|
pics = append(pics, pic)
|
|
|
|
}
|
|
|
|
return "", true, nil
|
|
|
|
})
|
|
|
|
return pics, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// getDispImages provides a function to get the Kingsoft WPS Office embedded
|
|
|
|
// cell images by given worksheet name and cell reference.
|
|
|
|
func (f *File) getDispImages(sheet, cell string) ([]Picture, error) {
|
2023-12-15 13:09:42 +08:00
|
|
|
formula, err := f.GetCellFormula(sheet, cell)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if !strings.HasPrefix(strings.TrimPrefix(strings.TrimPrefix(formula, "="), "_xlfn."), "DISPIMG") {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
imgID, err := f.CalcCellValue(sheet, cell)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
cellImages, err := f.cellImagesReader()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
rels, err := f.relsReader(defaultXMLPathCellImagesRels)
|
|
|
|
if rels == nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var pics []Picture
|
|
|
|
for _, cellImg := range cellImages.CellImage {
|
|
|
|
if cellImg.Pic.NvPicPr.CNvPr.Name == imgID {
|
|
|
|
for _, r := range rels.Relationships {
|
|
|
|
if r.ID == cellImg.Pic.BlipFill.Blip.Embed {
|
2024-03-27 15:50:51 +08:00
|
|
|
pic := Picture{Extension: filepath.Ext(r.Target), Format: &GraphicOptions{}, InsertType: PictureInsertTypeDISPIMG}
|
2023-12-15 13:09:42 +08:00
|
|
|
if buffer, _ := f.Pkg.Load("xl/" + r.Target); buffer != nil {
|
|
|
|
pic.File = buffer.([]byte)
|
|
|
|
pic.Format.AltText = cellImg.Pic.NvPicPr.CNvPr.Descr
|
|
|
|
pics = append(pics, pic)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return pics, err
|
|
|
|
}
|