From ca43c6511538f50581ec3bbe1e4ee275444f8049 Mon Sep 17 00:00:00 2001 From: xuri Date: Sun, 19 Jul 2020 00:10:42 +0800 Subject: [PATCH] Update test for addTable --- lib.go | 5 +---- table.go | 10 ++-------- table_test.go | 6 ++++++ xmlDrawing.go | 8 ++++---- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/lib.go b/lib.go index 6dcd97e..0efb074 100644 --- a/lib.go +++ b/lib.go @@ -396,10 +396,7 @@ func (f *File) addNameSpaces(path string, ns xml.Attr) { if !exist { f.xmlAttr[path] = append(f.xmlAttr[path], ns) if !mc { - f.xmlAttr[path] = append(f.xmlAttr[path], xml.Attr{ - Name: xml.Name{Local: "mc", Space: "xmlns"}, - Value: SourceRelationshipCompatibility, - }) + f.xmlAttr[path] = append(f.xmlAttr[path], SourceRelationshipCompatibility) } if !ignore { f.xmlAttr[path] = append(f.xmlAttr[path], xml.Attr{ diff --git a/table.go b/table.go index e26bbe2..64c87b1 100644 --- a/table.go +++ b/table.go @@ -287,14 +287,8 @@ func (f *File) AutoFilter(sheet, hcell, vcell, format string) error { } formatSet, _ := parseAutoFilterSet(format) - - var cellStart, cellEnd string - if cellStart, err = CoordinatesToCellName(hcol, hrow); err != nil { - return err - } - if cellEnd, err = CoordinatesToCellName(vcol, vrow); err != nil { - return err - } + cellStart, _ := CoordinatesToCellName(hcol, hrow) + cellEnd, _ := CoordinatesToCellName(vcol, vrow) ref, filterDB := cellStart+":"+cellEnd, "_xlnm._FilterDatabase" wb := f.workbookReader() sheetID := f.GetSheetIndex(sheet) diff --git a/table_test.go b/table_test.go index 127ee1b..95738e1 100644 --- a/table_test.go +++ b/table_test.go @@ -29,6 +29,8 @@ func TestAddTable(t *testing.T) { t.FailNow() } + // Test add table in not exist worksheet. + assert.EqualError(t, f.AddTable("SheetN", "B26", "A21", `{}`), "sheet SheetN is not exist") // Test add table with illegal formatset. assert.EqualError(t, f.AddTable("Sheet1", "B26", "A21", `{x}`), "invalid character 'x' looking for beginning of object key string") // Test add table with illegal cell coordinates. @@ -100,6 +102,10 @@ func TestAutoFilterError(t *testing.T) { }) } + assert.EqualError(t, f.autoFilter("SheetN", "A1", 1, 1, &formatAutoFilter{ + Column: "A", + Expression: "", + }), "sheet SheetN is not exist") assert.EqualError(t, f.autoFilter("Sheet1", "A1", 1, 1, &formatAutoFilter{ Column: "-", Expression: "-", diff --git a/xmlDrawing.go b/xmlDrawing.go index 24df0fa..64d2bc5 100644 --- a/xmlDrawing.go +++ b/xmlDrawing.go @@ -15,9 +15,10 @@ import "encoding/xml" // Source relationship and namespace. var ( - SourceRelationship = xml.Attr{Name: xml.Name{Local: "r", Space: "xmlns"}, Value: "http://schemas.openxmlformats.org/officeDocument/2006/relationships"} - NameSpaceSpreadSheet = xml.Attr{Name: xml.Name{Local: "xmlns"}, Value: "http://schemas.openxmlformats.org/spreadsheetml/2006/main"} - NameSpaceSpreadSheetX14 = xml.Attr{Name: xml.Name{Local: "x14", Space: "xmlns"}, Value: "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"} + SourceRelationship = xml.Attr{Name: xml.Name{Local: "r", Space: "xmlns"}, Value: "http://schemas.openxmlformats.org/officeDocument/2006/relationships"} + SourceRelationshipCompatibility = xml.Attr{Name: xml.Name{Local: "mc", Space: "xmlns"}, Value: "http://schemas.openxmlformats.org/markup-compatibility/2006"} + NameSpaceSpreadSheet = xml.Attr{Name: xml.Name{Local: "xmlns"}, Value: "http://schemas.openxmlformats.org/spreadsheetml/2006/main"} + NameSpaceSpreadSheetX14 = xml.Attr{Name: xml.Name{Local: "x14", Space: "xmlns"}, Value: "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"} ) // Source relationship and namespace. @@ -39,7 +40,6 @@ const ( SourceRelationshipChart201506 = "http://schemas.microsoft.com/office/drawing/2015/06/chart" SourceRelationshipChart20070802 = "http://schemas.microsoft.com/office/drawing/2007/8/2/chart" SourceRelationshipChart2014 = "http://schemas.microsoft.com/office/drawing/2014/chart" - SourceRelationshipCompatibility = "http://schemas.openxmlformats.org/markup-compatibility/2006" NameSpaceDrawingML = "http://schemas.openxmlformats.org/drawingml/2006/main" NameSpaceDrawingMLChart = "http://schemas.openxmlformats.org/drawingml/2006/chart" NameSpaceDrawingMLSpreadSheet = "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing"