[]
        
(Showing Draft Content)

GC.Spread.Sheets.PivotTableManager

类: PivotTableManager

Spread.Sheets.PivotTableManager

Table of contents

构造方法

方法

构造方法

constructor

new PivotTableManager(sheet)

透视表管理器

参数

属性名 类型 说明
sheet Worksheet 表单

方法

add

add(name, sourceData, row, col, layout?, theme?, options?): PivotTable

description Add a pivot table to current worksheet.

代码示例

var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"),{sheetCount:3});
var sourceSheet = spread.getSheet(0);
var sheet = spread.getSheet(1);
var sourceData = [["Date","Buyer","Type","Amount"],
                  ["01-Jan","Mom","Fuel",74],
                  ["15-Jan","Mom","Food",235],
                  ["17-Jan","Dad","Sports",20],
                  ["21-Jan","Kelly","Books",125]];
sourceSheet.setArray(0, 0, sourceData );
sourceSheet.tables.add('sourceData', 0, 0, 5, 4);
var layout = GC.Spread.Pivot.PivotTableLayoutType.compact;
var theme = GC.Spread.Pivot.PivotTableThemes.medium2;
sheet.pivotTables.add("pivotTable_1", 'sourceData', 1, 1, layout, theme);

参数

属性名 类型 说明
name string 透视表名称,它在整个工作簿中应该是唯一的
sourceData string | any[][] 用于透视表的数据源。它支持三种类型:表名、透视表名或绝对引用范围的公式
row number 透视表起始行位置
col number 透视表起始列位置
layout? PivotTableLayoutType 透视表布局类型
theme? PivotTableTheme 透视表主题样式
options? IPivotTableOption 透视表的选项.

返回值

PivotTable

透视表实例


all

all(): PivotTable[]

description 获取当前工作表中的所有透视表

代码示例

var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"),{sheetCount:3});
var sourceSheet = spread.getSheet(0);
var sheet = spread.getSheet(1);
var sourceData = [["Date","Buyer","Type","Amount"],
                  ["01-Jan","Mom","Fuel",74],
                  ["15-Jan","Mom","Food",235],
                  ["17-Jan","Dad","Sports",20],
                  ["21-Jan","Kelly","Books",125]];
sourceSheet.setArray(0, 0, sourceData );
sourceSheet.tables.add('sourceData', 0, 0, 5, 4);
var layout = GC.Spread.Pivot.PivotTableLayoutType.compact;
var theme = GC.Spread.Pivot.PivotTableThemes.medium2;
var options = {showRowHeader: true, showColumnHeader: true};
var pivotTable = sheet.pivotTables.add("pivotTable_1", 'sourceData', 1, 1, layout, theme, options);
var pivotTables = pivotTableManager.all();
console.log(pivotTables);

返回值

PivotTable[]

返回当前工作表中的所有透视表


findPivotTable

findPivotTable(r, c): PivotTable

description 按单元格位置获取数据透视表

参数

属性名 类型 说明
r number 单元格行索引
c number 单元格列索引

返回值

PivotTable

返回透视表实例


get

get(name): PivotTable

description 按名称获取数据透视表

参数

属性名 类型 说明
name string 数据透视表名称

返回值

PivotTable

返回透视表实例


getRangePivotAreas

getRangePivotAreas(range): IPivotAreasCollection

description 按指定的表单范围获取透视表区域

代码示例

var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"),{sheetCount:3});
var sourceSheet = spread.getSheet(0);
var sheet = spread.getSheet(1);
var sourceData = [["Date","Buyer","Type","Amount"],
                  ["01-Jan","Mom","Fuel",74],
                  ["15-Jan","Mom","Food",235],
                  ["17-Jan","Dad","Sports",20],
                  ["21-Jan","Kelly","Books",125]];
sourceSheet.setArray(0, 0, sourceData );
sourceSheet.tables.add('sourceData', 0, 0, 5, 4);
var layout = GC.Spread.Pivot.PivotTableLayoutType.compact;
var theme = GC.Spread.Pivot.PivotTableThemes.medium2;
var myPivotTable = sheet.pivotTables.add("pivotTable_1", 'sourceData', 1, 1, layout, theme);
myPivotTable.add("Buyer", "Buyer", GC.Spread.Pivot.PivotTableFieldType.rowField);
myPivotTable.add("Type", "Type", GC.Spread.Pivot.PivotTableFieldType.columnField)
myPivotTable.add("Amount", "Sum of Amount", GC.Spread.Pivot.PivotTableFieldType.valueField, GC.Pivot.SubtotalType.sum);
var pivotAreas = sheet.pivotTables.getRangePivotAreas(new GC.Spread.Sheets.Range(3, 2, 2, 2))[myPivotTable.name()];
var style = new GC.Spread.Sheets.Style();
style.backColor = 'red';
myPivotTable.setStyle(pivotAreas[0], style);

参数

属性名 类型 说明
range Range 表单区域

返回值

IPivotAreasCollection

包含所有数据透视表的区域


remove

remove(name): any

description 从表单中删除数据透视表

代码示例

var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"),{sheetCount:3});
var sourceSheet = spread.getSheet(0);
var sheet = spread.getSheet(1);
var sourceData = [["Date","Buyer","Type","Amount"],
                  ["01-Jan","Mom","Fuel",74],
                  ["15-Jan","Mom","Food",235],
                  ["17-Jan","Dad","Sports",20],
                  ["21-Jan","Kelly","Books",125]];
sourceSheet.setArray(0, 0, sourceData );
sourceSheet.tables.add('sourceData', 0, 0, 5, 4);
var layout = GC.Spread.Pivot.PivotTableLayoutType.compact;
var theme = GC.Spread.Pivot.PivotTableThemes.medium2;
sheet.pivotTables.add("pivotTable_1", 'sourceData', 1, 1, layout, theme);
sheet.pivotTables.remove("pivotTable_1");

参数

属性名 类型 说明
name string 数据透视表名称

返回值

any