I have managed to populate my Pivot grid, but now!, How do I export this to Excel or Word?
I can not really find a clear example of how this is to be done. Can you please guide me to a simple solution
Hello,
After working on this and doing some research, “Export PivotGrid to Excel and Word” has been determined to be a new product idea. You can suggest new product ideas for future versions (or vote for existing ones) at <http://ideas.infragistics.com>.
There are many benefits to submitting a product idea:
- Direct communication with our product management team regarding your product idea.
- Notifications whenever new information regarding your idea becomes available.
- Ability to vote on your favorite product ideas to let us know which ones are the most important to you. You will have ten votes for this and can change which ideas you are voting for at any time.
- Allow you to shape the future of our products by requesting new controls and products altogether.
- You and other developers can discuss existing product ideas with members of our Product Management team.
Steps to create your idea:
1. Log into the Infragistics Product Idea site at http://ideas.infragistics.com (creating a new login if needed).
2. Navigate to the product / platform channel of your choice (e.g. WPF, Windows Forms, ASP.NET, HTML5 / Ignite UI, iOS / NucliOS, etc.)
3. Add your product idea and be sure to be specific and provide as much detail as possible.
Explain the context in which a feature would be used, why it is needed, why it can’t be accomplished today, and who would benefit from it. You can even add screenshots to build a stronger case. Remember that for your suggestion to be successful, you need other members of the community to vote for it. Be convincing!
[CASE: “Reference case [case number], FORUMS: “Include a link to this thread”] in your idea so product management will be able to look back at this case.
The Product Idea site puts you in the driver’s seat and allows you to track the progress of your ideas at any time, see how many votes it got, read comments from other developers in the community, and see if someone from the product team has additional questions for you.
Thank you for contacting Infragistics.
Hi,
That is basically our full code, but I had to "clean" it when sharing because we use some internal libraries that I can't share.
Trying to address your errors:
1) DS is the FlatDatasource from where you are populating your PivotGrid
Dim ds As FlatDataSource
2) The function that can be shown as errors to you are Imports
<Runtime.InteropServices.DllImport("user32.dll")> Private Shared Function SetForegroundWindow(hWnd As IntPtr) As <Runtime.InteropServices.MarshalAs(Runtime.InteropServices.UnmanagedType.Bool)> Boolean End Function
<Runtime.InteropServices.DllImport("user32.dll", SetLastError:=True)> Private Shared Function FindWindow(lpClassName As String, lpWindowName As String) As System.IntPtr End Function
Hope it helps,
Eduardo Peccorini
Thanks for the post.
I tried your attached code but its getting some errors. like ds. and some functions.
Could you please share your exporting full code.
Regards,
Jims
I submitted the "New Idea" for "Excel Export" on Infragistics ideas site more than a year ago and it is still "Waiting for Votes" even when it was the most voted on WinForms for some time, let’s face it, it's not a "New Idea" it's basic functionality and Infragistics should have developed this on their own with the release or immediately after releasing the WinPivotGrid control, they just don't care about WinForms anymore.
So, after the painful wait of over a year I decided that it shouldn't be so complicated to figure out how to do it myself even when not having access to all the internal properties that Infragistics has on their own code (for them should be even easier), so I sat down a Saturday and by Sunday it was working really good (wife was not happy, but I was :)). After some time in beta testing and some production tests it is now working ok, fast and stable enough that I can deploy it to my customers. I'm sure that all the smart devs here will find some things to improve, since I'm not really familiar with Excel Interops, and I will be really happy if they point them out and the code gets improved.
I want to share this with everyone here as a way of repaying all the help that you get when someone shares his work online and you find a way to do what you need fast and easy, it has really helped me before, and I hope it saves some time for others.
Of course this code was created taking bits of code and ideas from several sources on Internet, all the credit goes to the different devs that published their findings. I took the time to clean up the code that we use to leave just the relevant parts and translate it (we speak Spanish, sorry for my English by the way), so if there are errors is because I made a typo while translating, please point them and I will correct them for the next one.
Let's get to how to do it, take into account that we use FlatDataSource as the data source for our WinPivotGrid, of course if you are using anything else you will have to adapt. Also as you can imagine the resulting Excel PivotTable does not look exactly the same as your report but is close and it will let you work with it.
1) The main problem to create the Export yourself is that Infragistics never introduced the ability to iterate over currently selected RowHeaders, ColumnHeaders and Measures, so there is no way for you to recreate the Pivot in Excel as is on the WinPivot because you don't know what the user has selected. Well, to be able to save and load a report as the user built-it Michael DiFilippo from Infragistics suggested to me to handle the following events (Thank God the guys from Infragistics in the Forums and handling Support Cases are always really nice, take the time to help and really know their stuff): AxisAddHierarchyAsyncCompleted AxisRemoveHierarchyAsyncCompleted AddFilterAsyncCompleted RemoveFilterAsyncCompleted AddMeasureAsyncCompleted RemoveMeasureAsyncCompleted
These events let you know when a RowHeader, ColumnHeader, Filter or Measure is being added or removed so you can keep track of the user selection reflecting the changes in your own lists. You can check this on the related post: http://ko.infragistics.com/community/forums/t/93336.aspx
2) Once you have that working, firstly make sure that you have Microsoft Office Interops installed and referenced in your project, then you just need to use Interops to create an Excel Book, transfer the data to one sheet, create a PivotTable pointing to that data and use your lists to populate the Pivot's Rows, Columns and Measures. Sounds easy right :). Attached is a text file with the code, some prerequisites/clarifications:
a) “ds” is the FlatDataSource that you are using for your WinPivotGrid (i.e. Dim ds As FlatDataSource.
b) “Rows”, “Cols” and “Measures” are the lists (List(Of String)) that hold the RowHeaders, ColumnHeaders and Measures that the user selected. Dim Rows As New List(Of String) Dim Cols As New List(Of String) Dim Measures As New List(Of String)
c) The FlatDataSource must have at least 1 item (ds.ItemSource(0))
I have also been waiting for a solution and been contacting the infragistics helpdesk a few times in regards to this features as well as others such as:
expand all columns/rows, columns/rows sorting, layout saving
Unfortunately their standard answer is always ask you to look at their ideas site to show you the ideas are already included and will be available in the "future".
For excel export, if you already have data binding to your data collection, you could do what I did by adding a copy contextmenu, and then structure your data collection into "," delimiter and put into clipboard. this way at least I allow user to paste it to excel.
Now, nearly a half year later my question: when will this idea be implemented?
Do you have a timeline?
Best regards,
Birgit