Skip to content

Commit 0aa1510

Browse files
committed
update docs and improve compatibility
1 parent 42b1c81 commit 0aa1510

File tree

10 files changed

+59
-67
lines changed

10 files changed

+59
-67
lines changed

drawing.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,8 +1001,6 @@ func (f *File) drawPlotAreaValAx(formatSet *formatChart) []*cAxs {
10011001
max = nil
10021002
}
10031003
var logBase *attrValFloat
1004-
// Follow OOXML requirements on
1005-
// [https://github.com/sc34wg4/OOXMLSchemas/blob/2b074ca2c5df38b18ac118646b329b508b5bdecc/Part1/OfficeOpenXML-XMLSchema-Strict/dml-chart.xsd#L1142-L1147]
10061004
if formatSet.YAxis.LogBase >= 2 && formatSet.YAxis.LogBase <= 1000 {
10071005
logBase = &attrValFloat{Val: float64Ptr(formatSet.YAxis.LogBase)}
10081006
}

lib_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ func TestColumnNumberToName_Error(t *testing.T) {
9595
if assert.Error(t, err) {
9696
assert.Equal(t, "", out)
9797
}
98+
99+
_, err = ColumnNumberToName(TotalColumns + 1)
100+
assert.EqualError(t, err, "column number exceeds maximum limit")
98101
}
99102

