summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxuri <xuri.me@gmail.com>2020-07-11 02:31:02 +0800
committerxuri <xuri.me@gmail.com>2020-07-11 02:31:02 +0800
commit0aa15106947965bdae9daae7571a4a3f569bf32d (patch)
tree212b49784a953a056169351be9d07e3abefb8a55
parent42b1c8148883844cf80b70a3096e6ee67be01f61 (diff)
update docs and improve compatibility
-rw-r--r--drawing.go2
-rw-r--r--lib_test.go3
-rw-r--r--picture.go11
-rw-r--r--picture_test.go5
-rw-r--r--rows_test.go2
-rw-r--r--stream.go2
-rw-r--r--xmlStyles.go21
-rw-r--r--xmlTheme.go6
-rw-r--r--xmlWorkbook.go8
-rw-r--r--xmlWorksheet.go66
10 files changed, 59 insertions, 67 deletions
diff --git a/drawing.go b/drawing.go
index 3ce1282..5e5bba9 100644
--- a/drawing.go
+++ b/drawing.go
@@ -1001,8 +1001,6 @@ func (f *File) drawPlotAreaValAx(formatSet *formatChart) []*cAxs {
max = nil
}
var logBase *attrValFloat
- // Follow OOXML requirements on
- // [https://github.com/sc34wg4/OOXMLSchemas/blob/2b074ca2c5df38b18ac118646b329b508b5bdecc/Part1/OfficeOpenXML-XMLSchema-Strict/dml-chart.xsd#L1142-L1147]
if formatSet.YAxis.LogBase >= 2 && formatSet.YAxis.LogBase <= 1000 {
logBase = &attrValFloat{Val: float64Ptr(formatSet.YAxis.LogBase)}
}
diff --git a/lib_test.go b/lib_test.go
index 229412c..e4ccdcc 100644
--- a/lib_test.go
+++ b/lib_test.go
@@ -95,6 +95,9 @@ func TestColumnNumberToName_Error(t *testing.T) {
if assert.Error(t, err) {
assert.Equal(t, "", out)
}
+
+ _, err = ColumnNumberToName(TotalColumns + 1)
+ assert.EqualError(t, err, "column number exceeds maximum limit")
}
func TestSplitCellName_OK(t *testing.T) {
diff --git a/picture.go b/picture.go
index 0e9e3bb..c7f6e27 100644
--- a/picture.go
+++ b/picture.go
@@ -549,11 +549,12 @@ func (f *File) getPictureFromWsDr(row, col int, drawingRelationships string, wsD
for _, anchor = range wsDr.TwoCellAnchor {
if anchor.From != nil && anchor.Pic != nil {
if anchor.From.Col == col && anchor.From.Row == row {
- drawRel = f.getDrawingRelationships(drawingRelationships,
- anchor.Pic.BlipFill.Blip.Embed)
- if _, ok = supportImageTypes[filepath.Ext(drawRel.Target)]; ok {
- ret, buf = filepath.Base(drawRel.Target), f.XLSX[strings.Replace(drawRel.Target, "..", "xl", -1)]
- return
+ if drawRel = f.getDrawingRelationships(drawingRelationships,
+ anchor.Pic.BlipFill.Blip.Embed); drawRel != nil {
+ if _, ok = supportImageTypes[filepath.Ext(drawRel.Target)]; ok {
+ ret, buf = filepath.Base(drawRel.Target), f.XLSX[strings.Replace(drawRel.Target, "..", "xl", -1)]
+ return
+ }
}
}
}
diff --git a/picture_test.go b/picture_test.go
index 015d854..f6f716e 100644
--- a/picture_test.go
+++ b/picture_test.go
@@ -152,6 +152,11 @@ func TestGetPicture(t *testing.T) {
assert.NoError(t, err)
assert.Empty(t, file)
assert.Empty(t, raw)
+ f, err = prepareTestBook1()
+ assert.NoError(t, err)
+ f.XLSX["xl/drawings/drawing1.xml"] = MacintoshCyrillicCharset
+ _, _, err = f.getPicture(20, 5, "xl/drawings/drawing1.xml", "xl/drawings/_rels/drawing2.xml.rels")
+ assert.EqualError(t, err, "xml decode error: XML syntax error on line 1: invalid UTF-8")
}
func TestAddDrawingPicture(t *testing.T) {
diff --git a/rows_test.go b/rows_test.go
index fd7196d..14537eb 100644
--- a/rows_test.go
+++ b/rows_test.go
@@ -169,6 +169,8 @@ func TestSharedStringsReader(t *testing.T) {
f := NewFile()
f.XLSX["xl/sharedStrings.xml"] = MacintoshCyrillicCharset
f.sharedStringsReader()
+ si := xlsxSI{}
+ assert.EqualValues(t, "", si.String())
}
func TestRowVisibility(t *testing.T) {
diff --git a/stream.go b/stream.go
index 81dea1e..bdc0d26 100644
--- a/stream.go
+++ b/stream.go
@@ -72,7 +72,7 @@ type StreamWriter struct {
//
func (f *File) NewStreamWriter(sheet string) (*StreamWriter, error) {
sheetID := f.getSheetID(sheet)
- if sheetID == 0 {
+ if sheetID == -1 {
return nil, fmt.Errorf("sheet %s is not exist", sheet)
}
sw := &StreamWriter{
diff --git a/xmlStyles.go b/xmlStyles.go
index 07413dd..2884800 100644
--- a/xmlStyles.go
+++ b/xmlStyles.go
@@ -13,9 +13,7 @@ package excelize
import "encoding/xml"
-// xlsxStyleSheet directly maps the stylesheet element in the namespace
-// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
-// not checked it for completeness - it does as much as I need.
+// xlsxStyleSheet is the root element of the Styles part.
type xlsxStyleSheet struct {
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/spreadsheetml/2006/main styleSheet"`
NumFmts *xlsxNumFmts `xml:"numFmts,omitempty"`
@@ -55,9 +53,7 @@ type xlsxProtection struct {
Locked bool `xml:"locked,attr"`
}
-// xlsxLine directly maps the line style element in the namespace
-// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
-// not checked it for completeness - it does as much as I need.
+// xlsxLine expresses a single set of cell border.
type xlsxLine struct {
Style string `xml:"style,attr,omitempty"`
Color *xlsxColor `xml:"color,omitempty"`
@@ -119,13 +115,10 @@ type xlsxFill struct {
GradientFill *xlsxGradientFill `xml:"gradientFill,omitempty"`
}
-// xlsxPatternFill directly maps the patternFill element in the namespace
-// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
-// not checked it for completeness - it does as much as I need. This element is
-// used to specify cell fill information for pattern and solid color cell fills.
-// For solid cell fills (no pattern), fgColor is used. For cell fills with
-// patterns specified, then the cell fill color is specified by the bgColor
-// element.
+// xlsxPatternFill is used to specify cell fill information for pattern and
+// solid color cell fills. For solid cell fills (no pattern), fgColor is used.
+// For cell fills with patterns specified, then the cell fill color is
+// specified by the bgColor element.
type xlsxPatternFill struct {
PatternType string `xml:"patternType,attr,omitempty"`
FgColor xlsxColor `xml:"fgColor,omitempty"`
@@ -303,7 +296,7 @@ type xlsxNumFmts struct {
// format properties which indicate how to format and render the numeric value
// of a cell.
type xlsxNumFmt struct {
- NumFmtID int `xml:"numFmtId,attr,omitempty"`
+ NumFmtID int `xml:"numFmtId,attr"`
FormatCode string `xml:"formatCode,attr,omitempty"`
}
diff --git a/xmlTheme.go b/xmlTheme.go
index 2f181e2..e3588dc 100644
--- a/xmlTheme.go
+++ b/xmlTheme.go
@@ -123,9 +123,9 @@ type xlsxBgFillStyleLst struct {
BgFillStyleLst string `xml:",innerxml"`
}
-// xlsxClrScheme maps to children of the clrScheme element in the namespace
-// http://schemas.openxmlformats.org/drawingml/2006/main - currently I have
-// not checked it for completeness - it does as much as I need.
+// xlsxClrScheme specifies the theme color, stored in the document's Theme
+// part to which the value of this theme color shall be mapped. This mapping
+// enables multiple theme colors to be chained together.
type xlsxClrSchemeEl struct {
XMLName xml.Name
SysClr *xlsxSysClr `xml:"sysClr"`
diff --git a/xmlWorkbook.go b/xmlWorkbook.go
index 733eb57..89cacd9 100644
--- a/xmlWorkbook.go
+++ b/xmlWorkbook.go
@@ -27,9 +27,9 @@ type xlsxRelationship struct {
TargetMode string `xml:",attr,omitempty"`
}
-// xlsxWorkbook directly maps the workbook element from the namespace
-// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
-// not checked it for completeness - it does as much as I need.
+// xlsxWorkbook contains elements and attributes that encompass the data
+// content of the workbook. The workbook's child elements each have their own
+// subclause references.
type xlsxWorkbook struct {
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/spreadsheetml/2006/main workbook"`
FileVersion *xlsxFileVersion `xml:"fileVersion"`
@@ -153,7 +153,7 @@ type xlsxSheets struct {
type xlsxSheet struct {
Name string `xml:"name,attr,omitempty"`
SheetID int `xml:"sheetId,attr,omitempty"`
- ID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
+ ID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr"`
State string `xml:"state,attr,omitempty"`
}
diff --git a/xmlWorksheet.go b/xmlWorksheet.go
index 03b1a71..7cd73c4 100644
--- a/xmlWorksheet.go
+++ b/xmlWorksheet.go
@@ -165,25 +165,20 @@ type xlsxSheetFormatPr struct {
OutlineLevelCol uint8 `xml:"outlineLevelCol,attr,omitempty"`
}
-// xlsxSheetViews directly maps the sheetViews element in the namespace
-// http://schemas.openxmlformats.org/spreadsheetml/2006/main - Worksheet views
-// collection.
+// xlsxSheetViews represents worksheet views collection.
type xlsxSheetViews struct {
XMLName xml.Name `xml:"sheetViews"`
SheetView []xlsxSheetView `xml:"sheetView"`
}
-// xlsxSheetView directly maps the sheetView element in the namespace
-// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
-// not checked it for completeness - it does as much as I need. A single sheet
-// view definition. When more than one sheet view is defined in the file, it
-// means that when opening the workbook, each sheet view corresponds to a
-// separate window within the spreadsheet application, where each window is
-// showing the particular sheet containing the same workbookViewId value, the
-// last sheetView definition is loaded, and the others are discarded. When
-// multiple windows are viewing the same sheet, multiple sheetView elements
-// (with corresponding workbookView entries) are saved.
-// See https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.sheetview
+// xlsxSheetView represents a single sheet view definition. When more than one
+// sheet view is defined in the file, it means that when opening the workbook,
+// each sheet view corresponds to a separate window within the spreadsheet
+// application, where each window is showing the particular sheet containing
+// the same workbookViewId value, the last sheetView definition is loaded, and
+// the others are discarded. When multiple windows are viewing the same sheet,
+// multiple sheetView elements (with corresponding workbookView entries) are
+// saved.
type xlsxSheetView struct {
WindowProtection bool `xml:"windowProtection,attr,omitempty"`
ShowFormulas bool `xml:"showFormulas,attr,omitempty"`
@@ -245,31 +240,27 @@ type xlsxSheetPr struct {
PageSetUpPr *xlsxPageSetUpPr `xml:"pageSetUpPr,omitempty"`
}
-// xlsxOutlinePr maps to the outlinePr element
-// SummaryBelow allows you to adjust the direction of grouper controls
+// xlsxOutlinePr maps to the outlinePr element. SummaryBelow allows you to
+// adjust the direction of grouper controls.
type xlsxOutlinePr struct {
SummaryBelow bool `xml:"summaryBelow,attr"`
}
-// xlsxPageSetUpPr directly maps the pageSetupPr element in the namespace
-// http://schemas.openxmlformats.org/spreadsheetml/2006/main - Page setup
-// properties of the worksheet.
+// xlsxPageSetUpPr expresses page setup properties of the worksheet.
type xlsxPageSetUpPr struct {
AutoPageBreaks bool `xml:"autoPageBreaks,attr,omitempty"`
- FitToPage bool `xml:"fitToPage,attr,omitempty"` // Flag indicating whether the Fit to Page print option is enabled.
+ FitToPage bool `xml:"fitToPage,attr,omitempty"`
}
-// xlsxTabColor directly maps the tabColor element in the namespace currently I
-// have not checked it for completeness - it does as much as I need.
+// xlsxTabColor represents background color of the sheet tab.
type xlsxTabColor struct {
RGB string `xml:"rgb,attr,omitempty"`
Theme int `xml:"theme,attr,omitempty"`
Tint float64 `xml:"tint,attr,omitempty"`
}
-// xlsxCols directly maps the cols element in the namespace
-// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
-// not checked it for completeness - it does as much as I need.
+// xlsxCols defines column width and column formatting for one or more columns
+// of the worksheet.
type xlsxCols struct {
XMLName xml.Name `xml:"cols"`
Col []xlsxCol `xml:"col"`
@@ -293,18 +284,18 @@ type xlsxCol struct {
// xlsxDimension directly maps the dimension element in the namespace
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - This element
// specifies the used range of the worksheet. It specifies the row and column
-// bounds of used cells in the worksheet. This is optional and is not required.
-// Used cells include cells with formulas, text content, and cell formatting.
-// When an entire column is formatted, only the first cell in that column is
-// considered used.
+// bounds of used cells in the worksheet. This is optional and is not
+// required. Used cells include cells with formulas, text content, and cell
+// formatting. When an entire column is formatted, only the first cell in that
+// column is considered used.
type xlsxDimension struct {
XMLName xml.Name `xml:"dimension"`
Ref string `xml:"ref,attr"`
}
-// xlsxSheetData directly maps the sheetData element in the namespace
-// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
-// not checked it for completeness - it does as much as I need.
+// xlsxSheetData collection represents the cell table itself. This collection
+// expresses information about each cell, grouped together by rows in the
+// worksheet.
type xlsxSheetData struct {
XMLName xml.Name `xml:"sheetData"`
Row []xlsxRow `xml:"row"`
@@ -440,9 +431,9 @@ type DataValidation struct {
Formula2 string `xml:",innerxml"`
}
-// xlsxC directly maps the c element in the namespace
-// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
-// not checked it for completeness - it does as much as I need.
+// xlsxC collection represents a cell in the worksheet. Information about the
+// cell's location (reference), value, data type, formatting, and formula is
+// expressed here.
//
// This simple type is restricted to the values listed in the following table:
//
@@ -472,9 +463,8 @@ func (c *xlsxC) hasValue() bool {
return c.S != 0 || c.V != "" || c.F != nil || c.T != ""
}
-// xlsxF directly maps the f element in the namespace
-// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
-// not checked it for completeness - it does as much as I need.
+// xlsxF represents a formula for the cell. The formula expression is
+// contained in the character node of this element.
type xlsxF struct {
Content string `xml:",chardata"`
T string `xml:"t,attr,omitempty"` // Formula type