Solved

ASP.Net export multiple gridview to one excel sheet

Posted on 2013-01-28
2
908 Views
Last Modified: 2013-02-13
I have an ASP.Net page (C# code behind). The page had 4 gridviews on it, each showing records based on who is logged in. What I want to do is take the contents of each grid and export them to the same excel spreadsheet sheet. Is there a way to do this? Possibly tell it to export each grid to a different cell range? Thanks for any help.
0
Comment
Question by:dodgerfan
2 Comments
 
LVL 16

Assisted Solution

by:Kamal Khaleefa
Kamal Khaleefa earned 250 total points
ID: 38829870
Hi

you can export each one to separate excel sheet or you can export all of them to one excel sheet

what you can do is to join all the data tables into one table

for example
 gridview1 datasource is dt1
 gridview2 datasource is dt2
 gridview3 datasource is dt3
 gridview4 datasource is dt4

in code behind create a new data table and add all the dt's to It

then export this dt to one excel sheet
Thanks
0
 
LVL 14

Accepted Solution

by:
binaryevo earned 250 total points
ID: 38830740
I personally use the OpenXML standards for newer versions of Office ( Im pretty sure 2007+ work with OpenXML ).  You can either do one of two things with this approach, code it manually ( not recommended as it is very time consuming ) or you can simply utilize a wrapper.  The wrapper I use is called closed XML ( http://closedxml.codeplex.com ) and is very easy to implement.  The closed xml wrapper will handle all of your requirements and more... I typically add sorting functionality on exports and header formatting when it makes sense.  Take a look at the link there is a plethora of cool stuff you can do with this library.

Hope this helps
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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…

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