Solved

C# PivotTable set range dynamically in code

Posted on 2010-09-21
3
1,339 Views
Last Modified: 2012-05-10
Hi!

I develop a web application with Visual Studio 2008 and I use Microsoft.Office.Interop.Excel version 11 to export data (from database) in an excel file.
I have a template file containing a pivot. I want to define in code the range of the pivot 'Sheet1'!$I$1:$R$1000 because the number of rows can change!

Do you have an idea to do this?

I succeed to access to the pivotTable in code:
PivotTable pivot = (PivotTable)ioSheet.PivotTables(1);
But I don't succeed to update the range programatically...

Thanks
0
Comment
Question by:AngieWill
  • 2
3 Comments
 
LVL 29

Accepted Solution

by:
Kumaraswamy R earned 500 total points
ID: 33731504
0
 

Author Comment

by:AngieWill
ID: 33732294
Thanks for your answer.

I try with this code:
PivotTable pivot = (PivotTable)ioSheet.PivotTables(1);
pivot.SourceData = "'Sheet1'!$I$1:$R$10";
lRet = pivot.RefreshTable();

But I wait, wait... and nothing

Do you have an idea?
0
 

Author Closing Comment

by:AngieWill
ID: 33732505
pivot.SourceData = "'SQL Results'!R1C9:R1000C18";

Succeed!

Thanks
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now