Solved

C# PivotTable set range dynamically in code

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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

830 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