@@ -300,6 +300,7 @@ func TestPivotTable(t *testing.T) {
300
300
assert .EqualError (t , err , `parameter 'DataRange' parsing error: parameter is required` )
301
301
// Test add pivot table with unsupported charset content types.
302
302
f = NewFile ()
303
+ assert .NoError (t , f .SetSheetRow ("Sheet1" , "A1" , & []string {"Month" , "Year" , "Type" , "Sales" , "Region" }))
303
304
f .ContentTypes = nil
304
305
f .Pkg .Store (defaultXMLPathContentTypes , MacintoshCyrillicCharset )
305
306
assert .EqualError (t , f .AddPivotTable (& PivotTableOptions {
@@ -393,6 +394,25 @@ func TestPivotTableDataRange(t *testing.T) {
393
394
f .Relationships .Delete ("xl/worksheets/_rels/sheet1.xml.rels" )
394
395
f .Pkg .Delete ("xl/worksheets/_rels/sheet1.xml.rels" )
395
396
assert .EqualError (t , f .DeletePivotTable ("Sheet1" , "PivotTable1" ), "table PivotTable1 does not exist" )
397
+
398
+ t .Run ("data_range_with_empty_column" , func (t * testing.T ) {
399
+ // Test add pivot table with data range doesn't organized as a list with labeled columns
400
+ f := NewFile ()
401
+ // Create some data in a sheet
402
+ month := []string {"Jan" , "Feb" , "Mar" , "Apr" , "May" , "Jun" , "Jul" , "Aug" , "Sep" , "Oct" , "Nov" , "Dec" }
403
+ types := []string {"Meat" , "Dairy" , "Beverages" , "Produce" }
404
+ assert .NoError (t , f .SetSheetRow ("Sheet1" , "A1" , & []string {"Month" , "" , "Type" }))
405
+ for row := 2 ; row < 32 ; row ++ {
406
+ assert .NoError (t , f .SetCellValue ("Sheet1" , fmt .Sprintf ("A%d" , row ), month [rand .Intn (12 )]))
407
+ assert .NoError (t , f .SetCellValue ("Sheet1" , fmt .Sprintf ("C%d" , row ), types [rand .Intn (4 )]))
408
+ }
409
+ assert .Equal (t , newPivotTableDataRangeError ("parameter is invalid" ), f .AddPivotTable (& PivotTableOptions {
410
+ DataRange : "Sheet1!A1:E31" ,
411
+ PivotTableRange : "Sheet1!G2:M34" ,
412
+ Rows : []PivotTableField {{Data : "Month" , DefaultSubtotal : true }},
413
+ Data : []PivotTableField {{Data : "Type" }},
414
+ }))
415
+ })
396
416
}
397
417
398
418
func TestParseFormatPivotTableSet (t * testing.T ) {
0 commit comments