EPPlus:如何更新数据透视表SourceRange [英] EPPlus: How to update Pivot Table SourceRange
问题描述
我在尝试使用C#类中的EPPLus更新数据透视表的SourceRange时遇到麻烦.我发现CacheDefinition.SourceRange包含我的现有数据透视表的数据源,但是我不知道如何更改它.现有数据透视表数据源是同一Excel文件中数据工作表上的范围.
I'm getting stuck trying to update the SourceRange of a Pivot-Table with EPPLus inside a C# class. I've found that CacheDefinition.SourceRange contains the DataSource of my existing Pivot-Table but I don't know how to change it. Existing Pivot-Table datasource is a range on a data worksheet in the same Excel file.
有什么建议吗?
预先感谢,亚历山德罗
推荐答案
这可能有效:
您可以创建一个自定义的定义名称,该名称包含您的数据范围.我一直都在用这个.
You can create a self-dimensioning defined name that encompasses your data range. I use this all the time.
打开名称管理器.
点击新建.
输入您的范围的名称.
在引用"行中放置以下内容
Put the following in the Refers to: line
OFFSET(DataSource! $ A $ 1
,0,0,COUNTA(DataSource!$ A:$ A),COUNTA(DataSource!$ 1:$ 1))
OFFSET(DataSource!$A$1
,0,0,COUNTA(DataSource!$A:$A),COUNTA(DataSource!$1:$1))
语法:OFFSET(参考,行,列,[高度],[宽度])
syntax: OFFSET(reference, rows, cols, [height], [width])
用您的工作表/标签名称代替数据源.假定表以A1(第一部分)开始,并且您想要一个定义的名称,只要该名称与A列中的值的数量和第1行中的值的宽度一样即可.这是一种非常灵活且有用的方法,确保您定义的名称包含工作表中的所有数据.
Substitute your sheet/tab name for DataSource. This assumes that the table starts in A1 (first section) and you that you want a defined name as long as the number of values in column A and as wide as the values in row 1. It is a very flexible and useful method for making sure your defined names encompass all the data on the sheet.
这篇关于EPPlus:如何更新数据透视表SourceRange的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!