Skip to content

Commit acd9e68

Browse files
add item err
1 parent c2dd50b commit acd9e68

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

slicer_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,24 @@ func TestSlicer(t *testing.T) {
218218
}), "XML syntax error on line 1: invalid UTF-8")
219219
assert.NoError(t, f.Close())
220220

221+
// Test add a pivot table slicer with invalid pivot cache XML content to trigger buildSlicerItems error
222+
f, err = OpenFile(workbookPath)
223+
assert.NoError(t, err)
224+
pivotTables, err := f.GetPivotTables("Sheet2")
225+
assert.NoError(t, err)
226+
assert.NotEmpty(t, pivotTables)
227+
f.Pkg.Store(pivotTables[0].pivotCacheXML, []byte("<!DOCTYPE html><html><body>Not actually XML</body></html>"))
228+
err = f.AddSlicer("Sheet2", &SlicerOptions{
229+
Name: "Month",
230+
Cell: "S42",
231+
TableSheet: "Sheet2",
232+
TableName: "PivotTable1",
233+
Caption: "Test Invalid XML",
234+
})
235+
assert.Error(t, err)
236+
assert.Contains(t, err.Error(), "pivotCacheDefinition")
237+
assert.NoError(t, f.Close())
238+
221239
// Test open a workbook and get already exist slicers
222240
f, err = OpenFile(workbookPath)
223241
assert.NoError(t, err)

0 commit comments

Comments
 (0)