Solved

C# PivotTable set range dynamically in code

Posted on 2010-09-21
3
1,329 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
Comment Utility
0
 

Author Comment

by:AngieWill
Comment Utility
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
Comment Utility
pivot.SourceData = "'SQL Results'!R1C9:R1000C18";

Succeed!

Thanks
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 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

9 Experts available now in Live!

Get 1:1 Help Now