<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx</link><description>I received an email from a customer the other day asking how to set up an Excel pivot table programmatically. The Excel OM exposes a number of objects and methods that you can use to create pivot tables, some more sophisticated than others. I wanted the</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Creating a PivotTable Programmatically </title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#8773881</link><pubDate>Sat, 26 Jul 2008 05:23:15 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8773881</guid><dc:creator>DotNetKicks.com</dc:creator><description>&lt;p&gt;You've been kicked (a good thing) - Trackback from DotNetKicks.com&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#8799936</link><pubDate>Fri, 01 Aug 2008 17:10:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8799936</guid><dc:creator>Alexandre Brisebois</dc:creator><description>&lt;p&gt;How can I loop through all the PivotFields of a Pivot table in C# ?&lt;/p&gt;
&lt;p&gt;I currently need to find all the PivotFields of an already built PivotTable.&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#8801483</link><pubDate>Fri, 01 Aug 2008 22:07:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8801483</guid><dc:creator>andreww</dc:creator><description>&lt;P&gt;Alexandre - you can use the PivotFields method to retrieve the PivotFields collection, and then iterate through it. The exact mechanism is slightly obscure, but pretty simple. Here's an example:&lt;/P&gt;
&lt;P&gt;Excel.PivotFields fields = (Excel.PivotFields)this.pivotTable.PivotFields(missing);&lt;/P&gt;
&lt;P&gt;int fieldCount = fields.Count;&lt;/P&gt;
&lt;P&gt;StringBuilder builder = new StringBuilder();&lt;/P&gt;
&lt;P&gt;for (int i = 1; i &amp;lt;= fieldCount; i++)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;Excel.PivotField field = (Excel.PivotField)this.pivotTable.PivotFields(i);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;builder.AppendLine(field.Name);&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;MessageBox.Show(builder.ToString());&lt;/P&gt;</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#8802204</link><pubDate>Sat, 02 Aug 2008 00:12:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8802204</guid><dc:creator>Alexandre Brisebois</dc:creator><description>&lt;p&gt;thank you for the prompt reply,&lt;/p&gt;
&lt;p&gt;I found out about the optional parameter while looking through msdn a couple of hours after asking here, but I still have one problem.&lt;/p&gt;
&lt;p&gt;I now can find the column fields and the row fields.&lt;/p&gt;
&lt;p&gt;If i understand how this works,&lt;/p&gt;
&lt;p&gt;There is a root PivotField for the row and column, the subsequent PivotFields in each are then added as a child PivotField and so on. please correct me if i'm wrong.&lt;/p&gt;
&lt;p&gt;I do not seem to be able to get the DataFields, &amp;quot;xlDataField&amp;quot; is there something special I must do to access these fields.&lt;/p&gt;
&lt;p&gt;At the moment I am trying to crawl the pivot table so that I may be able to record what fields are in what Orientation. I am doing this so that I may create a PivotTable definition, which can be used at a later time to recreate the PivotTable.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#8805524</link><pubDate>Sat, 02 Aug 2008 15:23:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8805524</guid><dc:creator>Alexandre Brisebois</dc:creator><description>&lt;p&gt;for those who have the same questions as I've been having.&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#8806870</link><pubDate>Sat, 02 Aug 2008 21:54:33 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8806870</guid><dc:creator>andreww</dc:creator><description>&lt;p&gt;Alexandre - the data, row, column etc fields are not exactly children of the PivotField. Rather, they are all PivotFields that form subsets of the PivotFields collection in the PivotTable. The simplest approach is to use the corresponding RowFields, DataFields etc collection properties of the PivotTable itself. For example: &lt;/p&gt;
&lt;p&gt;StringBuilder builder = new StringBuilder();&lt;/p&gt;
&lt;p&gt;builder.AppendLine(&amp;quot;PivotFields:&amp;quot;);&lt;/p&gt;
&lt;p&gt;Excel.PivotFields pivotFields = (Excel.PivotFields)this.pivotTable.PivotFields(missing);&lt;/p&gt;
&lt;p&gt;for (int i = 1; i &amp;lt;= pivotFields.Count; i++)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Excel.PivotField pivotField = (Excel.PivotField)this.pivotTable.PivotFields(i);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;builder.AppendLine(pivotField.Name);&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;builder.AppendLine();&lt;/p&gt;
&lt;p&gt;builder.AppendLine(&amp;quot;ColumnFields:&amp;quot;);&lt;/p&gt;
&lt;p&gt;Excel.PivotFields columnFields = (Excel.PivotFields)this.pivotTable.get_ColumnFields(missing);&lt;/p&gt;
&lt;p&gt;for (int i = 1; i &amp;lt;= columnFields.Count; i++)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Excel.PivotField columnField = (Excel.PivotField)this.pivotTable.get_ColumnFields(i);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;builder.AppendLine(columnField.Name);&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;builder.AppendLine();&lt;/p&gt;
&lt;p&gt;builder.AppendLine(&amp;quot;RowFields:&amp;quot;);&lt;/p&gt;
&lt;p&gt;Excel.PivotFields rowFields = (Excel.PivotFields)this.pivotTable.get_RowFields(missing);&lt;/p&gt;
&lt;p&gt;for (int i = 1; i &amp;lt;= rowFields.Count; i++)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Excel.PivotField rowField = (Excel.PivotField)this.pivotTable.get_RowFields(i);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;builder.AppendLine(rowField.Name);&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;builder.AppendLine();&lt;/p&gt;
&lt;p&gt;builder.AppendLine(&amp;quot;DataFields:&amp;quot;);&lt;/p&gt;
&lt;p&gt;Excel.PivotFields dataFields = (Excel.PivotFields)this.pivotTable.get_DataFields(missing);&lt;/p&gt;
&lt;p&gt;for (int i = 1; i &amp;lt;= dataFields.Count; i++)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Excel.PivotField dataField = (Excel.PivotField)this.pivotTable.get_DataFields(i);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;builder.AppendLine(dataField.Name);&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;MessageBox.Show(builder.ToString());&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#8850050</link><pubDate>Tue, 12 Aug 2008 09:44:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8850050</guid><dc:creator>shreyas</dc:creator><description>&lt;p&gt;How do i make this functionality work for SSAS OLAP Cube&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#8851385</link><pubDate>Tue, 12 Aug 2008 16:58:40 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8851385</guid><dc:creator>shreyas</dc:creator><description>&lt;p&gt;Hi, I tried your code posted as “Creating a PivotTable Programmatically”, it works perfectly. I need to get exactly similar functionality with OLAP Cube. Below is the code I tried but I get error at line marked as (*****), when i try to add Pivot Table. I get exception as &amp;nbsp;“Exception from HRESULT: 0x800A03EC”.&lt;/p&gt;
&lt;p&gt;Microsoft.Office.Interop.Excel.Application app;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;app = new Microsoft.Office.Interop.Excel.Application(); &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Microsoft.Office.Interop.Excel.Workbook wkbk = (Microsoft.Office.Interop.Excel.Workbook)app.Workbooks.Add(Type.Missing);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Microsoft.Office.Interop.Excel.Worksheet sheet = (Microsoft.Office.Interop.Excel.Worksheet)wkbk.ActiveSheet;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;string connection = @&amp;quot;OLEDB; Provider=msolap; Integrated Security=SSPI ; Datasource=localhost; Initial Catalog=MSLMKTG_DemoCube; UID = Administrator; Password = cybage@123&amp;quot;;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;string command = &amp;quot;CubeUserMSLMKTG&amp;quot;;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Microsoft.Office.Interop.Excel.PivotCache pivotCache;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;pivotCache = wkbk.PivotCaches().Add(Microsoft.Office.Interop.Excel.XlPivotTableSourceType.xlExternal,Type.Missing);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;pivotCache.Connection = connection;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;pivotCache.MaintainConnection = true;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;pivotCache.CommandType = Microsoft.Office.Interop.Excel.XlCmdType.xlCmdCube;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;pivotCache.CommandText = command; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Microsoft.Office.Interop.Excel.PivotTables pvtTables = (Microsoft.Office.Interop.Excel.PivotTables)sheet.PivotTables(Type.Missing);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(*****)Microsoft.Office.Interop.Excel.PivotTable pvt = pvtTables.Add(pivotCache,sheet.Cells[1,1], &amp;quot;PivotTable1&amp;quot;, true, Type.Missing);&lt;/p&gt;
&lt;p&gt;Please help urgently&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Shreyas&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#8851505</link><pubDate>Tue, 12 Aug 2008 17:16:55 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8851505</guid><dc:creator>shreyas</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;once again mailing you.&lt;/p&gt;
&lt;p&gt;In my previos code if i change my adding pivot code to &lt;/p&gt;
&lt;p&gt;Microsoft.Office.Interop.Excel.PivotTable pvt = pivotCache.CreatePivotTable(sheet.Cells[8, 3], &amp;quot;PivotTable1&amp;quot;, Type.Missing, Type.Missing);&lt;/p&gt;
&lt;p&gt;I get error something as OLE DB error saying problem in opening dialog box and the second time execute the same code i get the error as &amp;quot;Exception from HRESULT: 0x800A03EC&amp;quot;&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#8872900</link><pubDate>Sun, 17 Aug 2008 03:51:16 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8872900</guid><dc:creator>amrut</dc:creator><description>&lt;p&gt;Im not sure if this was answered in the previous codes as I am new to VB. If i were to try to access all the datafields in my pivotfield to make changes to formatting how could i do that?&lt;/p&gt;
&lt;p&gt;Also I want to remove the &amp;quot;sum of&amp;quot; out of each datafield. So it says Billpayers instead of Sum of Billpayers. Is there a way to do that to all datafields at once?&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#8876145</link><pubDate>Mon, 18 Aug 2008 12:36:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8876145</guid><dc:creator>Shreyas</dc:creator><description>&lt;p&gt;Has any one done this.......see the above threads :)&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Shreyas&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#8887677</link><pubDate>Fri, 22 Aug 2008 15:43:36 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8887677</guid><dc:creator>Teme</dc:creator><description>&lt;p&gt;Thanks for this blog post!&lt;/p&gt;
&lt;p&gt;To Shreyas.&lt;/p&gt;
&lt;p&gt;It can be used to create connection to OLAP cube.&lt;/p&gt;
&lt;p&gt;Connection string I used in test case was:&lt;/p&gt;
&lt;p&gt;&amp;quot;OLEDB;Provider=MSOLAP.1; Location=ServerName;Connect Timeout=60; Initial Catalog=Analysis Services ProjectTest;Client Cache Size=25&amp;quot;;&amp;quot;&lt;/p&gt;
&lt;p&gt;Properties:&lt;/p&gt;
&lt;p&gt;pivotCache.CommandText = &amp;quot;name of the cube&amp;quot;;&lt;/p&gt;
&lt;p&gt;pivotCache.CommandType = XlCmdType.xlCmdCube;&lt;/p&gt;
&lt;p&gt;And assignment of fields:&lt;/p&gt;
&lt;p&gt;pivotTable.CubeFields[&amp;quot;Name of cube dimension&amp;quot;].Orientation = XlPivotFieldOrientation.xlRowField;&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#8887679</link><pubDate>Fri, 22 Aug 2008 15:43:59 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8887679</guid><dc:creator>Teme</dc:creator><description>&lt;p&gt;Thanks for this blog post!&lt;/p&gt;
&lt;p&gt;To Shreyas.&lt;/p&gt;
&lt;p&gt;It can be used to create connection to OLAP cube.&lt;/p&gt;
&lt;p&gt;Connection string I used in test case was:&lt;/p&gt;
&lt;p&gt;&amp;quot;OLEDB;Provider=MSOLAP.1; Location=ServerName;Connect Timeout=60; Initial Catalog=Analysis Services ProjectTest;Client Cache Size=25&amp;quot;;&amp;quot;&lt;/p&gt;
&lt;p&gt;Properties:&lt;/p&gt;
&lt;p&gt;pivotCache.CommandText = &amp;quot;name of the cube&amp;quot;;&lt;/p&gt;
&lt;p&gt;pivotCache.CommandType = CmdType.xlCmdCube;&lt;/p&gt;
&lt;p&gt;And assignment of fields:&lt;/p&gt;
&lt;p&gt;pivotTable.CubeFields[&amp;quot;Name of cube dimension&amp;quot;].Orientation = XlPivotFieldOrientation.xlRowField;&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#8903736</link><pubDate>Thu, 28 Aug 2008 20:21:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8903736</guid><dc:creator>Gaby</dc:creator><description>&lt;p&gt;Hello Andrew,&lt;/p&gt;
&lt;p&gt;I'm having a couple of issues with a PivotTable:&lt;/p&gt;
&lt;p&gt;1) I get the following error when setting the Orientation property of the fifth PivotField: &amp;quot;Unable to set the Orientation property of the PivotField class&amp;quot;. &amp;nbsp;It seems that the error is related to the number of fields, not to the type of orientation being used.&lt;/p&gt;
&lt;p&gt;2) I don't know how to put the data fields as columns (as when you right-click the &amp;quot;Data&amp;quot; cell, select Order and choose &amp;quot;Move to Column&amp;quot;). &amp;nbsp;Can this be accomplished programatically?&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#8904596</link><pubDate>Fri, 29 Aug 2008 10:07:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8904596</guid><dc:creator>Alexandre Brisebois</dc:creator><description>&lt;p&gt;Dear Gaby, &lt;/p&gt;
&lt;p&gt;I was facing the exact same problem a few weeks ago.&lt;/p&gt;
&lt;p&gt;This is what I found:&lt;/p&gt;
&lt;p&gt;You need to create the pivot table in steps. The first of these steps is add all the data fields:&lt;/p&gt;
&lt;p&gt;if (orientation.Equals(&amp;quot;xlDataField&amp;quot;))&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; string source = field.Attribute(&amp;quot;SourceName&amp;quot;).Value;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; string function = field.Attribute(&amp;quot;Function&amp;quot;).Value;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; pivot.AddDataField(pivot.PivotFields(source), name, SelectFunction(function));&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;Then set the orientation of the PivotFields. Be sure not to set the orientation of the &amp;quot;Data&amp;quot; named PivotField.&lt;/p&gt;
&lt;p&gt;Once all the fields have been set, you may then set the orientation of the &amp;quot;Data&amp;quot; field. You need to do this last since by placing PivotFields the value PivotField is automatically generated. &lt;/p&gt;
&lt;p&gt;Please correct me if I'm wrong.&lt;/p&gt;
&lt;p&gt;Now you can set the Position and Caption of the fields.&lt;/p&gt;
&lt;p&gt;This is how i went about it. Let me know if this works.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Alexandre Brisebois&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#8907008</link><pubDate>Sat, 30 Aug 2008 01:01:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8907008</guid><dc:creator>Gaby</dc:creator><description>&lt;p&gt;Hello Alexandre,&lt;/p&gt;
&lt;p&gt;It didn't work. &amp;nbsp;It seems that error # 1 appears because there are too many rows. &amp;nbsp;I'll try to sort that out later.&lt;/p&gt;
&lt;p&gt;Do you have any idea on how to accomplish # 2 (&amp;quot;Move to Columns&amp;quot; programatically)?&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Gaby&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#8907140</link><pubDate>Sat, 30 Aug 2008 01:38:04 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8907140</guid><dc:creator>Gaby</dc:creator><description>&lt;p&gt;I made it work with this line&lt;/p&gt;
&lt;p&gt;table1.PivotFields(&amp;quot;Data&amp;quot;).Orientation = Excel.XlPivotFieldOrientation.xlColumnField&lt;/p&gt;
&lt;p&gt;before setting the RowColumn that caused the problem with too many rows.&lt;/p&gt;
&lt;p&gt;Thanks.&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#8915839</link><pubDate>Mon, 01 Sep 2008 10:15:07 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8915839</guid><dc:creator>Teme need furhter help</dc:creator><description>&lt;p&gt;Hi Teme,&lt;/p&gt;
&lt;p&gt;Thanks...i tried your suggested code.&lt;/p&gt;
&lt;p&gt;I am getting error when assigning dimensions to the pivot table. The error is &amp;quot;Invalid index. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX))&amp;quot;&lt;/p&gt;
&lt;p&gt;pvt.CubeFields[&amp;quot;Data Source Name&amp;quot;].Orientation = Microsoft.Office.Interop.Excel.XlPivotFieldOrientation.xlColumnField;&lt;/p&gt;
&lt;p&gt;here &amp;quot;Data Source Name&amp;quot; is the name of the dimension but it comes under dimension Dim Source, it is a hierachy under this dimension.&lt;/p&gt;
&lt;p&gt;Would be helpful if you can send me your working code&lt;/p&gt;
&lt;p&gt;My mail id is bhagatshreyas@gmail.com&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Shreyas&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#8918886</link><pubDate>Tue, 02 Sep 2008 07:50:05 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8918886</guid><dc:creator>Teme...finally it worked</dc:creator><description>&lt;p&gt;Thanks Teme....finally it worked :)&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Shreyas&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#8919717</link><pubDate>Tue, 02 Sep 2008 13:17:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8919717</guid><dc:creator>Teme..need help</dc:creator><description>&lt;p&gt;Hi Teme, &lt;/p&gt;
&lt;p&gt;I am done with the implementation but when i deploy it on IIS server, nothing is getting generated in the excel.Please share your contact information.&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Shreyas&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#8919743</link><pubDate>Tue, 02 Sep 2008 13:32:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8919743</guid><dc:creator>Alexandre Brisebois</dc:creator><description>&lt;p&gt;Shreyas,&lt;/p&gt;
&lt;p&gt;Why are you generating these on IIS, this might turn out to be very resource hungry?&lt;/p&gt;
&lt;p&gt;Have you installed the VSTO components on the server ? Haven you Installed Excel 2007 on the server ?&lt;/p&gt;
&lt;p&gt;Best regards, &lt;/p&gt;
&lt;p&gt;Alexandre Brisebois&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#8919747</link><pubDate>Tue, 02 Sep 2008 13:35:24 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8919747</guid><dc:creator>Alexandre Brisebois</dc:creator><description>&lt;p&gt;I have been working with PivotCharts, &lt;/p&gt;
&lt;p&gt;and I'm trying to wrap my head around getting the chart layout. I have only found the ApplyLayout [ ApplyLayout(1,Type.Missing); ] method of the Chart Object. Is if possible for me to retrieve this integer value ?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Alexandre Brisebois&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#8920011</link><pubDate>Tue, 02 Sep 2008 16:50:59 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8920011</guid><dc:creator>Microsoft.Office.Interop.Excel help</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;when i run my code in Visual studio it works perfectly fine...but when i deploy it on IIS server then my excel sheet doesn't show anything.How do get this done.Some where i read about Microsoft.Office.Interop.Excel which IIS does not support.Please let me know the detail steps.&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Shreyas&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#8921448</link><pubDate>Wed, 03 Sep 2008 09:45:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8921448</guid><dc:creator>Teme</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;Sorry haven't had the time to check replies. It can be done on IIS. Have you included all the dlls that needed to Bin folder of website? I had Microsoft.Office.Interop.Excel.dll and office.dll.&lt;/p&gt;
&lt;p&gt;For first time I tried it on IIS I ran to the language version bug. Before using Excel operations set your culture to US.&lt;/p&gt;
&lt;p&gt;System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo(&amp;quot;en-US&amp;quot;); &lt;/p&gt;
&lt;p&gt;You must disable all popup questions of Excel because IIS runs it without console. So no one can reply to question -&amp;gt; process hangs.&lt;/p&gt;
&lt;p&gt;_exelApp.DisplayAlerts = false;&lt;/p&gt;
&lt;p&gt;Have you set user rights for folders that are used?&lt;/p&gt;
&lt;p&gt;-Teme&lt;/p&gt;
&lt;p&gt;For detailed questions:&lt;/p&gt;
&lt;p&gt;teme1011@gmail.com&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#8935658</link><pubDate>Tue, 09 Sep 2008 05:37:14 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8935658</guid><dc:creator>andreww</dc:creator><description>&lt;p&gt;Alexandre - I don't believe there is any way to retrieve the chart layout. When you call ApplyLayout, the integer you pass as the first parameter is an identifier into the list of possible layouts for this chart type (you can see these values in the Design tab of the Ribbon). These layouts affect one or more values (such as the existence and/or position of the Legend) - not necessarily just a single property.&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#8936034</link><pubDate>Tue, 09 Sep 2008 10:17:57 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8936034</guid><dc:creator>Alexandre Brisebois</dc:creator><description>&lt;p&gt;Andrew,&lt;/p&gt;
&lt;p&gt;after some time i decided on setting the '1' layout for all my charts and have the user customize it before printing it out.&lt;/p&gt;
&lt;p&gt;Thanks for the response. I do think that this would be an interesting addition to future versions.&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#8957255</link><pubDate>Thu, 18 Sep 2008 16:11:16 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8957255</guid><dc:creator>Helen</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;If I already have a dataset with the data, how can I create the pivot table?&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#8958499</link><pubDate>Fri, 19 Sep 2008 12:41:54 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8958499</guid><dc:creator>Helen</dc:creator><description>&lt;p&gt;I tried the code and works but when I tried the line:&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Excel.PivotTable pivotTable = pivotTables.Add(&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;pivotCache, Globals.ThisAddIn.Application.ActiveCell, &amp;quot;PivotTable1&amp;quot;,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;missing, missing);&lt;/p&gt;
&lt;p&gt;the programs shows me an SQL connection windwos ask me for a databaseName, id an password?&lt;/p&gt;
&lt;p&gt;Why??&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#8962488</link><pubDate>Tue, 23 Sep 2008 20:06:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8962488</guid><dc:creator>andreww</dc:creator><description>&lt;p&gt;Helen - the code I posted specifically uses a SQL connection, so if you use this code, the PivotCache is set up to use a SQL database. Are you saying that you have the data in an Excel Range, and that you want to use that data for your PivotTable? If so, you can do so very simply. For example: &lt;/p&gt;
&lt;p&gt;Excel.PivotCache pivotCache =&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;this.Application.ActiveWorkbook.PivotCaches().Add(&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Excel.XlPivotTableSourceType.xlDatabase,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;(Excel.Range)sheet.get_Range(&amp;quot;A1&amp;quot;, &amp;quot;C17&amp;quot;));&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#9113720</link><pubDate>Tue, 18 Nov 2008 02:28:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9113720</guid><dc:creator>Connie LeMaster</dc:creator><description>&lt;p&gt;How can I get to the PivotItems of the individual PivotFields objects? I am trying to convert some VBA logic to C# .NET. In the VBA code I could loop through the PivotItems that were created for each PivotField and make them Visible or not depending on the caption. I cannot seem to find the right object/method to get to those same PivotItem objects in .NET VSTO.&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#9114192</link><pubDate>Tue, 18 Nov 2008 03:16:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9114192</guid><dc:creator>andreww</dc:creator><description>&lt;p&gt;Connie - you can simply iterate through the collection of PivotItems in C# in pretty much the same way you can do it in VBA - after all, you're still using the same exposed Excel object model. For example:&lt;/p&gt;
&lt;p&gt;StringBuilder builder = new StringBuilder();&lt;/p&gt;
&lt;p&gt;builder.AppendLine(&amp;quot;PivotItems:&amp;quot;);&lt;/p&gt;
&lt;p&gt;Excel.PivotItems items = (Excel.PivotItems)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;((Excel.PivotField)this.pivotTable.PivotFields(&amp;quot;2004&amp;quot;)).PivotItems(missing);&lt;/p&gt;
&lt;p&gt;for (int i = 1; i &amp;lt; items.Count; i++)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Excel.PivotItem item = (Excel.PivotItem)items.Item(i);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;builder.AppendLine(String.Format(&amp;quot;{0}&amp;quot;, item.Value));&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;MessageBox.Show(builder.ToString());&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#9120223</link><pubDate>Wed, 19 Nov 2008 00:14:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9120223</guid><dc:creator>Connie LeMaster</dc:creator><description>&lt;p&gt;Thanks so much! That worked like a charm. I did end up using it as a foreach (PivotItem item in items) but the principle is the same. The collections that are available in the Excel .NET tools feel a little different than the normal .NET collections. I always forget to try to use the Type.Missing object in place of an index.&lt;/p&gt;
&lt;p&gt;Thanks again!&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#9148575</link><pubDate>Fri, 28 Nov 2008 02:06:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9148575</guid><dc:creator>Dirk</dc:creator><description>&lt;p&gt;Andrew - great article!&lt;/p&gt;
&lt;p&gt;I like to create a Pivot table from a SSAS cube and wonder if you could post the complete code here. I suppose you have it anyways.&lt;/p&gt;
&lt;p&gt;Also I was able to get the MDX scripts that Excel generates and saved those. Now, what would I have to do to recreate a Pivot table with that. Would that be the COMMAND text?&lt;/p&gt;
&lt;p&gt;Your help in this matter is greatly appreciated.&lt;/p&gt;
&lt;p&gt;Thanks, Dirk&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#9148581</link><pubDate>Fri, 28 Nov 2008 02:08:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9148581</guid><dc:creator>Dirk</dc:creator><description>&lt;p&gt;Dirk again. I missed to mention that I have created an Excel 2007 Add-in that I like to use to create these Pivot tables based on the MDX queries saved beforehand.&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#9152716</link><pubDate>Fri, 28 Nov 2008 21:30:42 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9152716</guid><dc:creator>andreww</dc:creator><description>&lt;p&gt;Dirk - I'm afraid I don't know the answer to your question, although I suspect your best bet would be to use an AdomdCommand from the AnalysisServices library.&lt;/p&gt;
&lt;p&gt;Have you looked at the OLAP PivotTable Extensions utilities on codeplex? &lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://www.codeplex.com/OlapPivotTableExtend"&gt;http://www.codeplex.com/OlapPivotTableExtend&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#9153135</link><pubDate>Fri, 28 Nov 2008 23:06:04 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9153135</guid><dc:creator>Dirk</dc:creator><description>&lt;p&gt;Andrew -&lt;/p&gt;
&lt;p&gt;thanks for the quick feedback. It appears that Excel was not build to support my idea.&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Dirk&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#9156029</link><pubDate>Sat, 29 Nov 2008 16:59:41 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9156029</guid><dc:creator>Dirk</dc:creator><description>&lt;p&gt;Andrew - &lt;/p&gt;
&lt;p&gt;could you please take a quick look at my code and tell me why it is not working. I all it from within an Excel Add-in.&lt;/p&gt;
&lt;p&gt;I really would appreciate your help.&lt;/p&gt;
&lt;p&gt;Thanks in advance,&lt;/p&gt;
&lt;p&gt;Dirk&lt;/p&gt;
&lt;p&gt;--&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Sub CreateOLAPPivotTable()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;'Declare variables&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dim objMyPivotCache As Excel.PivotCache&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dim objMyPivotTable As Excel.PivotTable&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dim App As Excel.Application&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;App = Globals.ThisAddIn.Application&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;'Create PivotCache&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;objMyPivotCache = App.ActiveWorkbook.PivotCaches.Add(Microsoft.Office.Interop.Excel.XlPivotTableSourceType.xlExternal)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;'Retrieve data&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;With objMyPivotCache&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.Connection = &amp;quot;OLEDB;Provider=MSOLAP.3;Integrated Security=SSPI;Persist Security Info=True;Data Source=server;Initial Catalog=DuPont_EMEA&amp;quot;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.CommandText = &amp;quot;server cube FreeMining&amp;quot;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.CommandType = Excel.XlCmdType.xlCmdCube&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;End With&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;'Create PivotTable&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;objMyPivotTable = App.ActiveSheet.PivotTables.Add( _&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;PivotCache:=objMyPivotCache, _&lt;/p&gt;
&lt;p&gt;'&lt;/p&gt;
&lt;p&gt;'I believe the RANGE is crashing?&lt;/p&gt;
&lt;p&gt;'Exception from HRESULT: 0x800A03EC&lt;/p&gt;
&lt;p&gt;'&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;TableDestination:=App.Range(&amp;quot;A1&amp;quot;), _&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;TableName:=&amp;quot;OLAP PivotTable&amp;quot;)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;objMyPivotTable.CubeFields(&amp;quot;[REVIEWPERIOD]&amp;quot;).Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlDataField&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;objMyPivotTable.CubeFields(&amp;quot;[DMDUNIT]&amp;quot;).Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlRowField&lt;/p&gt;
&lt;p&gt;End Sub&lt;/p&gt;
&lt;p&gt;--&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#9163506</link><pubDate>Tue, 02 Dec 2008 10:28:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9163506</guid><dc:creator>andreww</dc:creator><description>&lt;p&gt;Dirk - I've looked at your code and I can't see anything wrong with it. TBH you might be better off posting OLAP questions to one of the Excel team's blogs, for instance: &lt;a rel="nofollow" target="_new" href="http://blogs.msdn.com/excel/archive/2008/02/05/common-questions-around-excel-2007-OLAP-PivotTables.aspx"&gt;http://blogs.msdn.com/excel/archive/2008/02/05/common-questions-around-excel-2007-OLAP-PivotTables.aspx&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#9178075</link><pubDate>Fri, 05 Dec 2008 06:15:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9178075</guid><dc:creator>Boris</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;How can I create the pivotcache from DataSet?&lt;/p&gt;
&lt;p&gt;the dataset is created in the code, not from the external database.&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Boris&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#9186020</link><pubDate>Tue, 09 Dec 2008 04:16:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9186020</guid><dc:creator>John</dc:creator><description>&lt;p&gt;How do I programatically change the SQL Server connection used by an existing pivot table?&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#9188813</link><pubDate>Wed, 10 Dec 2008 05:23:54 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9188813</guid><dc:creator>John</dc:creator><description>&lt;p&gt;The way you programatically change the connection is like this:&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://support.microsoft.com/kb/327572"&gt;http://support.microsoft.com/kb/327572&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The support article only updates the server name. If you want to change the whole string, it must be in the following format. Otherwise you'll get a cryptic 0x800A03EC exception.&lt;/p&gt;
&lt;p&gt;ODBC;DRIVER=SQL Server;SERVER=&amp;lt;&amp;lt;yourserver&amp;gt;&amp;gt;;DATABASE=&amp;lt;&amp;lt;yourdatabase&amp;gt;&amp;gt;;Network=DBMSSOCN;Trusted_Connection=Yes&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#9188819</link><pubDate>Wed, 10 Dec 2008 05:27:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9188819</guid><dc:creator>John</dc:creator><description>&lt;p&gt;The above connection string was truncated. Here it is again.&lt;/p&gt;
&lt;p&gt;ODBC;DRIVER=SQL Server;SERVER=&amp;lt;&amp;lt;your server&amp;gt;&amp;gt;;DATABASE=&amp;lt;&amp;lt;your database&amp;gt;&amp;gt;;Network=DBMSSOCN;Trusted_Connection=Yes&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#9252964</link><pubDate>Fri, 26 Dec 2008 10:34:01 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9252964</guid><dc:creator>naren</dc:creator><description>&lt;p&gt;how to remove/hide datafields from a pivot table using vba code??&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#9254025</link><pubDate>Sat, 27 Dec 2008 04:36:38 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9254025</guid><dc:creator>andreww</dc:creator><description>&lt;p&gt;Boris - you can create a PivotCache from an ADO Recordset, using the PivotCache.Recordset property. So, if you're starting from an ADO.NET DataSet, you can convert that to a Recordset first. See here for details: &lt;a rel="nofollow" target="_new" href="http://support.microsoft.com/kb/316337"&gt;http://support.microsoft.com/kb/316337&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#9254064</link><pubDate>Sat, 27 Dec 2008 05:39:16 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9254064</guid><dc:creator>andreww</dc:creator><description>&lt;p&gt;naren - to show/hide pivot fields, you can simply use the Visible property exposed by the Excel object model. For example:&lt;/p&gt;
&lt;p&gt;Excel.PivotFields rowFields = (Excel.PivotFields)this.pivotTable.get_RowFields(missing);&lt;/p&gt;
&lt;p&gt;for (int r = 1; r &amp;lt;= rowFields.Count; r++)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Excel.PivotField rowField = (Excel.PivotField)this.pivotTable.get_RowFields(r);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Excel.PivotItems items = (Excel.PivotItems)rowField.PivotItems(missing);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;for (int i = 1; i &amp;lt; items.Count; i++)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Excel.PivotItem item = (Excel.PivotItem)items.Item(i);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;string s = item.Value;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (s.StartsWith(&amp;quot;J&amp;quot;))&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;item.Visible = false;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#9410586</link><pubDate>Tue, 10 Feb 2009 16:59:13 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9410586</guid><dc:creator>Sayantan Samanta</dc:creator><description>&lt;p&gt;How do i publish a pivot by code to a sharepoint site.In excel 2007&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#9411140</link><pubDate>Tue, 10 Feb 2009 22:24:38 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9411140</guid><dc:creator>andreww</dc:creator><description>&lt;p&gt;Sayantan - this is really a question about usage of Excel and SharePoint, not really related to programmatic development of pivot tables. For the best answer, please post your question to one of the Excel and/or SharePoint forums: &lt;a rel="nofollow" target="_new" href="http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.excel.programming&amp;amp;lang=en&amp;amp;cr=US"&gt;http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.excel.programming&amp;amp;lang=en&amp;amp;cr=US&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.excel&amp;amp;cat=en_US_e064c9ec-14bf-4ef7-ba07-6a1970559f64&amp;amp;lang=en&amp;amp;cr=US"&gt;http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.excel&amp;amp;cat=en_US_e064c9ec-14bf-4ef7-ba07-6a1970559f64&amp;amp;lang=en&amp;amp;cr=US&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#9538279</link><pubDate>Wed, 08 Apr 2009 17:31:42 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9538279</guid><dc:creator>adolf garlic</dc:creator><description>&lt;p&gt;Does this work ok with excel 2003?&lt;/p&gt;
&lt;p&gt;Can the same technique be used for non pivot query tables?&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#9539301</link><pubDate>Thu, 09 Apr 2009 04:58:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9539301</guid><dc:creator>andreww</dc:creator><description>&lt;p&gt;adolf - yes, the general behavior is the same, although ome specific features have obviously changed from Excel 2003 to Excel 2007. For example, Excel 2003 did not provide ShowTableStyleRowStripes or TableStyle2 properties, so you'd have to use the similar TableStyle property instead, eg:&lt;/p&gt;
&lt;p&gt;//this.pivotTable.ShowTableStyleRowStripes = true;&lt;/p&gt;
&lt;p&gt;//this.pivotTable.TableStyle2 = &amp;quot;PivotStyleLight1&amp;quot;;&lt;/p&gt;
&lt;p&gt;this.pivotTable.TableStyle = &amp;quot;PivotStyleLight1&amp;quot;;&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#9553069</link><pubDate>Thu, 16 Apr 2009 18:46:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9553069</guid><dc:creator>ronaldfer747</dc:creator><description>&lt;p&gt;Ho do I use a table from a Dataset as a source data in a pivot table properties?&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#9553859</link><pubDate>Fri, 17 Apr 2009 08:17:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9553859</guid><dc:creator>andreww</dc:creator><description>&lt;p&gt;ronaldfer747 - see my previous reply to Boris, viz:&lt;/p&gt;
&lt;p&gt;You can create a PivotCache from an ADO Recordset, using the PivotCache.Recordset property. So, if you're starting from an ADO.NET DataSet, you can convert that to a Recordset first. See here for details: &lt;a rel="nofollow" target="_new" href="http://support.microsoft.com/kb/316337"&gt;http://support.microsoft.com/kb/316337&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#9574437</link><pubDate>Wed, 29 Apr 2009 01:21:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9574437</guid><dc:creator>Matt</dc:creator><description>&lt;p&gt;Did anyone have a solution for shreyas HRESULT: 0x800A03EC error? I'm having the same problem and have been unable to solve it. I believe the error has to do with the second parameter in PivotTables.Add() which is the tableDefinition. Application.ActiveCell doesn't seem to work and any other explicit cell location also doesn't work.&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#9652801</link><pubDate>Fri, 29 May 2009 15:10:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9652801</guid><dc:creator>Artur</dc:creator><description>&lt;p&gt;Hi!&lt;/p&gt;
&lt;p&gt;Great article! I habe build a Cube PivotTable i can browse any PivotItem. Thats fine byu i'm not able to set any PivotFilter and also not able so set some attributes visible false. Has anyone an idee what i'm doing wrong.&lt;/p&gt;
&lt;p&gt;I got every time the same HRSEULT Error like Matt.&lt;/p&gt;
&lt;p&gt;Thx for any help&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#9669117</link><pubDate>Sun, 31 May 2009 15:37:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9669117</guid><dc:creator>Christophe T. Chavey</dc:creator><description>&lt;p&gt;Hi, thank you for your great article.&lt;/p&gt;
&lt;p&gt;Someone know how can I hide the connection string from the &amp;quot;user's eyes&amp;quot;? The PivotTable continue working, updating data from database etc. but I must hide the connection string (or encrypt it) because the user can't see it (the credentials used to connect to database). If he go to the datasource's properties he can see what user and password was used to connect to the database, or if I can denied access to this property's dialog?&lt;/p&gt;
&lt;p&gt;Thanks for any help.&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#9803478</link><pubDate>Thu, 25 Jun 2009 15:39:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9803478</guid><dc:creator>R. Keeton</dc:creator><description>&lt;p&gt;I have a pivot table that is populated from an Oracle database thru a rather cumbersome query. I would like to use the raw data in the pivot table in a custom function to summarize the data. The majority of the time, the data population exceeds 65,536, which makes it impossible to show the detailed records. Does anybody know how to access the data from the pivot table memory?&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#9803997</link><pubDate>Thu, 25 Jun 2009 21:09:42 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9803997</guid><dc:creator>andreww</dc:creator><description>&lt;p&gt;R.Keeton - sorry, I don't know the answer, and if you don't get a response from anyone else on this blog, I suggest you re-post to the Excel team's blog, eg:&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://blogs.msdn.com/excel/archive/tags/PivotTables/default.aspx"&gt;http://blogs.msdn.com/excel/archive/tags/PivotTables/default.aspx&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#9831352</link><pubDate>Mon, 13 Jul 2009 12:58:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9831352</guid><dc:creator>joeaxe</dc:creator><description>&lt;p&gt;Thanks andreww for this great article! It helped me to build a pivot table programatically on my local machine but when I publish the project on my server and try to do the same from server side it gives me a blank excel file. Is this due to MSQuery permissions or what? Did anybody had the same issue?&lt;/p&gt;
&lt;p&gt;Thanks in advance for any help you can provide me!&lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#9833564</link><pubDate>Wed, 15 Jul 2009 00:50:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9833564</guid><dc:creator>Rolando Granera</dc:creator><description>&lt;p&gt;Hello, you help me?&lt;/p&gt;
&lt;p&gt;andreww&lt;/p&gt;
&lt;p&gt;I need not show options in PivoteTable; Data; connection properties to prevent the connection string can not be viewed by the user. You might tell me how to do &lt;/p&gt;
</description></item><item><title>re: Creating a PivotTable Programmatically</title><link>http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx#9844968</link><pubDate>Wed, 22 Jul 2009 19:31:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9844968</guid><dc:creator>joeaxe</dc:creator><description>&lt;p&gt;Solved! The problem was due to the lack of permissions. The solution was to define local impersonation of the published site and voil&amp;#225;!&lt;/p&gt;
</description></item></channel></rss>