Solved

C# PivotTable set range dynamically in code

Posted on 2010-09-21
3
1,345 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

813 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

16 Experts available now in Live!

Get 1:1 Help Now