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
|
|
|
|
2016-08-30 21:54:28 +08:00
|
|
|
package excelize
|
|
|
|
|
2023-04-26 00:04:47 +08:00
|
|
|
import (
|
|
|
|
"encoding/xml"
|
|
|
|
"sync"
|
|
|
|
)
|
2016-08-30 21:54:28 +08:00
|
|
|
|
|
|
|
// xlsxSST directly maps the sst element from the namespace
|
2017-02-07 14:03:03 +08:00
|
|
|
// http://schemas.openxmlformats.org/spreadsheetml/2006/main. String values may
|
|
|
|
// be stored directly inside spreadsheet cell elements; however, storing the
|
|
|
|
// same value inside multiple cell elements can result in very large worksheet
|
|
|
|
// Parts, possibly resulting in performance degradation. The Shared String Table
|
|
|
|
// is an indexed list of string values, shared across the workbook, which allows
|
|
|
|
// implementations to store values only once.
|
2016-08-30 21:54:28 +08:00
|
|
|
type xlsxSST struct {
|
2023-04-26 00:04:47 +08:00
|
|
|
mu sync.Mutex
|
2016-08-30 21:54:28 +08:00
|
|
|
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/spreadsheetml/2006/main sst"`
|
|
|
|
Count int `xml:"count,attr"`
|
|
|
|
UniqueCount int `xml:"uniqueCount,attr"`
|
|
|
|
SI []xlsxSI `xml:"si"`
|
|
|
|
}
|
|
|
|
|
2020-04-06 00:23:27 +08:00
|
|
|
// xlsxSI (String Item) is the representation of an individual string in the
|
|
|
|
// Shared String table. If the string is just a simple string with formatting
|
|
|
|
// applied at the cell level, then the String Item (si) should contain a
|
|
|
|
// single text element used to express the string. However, if the string in
|
|
|
|
// the cell is more complex - i.e., has formatting applied at the character
|
|
|
|
// level - then the string item shall consist of multiple rich text runs which
|
|
|
|
// collectively are used to express the string.
|
2016-08-30 21:54:28 +08:00
|
|
|
type xlsxSI struct {
|
2020-09-03 23:44:43 +08:00
|
|
|
T *xlsxT `xml:"t,omitempty"`
|
|
|
|
R []xlsxR `xml:"r"`
|
|
|
|
RPh []*xlsxPhoneticRun `xml:"rPh"`
|
|
|
|
PhoneticPr *xlsxPhoneticPr `xml:"phoneticPr"`
|
2016-08-30 21:54:28 +08:00
|
|
|
}
|
|
|
|
|
2020-04-06 00:23:27 +08:00
|
|
|
// xlsxR represents a run of rich text. A rich text run is a region of text
|
|
|
|
// that share a common set of properties, such as formatting properties. The
|
|
|
|
// properties are defined in the rPr element, and the text displayed to the
|
|
|
|
// user is defined in the Text (t) element.
|
2016-08-30 21:54:28 +08:00
|
|
|
type xlsxR struct {
|
2022-10-10 00:11:18 +08:00
|
|
|
XMLName xml.Name `xml:"r"`
|
|
|
|
RPr *xlsxRPr `xml:"rPr"`
|
|
|
|
T *xlsxT `xml:"t"`
|
2020-04-06 00:23:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// xlsxT directly maps the t element in the run properties.
|
|
|
|
type xlsxT struct {
|
|
|
|
XMLName xml.Name `xml:"t"`
|
2020-05-26 02:09:39 +08:00
|
|
|
Space xml.Attr `xml:"space,attr,omitempty"`
|
2020-07-01 22:41:29 +08:00
|
|
|
Val string `xml:",chardata"`
|
2017-05-13 13:28:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// xlsxRPr (Run Properties) specifies a set of run properties which shall be
|
|
|
|
// applied to the contents of the parent run after all style formatting has been
|
|
|
|
// applied to the text. These properties are defined as direct formatting, since
|
|
|
|
// they are directly applied to the run and supersede any formatting from
|
|
|
|
// styles.
|
|
|
|
type xlsxRPr struct {
|
2020-04-06 00:23:27 +08:00
|
|
|
RFont *attrValString `xml:"rFont"`
|
|
|
|
Charset *attrValInt `xml:"charset"`
|
|
|
|
Family *attrValInt `xml:"family"`
|
2021-02-22 20:04:13 +08:00
|
|
|
B *string `xml:"b"`
|
|
|
|
I *string `xml:"i"`
|
|
|
|
Strike *string `xml:"strike"`
|
|
|
|
Outline *string `xml:"outline"`
|
|
|
|
Shadow *string `xml:"shadow"`
|
|
|
|
Condense *string `xml:"condense"`
|
|
|
|
Extend *string `xml:"extend"`
|
2020-04-06 00:23:27 +08:00
|
|
|
Color *xlsxColor `xml:"color"`
|
|
|
|
Sz *attrValFloat `xml:"sz"`
|
|
|
|
U *attrValString `xml:"u"`
|
|
|
|
VertAlign *attrValString `xml:"vertAlign"`
|
|
|
|
Scheme *attrValString `xml:"scheme"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// RichTextRun directly maps the settings of the rich text run.
|
|
|
|
type RichTextRun struct {
|
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
|
|
|
Font *Font
|
|
|
|
Text string
|
2016-08-30 21:54:28 +08:00
|
|
|
}
|