100103
func TestSplitCellName_OK(t *testing.T) {

picture.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -549,11 +549,12 @@ func (f *File) getPictureFromWsDr(row, col int, drawingRelationships string, wsD
549549
for _, anchor = range wsDr.TwoCellAnchor {
550550
if anchor.From != nil && anchor.Pic != nil {
551551
if anchor.From.Col == col && anchor.From.Row == row {
552-
drawRel = f.getDrawingRelationships(drawingRelationships,
553-
anchor.Pic.BlipFill.Blip.Embed)
554-
if _, ok = supportImageTypes[filepath.Ext(drawRel.Target)]; ok {
555-
ret, buf = filepath.Base(drawRel.Target), f.XLSX[strings.Replace(drawRel.Target, "..", "xl", -1)]
556-
return
552+
if drawRel = f.getDrawingRelationships(drawingRelationships,
553+
anchor.Pic.BlipFill.Blip.Embed); drawRel != nil {
554+
if _, ok = supportImageTypes[filepath.Ext(drawRel.Target)]; ok {
555+
ret, buf = filepath.Base(drawRel.Target), f.XLSX[strings.Replace(drawRel.Target, "..", "xl", -1)]
556+
return
557+
}
557558
}
558559
}
559560
}

picture_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ func TestGetPicture(t *testing.T) {
152152
assert.NoError(t, err)
153153
assert.Empty(t, file)
154154
assert.Empty(t, raw)
155+
f, err = prepareTestBook1()
156+
assert.NoError(t, err)
157+
f.XLSX["xl/drawings/drawing1.xml"] = MacintoshCyrillicCharset
158+
_, _, err = f.getPicture(20, 5, "xl/drawings/drawing1.xml", "xl/drawings/_rels/drawing2.xml.rels")
159+
assert.EqualError(t, err, "xml decode error: XML syntax error on line 1: invalid UTF-8")
155160
}
156161

157162
func TestAddDrawingPicture(t *testing.T) {

rows_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ func TestSharedStringsReader(t *testing.T) {
169169
f := NewFile()
170170
f.XLSX["xl/sharedStrings.xml"] = MacintoshCyrillicCharset
171171
f.sharedStringsReader()
172+
si := xlsxSI{}
173+
assert.EqualValues(t, "", si.String())
172174
}
173175

174176
func TestRowVisibility(t *testing.T) {

stream.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ type StreamWriter struct {
7272
//
7373
func (f *File) NewStreamWriter(sheet string) (*StreamWriter, error) {
7474
sheetID := f.getSheetID(sheet)
75-
if sheetID == 0 {
75+
if sheetID == -1 {
7676
return nil, fmt.Errorf("sheet %s is not exist", sheet)
7777
}
7878
sw := &StreamWriter{

xmlStyles.go

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ package excelize
1313

1414
import "encoding/xml"
1515

16-
// xlsxStyleSheet directly maps the stylesheet element in the namespace
17-
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
18-
// not checked it for completeness - it does as much as I need.
16+
// xlsxStyleSheet is the root element of the Styles part.
1917
type xlsxStyleSheet struct {
2018
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/spreadsheetml/2006/main styleSheet"`
2119
NumFmts *xlsxNumFmts `xml:"numFmts,omitempty"`
@@ -55,9 +53,7 @@ type xlsxProtection struct {
5553
Locked bool `xml:"locked,attr"`
5654
}
5755

58-
// xlsxLine directly maps the line style element in the namespace
59-
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
60-
// not checked it for completeness - it does as much as I need.
56+
// xlsxLine expresses a single set of cell border.
6157
type xlsxLine struct {
6258
Style string `xml:"style,attr,omitempty"`
6359
Color *xlsxColor `xml:"color,omitempty"`
@@ -119,13 +115,10 @@ type xlsxFill struct {
119115
GradientFill *xlsxGradientFill `xml:"gradientFill,omitempty"`
120116
}
121117

122-
// xlsxPatternFill directly maps the patternFill element in the namespace
123-
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
124-
// not checked it for completeness - it does as much as I need. This element is
125-
// used to specify cell fill information for pattern and solid color cell fills.
126-
// For solid cell fills (no pattern), fgColor is used. For cell fills with
127-
// patterns specified, then the cell fill color is specified by the bgColor
128-
// element.
118+
// xlsxPatternFill is used to specify cell fill information for pattern and
119+
// solid color cell fills. For solid cell fills (no pattern), fgColor is used.
120+
// For cell fills with patterns specified, then the cell fill color is
121+
// specified by the bgColor element.
129122
type xlsxPatternFill struct {
130123
PatternType string `xml:"patternType,attr,omitempty"`
131124
FgColor xlsxColor `xml:"fgColor,omitempty"`
@@ -303,7 +296,7 @@ type xlsxNumFmts struct {
303296
// format properties which indicate how to format and render the numeric value
304297
// of a cell.
305298
type xlsxNumFmt struct {
306-
NumFmtID int `xml:"numFmtId,attr,omitempty"`
299+
NumFmtID int `xml:"numFmtId,attr"`
307300
FormatCode string `xml:"formatCode,attr,omitempty"`
308301
}
309302

xmlTheme.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ type xlsxBgFillStyleLst struct {
123123
BgFillStyleLst string `xml:",innerxml"`
124124
}
125125

126-
// xlsxClrScheme maps to children of the clrScheme element in the namespace
127-
// http://schemas.openxmlformats.org/drawingml/2006/main - currently I have
128-
// not checked it for completeness - it does as much as I need.
126+
// xlsxClrScheme specifies the theme color, stored in the document's Theme
127+
// part to which the value of this theme color shall be mapped. This mapping
128+
// enables multiple theme colors to be chained together.
129129
type xlsxClrSchemeEl struct {
130130
XMLName xml.Name
131131
SysClr *xlsxSysClr `xml:"sysClr"`

xmlWorkbook.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ type xlsxRelationship struct {
2727
TargetMode string `xml:",attr,omitempty"`
2828
}
2929

30-
// xlsxWorkbook directly maps the workbook element from the namespace
31-
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
32-
// not checked it for completeness - it does as much as I need.
30+
// xlsxWorkbook contains elements and attributes that encompass the data
31+
// content of the workbook. The workbook's child elements each have their own
32+
// subclause references.
3333
type xlsxWorkbook struct {
3434
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/spreadsheetml/2006/main workbook"`
3535
FileVersion *xlsxFileVersion `xml:"fileVersion"`
@@ -153,7 +153,7 @@ type xlsxSheets struct {
153153
type xlsxSheet struct {
154154
Name string `xml:"name,attr,omitempty"`
155155
SheetID int `xml:"sheetId,attr,omitempty"`
156-
ID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"`
156+
ID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr"`
157157
State string `xml:"state,attr,omitempty"`
158158
}
159159

xmlWorksheet.go

Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -165,25 +165,20 @@ type xlsxSheetFormatPr struct {
165165
OutlineLevelCol uint8 `xml:"outlineLevelCol,attr,omitempty"`
166166
}
167167

168-
// xlsxSheetViews directly maps the sheetViews element in the namespace
169-
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - Worksheet views
170-
// collection.
168+
// xlsxSheetViews represents worksheet views collection.
171169
type xlsxSheetViews struct {
172170
XMLName xml.Name `xml:"sheetViews"`
173171
SheetView []xlsxSheetView `xml:"sheetView"`
174172
}
175173

176-
// xlsxSheetView directly maps the sheetView element in the namespace
177-
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
178-
// not checked it for completeness - it does as much as I need. A single sheet
179-
// view definition. When more than one sheet view is defined in the file, it
180-
// means that when opening the workbook, each sheet view corresponds to a
181-
// separate window within the spreadsheet application, where each window is
182-
// showing the particular sheet containing the same workbookViewId value, the
183-
// last sheetView definition is loaded, and the others are discarded. When
184-
// multiple windows are viewing the same sheet, multiple sheetView elements
185-
// (with corresponding workbookView entries) are saved.
186-
// See https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.sheetview
174+
// xlsxSheetView represents a single sheet view definition. When more than one
175+
// sheet view is defined in the file, it means that when opening the workbook,
176+
// each sheet view corresponds to a separate window within the spreadsheet
177+
// application, where each window is showing the particular sheet containing
178+
// the same workbookViewId value, the last sheetView definition is loaded, and
179+
// the others are discarded. When multiple windows are viewing the same sheet,
180+
// multiple sheetView elements (with corresponding workbookView entries) are
181+
// saved.
187182
type xlsxSheetView struct {
188183
WindowProtection bool `xml:"windowProtection,attr,omitempty"`
189184
ShowFormulas bool `xml:"showFormulas,attr,omitempty"`
@@ -245,31 +240,27 @@ type xlsxSheetPr struct {
245240
PageSetUpPr *xlsxPageSetUpPr `xml:"pageSetUpPr,omitempty"`
246241
}
247242

248-
// xlsxOutlinePr maps to the outlinePr element
249-
// SummaryBelow allows you to adjust the direction of grouper controls
243+
// xlsxOutlinePr maps to the outlinePr element. SummaryBelow allows you to
244+
// adjust the direction of grouper controls.
250245
type xlsxOutlinePr struct {
251246
SummaryBelow bool `xml:"summaryBelow,attr"`
252247
}
253248

254-
// xlsxPageSetUpPr directly maps the pageSetupPr element in the namespace
255-
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - Page setup
256-
// properties of the worksheet.
249+
// xlsxPageSetUpPr expresses page setup properties of the worksheet.
257250
type xlsxPageSetUpPr struct {
258251
AutoPageBreaks bool `xml:"autoPageBreaks,attr,omitempty"`
259-
FitToPage bool `xml:"fitToPage,attr,omitempty"` // Flag indicating whether the Fit to Page print option is enabled.
252+
FitToPage bool `xml:"fitToPage,attr,omitempty"`
260253
}
261254

262-
// xlsxTabColor directly maps the tabColor element in the namespace currently I
263-
// have not checked it for completeness - it does as much as I need.
255+
// xlsxTabColor represents background color of the sheet tab.
264256
type xlsxTabColor struct {
265257
RGB string `xml:"rgb,attr,omitempty"`
266258
Theme int `xml:"theme,attr,omitempty"`
267259
Tint float64 `xml:"tint,attr,omitempty"`
268260
}
269261

270-
// xlsxCols directly maps the cols element in the namespace
271-
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
272-
// not checked it for completeness - it does as much as I need.
262+
// xlsxCols defines column width and column formatting for one or more columns
263+
// of the worksheet.
273264
type xlsxCols struct {
274265
XMLName xml.Name `xml:"cols"`
275266
Col []xlsxCol `xml:"col"`
@@ -293,18 +284,18 @@ type xlsxCol struct {
293284
// xlsxDimension directly maps the dimension element in the namespace
294285
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - This element
295286
// specifies the used range of the worksheet. It specifies the row and column
296-
// bounds of used cells in the worksheet. This is optional and is not required.
297-
// Used cells include cells with formulas, text content, and cell formatting.
298-
// When an entire column is formatted, only the first cell in that column is
299-
// considered used.
287+
// bounds of used cells in the worksheet. This is optional and is not
288+
// required. Used cells include cells with formulas, text content, and cell
289+
// formatting. When an entire column is formatted, only the first cell in that
290+
// column is considered used.
300291
type xlsxDimension struct {
301292
XMLName xml.Name `xml:"dimension"`
302293
Ref string `xml:"ref,attr"`
303294
}
304295

305-
// xlsxSheetData directly maps the sheetData element in the namespace
306-
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
307-
// not checked it for completeness - it does as much as I need.
296+
// xlsxSheetData collection represents the cell table itself. This collection
297+
// expresses information about each cell, grouped together by rows in the
298+
// worksheet.
308299
type xlsxSheetData struct {
309300
XMLName xml.Name `xml:"sheetData"`
310301
Row []xlsxRow `xml:"row"`
@@ -440,9 +431,9 @@ type DataValidation struct {
440431
Formula2 string `xml:",innerxml"`
441432
}
442433

443-
// xlsxC directly maps the c element in the namespace
444-
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
445-
// not checked it for completeness - it does as much as I need.
434+
// xlsxC collection represents a cell in the worksheet. Information about the
435+
// cell's location (reference), value, data type, formatting, and formula is
436+
// expressed here.
446437
//
447438
// This simple type is restricted to the values listed in the following table:
448439
//
@@ -472,9 +463,8 @@ func (c *xlsxC) hasValue() bool {
472463
return c.S != 0 || c.V != "" || c.F != nil || c.T != ""
473464
}
474465

475-
// xlsxF directly maps the f element in the namespace
476-
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
477-
// not checked it for completeness - it does as much as I need.
466+
// xlsxF represents a formula for the cell. The formula expression is
467+
// contained in the character node of this element.
478468
type xlsxF struct {
479469
Content string `xml:",chardata"`
480470
T string `xml:"t,attr,omitempty"` // Formula type

0 commit comments

Comments
 (0)