我们如何在C#中设置Pivot缓存对象的范围[已解决] [英] How do we set a range for the Pivot cache object in C# [SOLVED]

查看:116
本文介绍了我们如何在C#中设置Pivot缓存对象的范围[已解决]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在尝试在C#中实现数据透视缓存对象。代码构建正常,但是在运行代码时我得到的值不在下面代码行的预期范围误差内



 Excel.PivotTable oPivotTable =(Excel.PivotTable)oSheet.PivotTables()。Add(PivotCache:oPivotCache,TableDestination:oRange2,TableName: 摘要); 





这里oRange2已经启动了





 Excel.Range oRange2 =(Excel.Range)oSheet1.Range [  A3:G10]; 





任何人都可以解释这两行的含义以及我们如何设置值,或者更确切地说,是什么每个值是什么意思?

解决方案





因为我无法得到很多帮助网,我别无选择,只能自己调试,我意识到会有很多人可能面临同样的问题。因此,我发布了适合我的解决方案。



第二行代码

 Excel.Range oRange2 =(Excel.Range)oSheet1.Range [  A3:G10]; 





这可以设置工作表中数据透视表的范围,因此可以更好地给出



 Excel.Range oRange2 =(Excel.Range)oSheet1.Range [  Sheet2!


A:

K];





考虑到表1会有数据存在。



一旦我完成并给了枢轴一定数量的列,它对我有用。



还有另外一种方法,



 Excel .PivotTable oPivotTable = oPivotCache.CreatePivotTable(oRange2); 





如果你定义的范围是正确的,这也没有错误。



我希望这可以帮助那里的人:)



谢谢


Hi All,

I am trying to implement the pivot cache object in C#. The code is building fine, however on running the code I am getting value does not fall within the expected range error on the below line of code

Excel.PivotTable oPivotTable = (Excel.PivotTable)oSheet.PivotTables().Add(PivotCache: oPivotCache, TableDestination: oRange2, TableName: "Summary");



Here oRange2 has been initiated as under


Excel.Range oRange2 = (Excel.Range)oSheet1.Range["A3:G10"];



Can anyone please explain the meaning of these two lines and how are we to set the values, or rather, what does each value mean?

解决方案

Hi,

Since I couldn't get much help on the net, I had no option but to debug it on my own, I realized there would be a ton of people who might face the same problem. Hence, m posting the solution that worked for me.

The second line of code

Excel.Range oRange2 = (Excel.Range)oSheet1.Range["A3:G10"];



this sets the range of the pivot table in the worksheet, hence it can be better given as under

Excel.Range oRange2 = (Excel.Range)oSheet1.Range["Sheet2!


A:


K"];



considering sheet 1 would have the data present.

Once I finished that and gave the pivot a definite number of columns it worked for me.

There is another way of going about it,

Excel.PivotTable oPivotTable = oPivotCache.CreatePivotTable(oRange2);



This also gives no error in case your range defined is correct.

I hope this helps someone out there :)

Thanks


这篇关于我们如何在C#中设置Pivot缓存对象的范围[已解决]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