Skip to content

Commit ca43c65

Browse files
committed
Update test for addTable
1 parent c922c32 commit ca43c65

File tree

4 files changed

+13
-16
lines changed

4 files changed

+13
-16
lines changed

lib.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -396,10 +396,7 @@ func (f *File) addNameSpaces(path string, ns xml.Attr) {
396396
if !exist {
397397
f.xmlAttr[path] = append(f.xmlAttr[path], ns)
398398
if !mc {
399-
f.xmlAttr[path] = append(f.xmlAttr[path], xml.Attr{
400-
Name: xml.Name{Local: "mc", Space: "xmlns"},
401-
Value: SourceRelationshipCompatibility,
402-
})
399+
f.xmlAttr[path] = append(f.xmlAttr[path], SourceRelationshipCompatibility)
403400
}
404401
if !ignore {
405402
f.xmlAttr[path] = append(f.xmlAttr[path], xml.Attr{

table.go

+2-8
Original file line numberDiff line numberDiff line change
@@ -287,14 +287,8 @@ func (f *File) AutoFilter(sheet, hcell, vcell, format string) error {
287287
}
288288

289289
formatSet, _ := parseAutoFilterSet(format)
290-
291-
var cellStart, cellEnd string
292-
if cellStart, err = CoordinatesToCellName(hcol, hrow); err != nil {
293-
return err
294-
}
295-
if cellEnd, err = CoordinatesToCellName(vcol, vrow); err != nil {
296-
return err
297-
}
290+
cellStart, _ := CoordinatesToCellName(hcol, hrow)
291+
cellEnd, _ := CoordinatesToCellName(vcol, vrow)
298292
ref, filterDB := cellStart+":"+cellEnd, "_xlnm._FilterDatabase"
299293
wb := f.workbookReader()
300294
sheetID := f.GetSheetIndex(sheet)

table_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ func TestAddTable(t *testing.T) {
2929
t.FailNow()
3030
}
3131

32+
// Test add table in not exist worksheet.
33+
assert.EqualError(t, f.AddTable("SheetN", "B26", "A21", `{}`), "sheet SheetN is not exist")
3234
// Test add table with illegal formatset.
3335
assert.EqualError(t, f.AddTable("Sheet1", "B26", "A21", `{x}`), "invalid character 'x' looking for beginning of object key string")
3436
// Test add table with illegal cell coordinates.
@@ -100,6 +102,10 @@ func TestAutoFilterError(t *testing.T) {
100102
})
101103
}
102104

105+
assert.EqualError(t, f.autoFilter("SheetN", "A1", 1, 1, &formatAutoFilter{
106+
Column: "A",
107+
Expression: "",
108+
}), "sheet SheetN is not exist")
103109
assert.EqualError(t, f.autoFilter("Sheet1", "A1", 1, 1, &formatAutoFilter{
104110
Column: "-",
105111
Expression: "-",

xmlDrawing.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ import "encoding/xml"
1515

1616
// Source relationship and namespace.
1717
var (
18-
SourceRelationship = xml.Attr{Name: xml.Name{Local: "r", Space: "xmlns"}, Value: "http://schemas.openxmlformats.org/officeDocument/2006/relationships"}
19-
NameSpaceSpreadSheet = xml.Attr{Name: xml.Name{Local: "xmlns"}, Value: "http://schemas.openxmlformats.org/spreadsheetml/2006/main"}
20-
NameSpaceSpreadSheetX14 = xml.Attr{Name: xml.Name{Local: "x14", Space: "xmlns"}, Value: "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"}
18+
SourceRelationship = xml.Attr{Name: xml.Name{Local: "r", Space: "xmlns"}, Value: "http://schemas.openxmlformats.org/officeDocument/2006/relationships"}
19+
SourceRelationshipCompatibility = xml.Attr{Name: xml.Name{Local: "mc", Space: "xmlns"}, Value: "http://schemas.openxmlformats.org/markup-compatibility/2006"}
20+
NameSpaceSpreadSheet = xml.Attr{Name: xml.Name{Local: "xmlns"}, Value: "http://schemas.openxmlformats.org/spreadsheetml/2006/main"}
21+
NameSpaceSpreadSheetX14 = xml.Attr{Name: xml.Name{Local: "x14", Space: "xmlns"}, Value: "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"}
2122
)
2223

2324
// Source relationship and namespace.
@@ -39,7 +40,6 @@ const (
3940
SourceRelationshipChart201506 = "http://schemas.microsoft.com/office/drawing/2015/06/chart"
4041
SourceRelationshipChart20070802 = "http://schemas.microsoft.com/office/drawing/2007/8/2/chart"
4142
SourceRelationshipChart2014 = "http://schemas.microsoft.com/office/drawing/2014/chart"
42-
SourceRelationshipCompatibility = "http://schemas.openxmlformats.org/markup-compatibility/2006"
4343
NameSpaceDrawingML = "http://schemas.openxmlformats.org/drawingml/2006/main"
4444
NameSpaceDrawingMLChart = "http://schemas.openxmlformats.org/drawingml/2006/chart"
4545
NameSpaceDrawingMLSpreadSheet = "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing"

0 commit comments

Comments
 (0)