Skip to content

Commit 4ac39a8

Browse files
This closes qax-os#2161, fix panic on read unsupported pivot table cache source types (qax-os#2168)
- GetPivotTables function return error on read unsupported pivot table cache source types - Update docs for the AddChart function - Update unit tests
1 parent 55e152f commit 4ac39a8

File tree

7 files changed

+29
-9
lines changed

7 files changed

+29
-9
lines changed

chart.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -848,14 +848,16 @@ func (opts *Chart) parseTitle() {
848848
// SecondPlotValues
849849
// ShowBubbleSize
850850
// ShowCatName
851+
// ShowDataTable
852+
// ShowDataTableKeys
851853
// ShowLeaderLines
852854
// ShowPercent
853855
// ShowSerName
854856
// ShowVal
855857
// NumFmt
856858
//
857-
// SecondPlotValues: Specifies the values in second plot for the 'pieOfPie' and
858-
// 'barOfPie' chart.
859+
// SecondPlotValues: Specifies the values in second plot for the 'PieOfPie' and
860+
// 'BarOfPie' chart.
859861
//
860862
// ShowBubbleSize: Specifies the bubble size shall be shown in a data label. The
861863
// 'ShowBubbleSize' property is optional. The default value is false.

errors.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,12 @@ func newUnsupportedChartType(chartType ChartType) error {
328328
return fmt.Errorf("unsupported chart type %d", chartType)
329329
}
330330

331+
// newUnsupportedPivotCacheSourceType defined the error message on receiving the
332+
// source type of pivot table cache.
333+
func newUnsupportedPivotCacheSourceType(sourceType string) error {
334+
return fmt.Errorf("unsupported pivot table cache source type: %s", sourceType)
335+
}
336+
331337
// newUnzipSizeLimitError defined the error message on unzip size exceeds the
332338
// limit.
333339
func newUnzipSizeLimitError(unzipSizeLimit int64) error {

excelize.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ type charsetTranscoderFn func(charset string, input io.Reader) (rdr io.Reader, e
8484
// should be less than or equal to UnzipSizeLimit, the default value is
8585
// 16MB.
8686
//
87+
// TmpDir specifies the temporary directory for creating temporary files, if the
88+
// value is empty, the system default temporary directory will be used.
89+
//
8790
// ShortDatePattern specifies the short date number format code. In the
8891
// spreadsheet applications, date formats display date and time serial numbers
8992
// as date values. Date formats that begin with an asterisk (*) respond to
@@ -98,9 +101,6 @@ type charsetTranscoderFn func(charset string, input io.Reader) (rdr io.Reader, e
98101
//
99102
// CultureInfo specifies the country code for applying built-in language number
100103
// format code these effect by the system's local language settings.
101-
//
102-
// TmpDir specifies the temporary directory for creating temporary files, if the
103-
// value is empty, the system default temporary directory will be used.
104104
type Options struct {
105105
MaxCalcIterations uint
106106
Password string

pivotTable.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,9 @@ func (f *File) addWorkbookPivotCache(RID int) int {
781781
}
782782

783783
// GetPivotTables returns all pivot table definitions in a worksheet by given
784-
// worksheet name.
784+
// worksheet name. Currently only support get pivot table cache with worksheet
785+
// source type, and doesn't support source types: external, consolidation
786+
// and scenario.
785787
func (f *File) GetPivotTables(sheet string) ([]PivotTableOptions, error) {
786788
var pivotTables []PivotTableOptions
787789
name, ok := f.getSheetXMLPath(sheet)
@@ -868,6 +870,9 @@ func (f *File) getPivotTable(sheet, pivotTableXML, pivotCacheRels string) (Pivot
868870
if err != nil {
869871
return opts, err
870872
}
873+
if pc.CacheSource.WorksheetSource == nil {
874+
return opts, newUnsupportedPivotCacheSourceType(pc.CacheSource.Type)
875+
}
871876
opts = PivotTableOptions{
872877
pivotTableXML: pivotTableXML,
873878
pivotCacheXML: pivotCacheXML,

pivotTable_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,13 @@ func TestPivotTable(t *testing.T) {
356356
_, err = f.getPivotTables()
357357
assert.EqualError(t, err, "XML syntax error on line 1: invalid UTF-8")
358358
assert.NoError(t, f.Close())
359+
// Test get pivot table with unsupported pivot table cache source type
360+
f, err = OpenFile(filepath.Join("test", "TestAddPivotTable1.xlsx"))
361+
assert.NoError(t, err)
362+
f.Pkg.Store("xl/pivotCache/pivotCacheDefinition1.xml", fmt.Appendf(nil, `<pivotCacheDefinition xmlns="%s"><cacheSource type="external" connectionId="1"/></pivotCacheDefinition>`, NameSpaceSpreadSheet.Value))
363+
_, err = f.GetPivotTables("Sheet1")
364+
assert.Equal(t, err, newUnsupportedPivotCacheSourceType("external"))
365+
assert.NoError(t, f.Close())
359366
}
360367

361368
func TestPivotTableDataRange(t *testing.T) {

rows.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,8 @@ func (f *File) GetRowVisible(sheet string, row int) (bool, error) {
585585
}
586586

587587
// SetRowOutlineLevel provides a function to set outline level number of a
588-
// single row by given worksheet name and Excel row number. The value of
589-
// parameter 'level' is 1-7. For example, outline row 2 in Sheet1 to level 1:
588+
// single row by given worksheet name and row number. The range of 'level'
589+
// parameter value from 1 to 7. For example, outline row 2 in Sheet1 to level 1:
590590
//
591591
// err := f.SetRowOutlineLevel("Sheet1", 2, 1)
592592
func (f *File) SetRowOutlineLevel(sheet string, row int, level uint8) error {

sheet.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ func (f *File) getSheetRelationshipsTargetByID(sheet, rID string) string {
751751
// fmt.Println(err)
752752
// return
753753
// }
754-
// err := f.CopySheet(1, index)
754+
// err = f.CopySheet(0, index)
755755
func (f *File) CopySheet(from, to int) error {
756756
if from < 0 || to < 0 || from == to || f.GetSheetName(from) == "" || f.GetSheetName(to) == "" {
757757
return ErrSheetIdx

0 commit comments

Comments
 (0)