Solved

C# PivotTable set range dynamically in code

Posted on 2010-09-21
3
1,404 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…

752 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