473,418 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

exporting mutiple datagrids on different sheets of a same excel fi

Hi,
I have three datagrid control on my aspx page and one export to excel
button, i want to export all the 3 datagrids contents in one excel file. how
can i achive that?
--
Thanks
Hitesh
Nov 18 '05 #1
4 6169
You could try something of this kind.

DataGridItemCollection dgItem1 = DataGrid1.Items;
DataGridItemCollection dgItem2 = DataGrid2.Items;
DataGridItemCollection dgItem3 = DataGrid3.Items;

System.IO.FileStream f = new
System.IO.FileStream("c:\\Text1.csv",System.IO.Fil eMode.OpenOrCreate,System.
IO.FileAccess.Write);
System.IO.StreamWriter sr = new System.IO.StreamWriter(f);
string strOutput = "";

strOutput = "";
strOutput = strOutput + DataGrid1.Columns[1].HeaderText + ",";
sr.WriteLine(strOutput);

foreach(DataGridItem dgi1 in dgItem1)
{
strOutput = "";
strOutput = dgi1.Cells[0].Text + ",";
strOutput = strOutput + dgi1.Cells[1].Text ;
sr.WriteLine(strOutput);
}

foreach(DataGridItem dgi2 in dgItem2)
{
strOutput = "";
strOutput = dgi2.Cells[0].Text + ",";
strOutput = strOutput + dgi2.Cells[1].Text ;
sr.WriteLine(strOutput);
}

foreach(DataGridItem dgi3 in dgItem3)
{
strOutput = "";
strOutput = dgi3.Cells[0].Text + ",";
strOutput = strOutput + dg3i.Cells[1].Text ;
sr.WriteLine(strOutput);
}

sr.Close();

Regards,
--
Tarkeshwar
..Net Programmer
Fifth Generation Technologies

"Hitesh" <Hi****@discussions.microsoft.com> wrote in message
news:84**********************************@microsof t.com...
Hi,
I have three datagrid control on my aspx page and one export to excel
button, i want to export all the 3 datagrids contents in one excel file. how can i achive that?
--
Thanks
Hitesh

Nov 18 '05 #2
Hi Tarakeshwar,
Thanks for your suggestion yaa that will do the job of exporting multiple
datagrid's contents on one excel sheet, but the problem is all the data will
come on one single sheet only (data will be appended one below another), i
want the data for each datagrid to be on seprate sheets in the same excel
file and secondlly i am using an ASP.NET application.
So, can you help me out further, in achiving that.

Thanks and Regards
Hitesh Jain

"Tarakeshwar L" wrote:
You could try something of this kind.

DataGridItemCollection dgItem1 = DataGrid1.Items;
DataGridItemCollection dgItem2 = DataGrid2.Items;
DataGridItemCollection dgItem3 = DataGrid3.Items;

System.IO.FileStream f = new
System.IO.FileStream("c:\\Text1.csv",System.IO.Fil eMode.OpenOrCreate,System.
IO.FileAccess.Write);
System.IO.StreamWriter sr = new System.IO.StreamWriter(f);
string strOutput = "";

strOutput = "";
strOutput = strOutput + DataGrid1.Columns[1].HeaderText + ",";
sr.WriteLine(strOutput);

foreach(DataGridItem dgi1 in dgItem1)
{
strOutput = "";
strOutput = dgi1.Cells[0].Text + ",";
strOutput = strOutput + dgi1.Cells[1].Text ;
sr.WriteLine(strOutput);
}

foreach(DataGridItem dgi2 in dgItem2)
{
strOutput = "";
strOutput = dgi2.Cells[0].Text + ",";
strOutput = strOutput + dgi2.Cells[1].Text ;
sr.WriteLine(strOutput);
}

foreach(DataGridItem dgi3 in dgItem3)
{
strOutput = "";
strOutput = dgi3.Cells[0].Text + ",";
strOutput = strOutput + dg3i.Cells[1].Text ;
sr.WriteLine(strOutput);
}

sr.Close();

Regards,
--
Tarkeshwar
..Net Programmer
Fifth Generation Technologies

"Hitesh" <Hi****@discussions.microsoft.com> wrote in message
news:84**********************************@microsof t.com...
Hi,
I have three datagrid control on my aspx page and one export to excel
button, i want to export all the 3 datagrids contents in one excel file.

how
can i achive that?
--
Thanks
Hitesh


Nov 18 '05 #3
In that case you have to create an object for an excel application, create
an object for every sheet, and then add data to each sheet. You could go
thru msdn, which has examples on creating excel sheets in dotnet.

http://msdn.microsoft.com/office/und...l/excelobj.asp

Use this link to create workbook object and try using it from there.

--
Tarkeshwar
..Net Programmer
Fifth Generation Technologies

"Hitesh" <Hi****@discussions.microsoft.com> wrote in message
news:D7**********************************@microsof t.com...
Hi Tarakeshwar,
Thanks for your suggestion yaa that will do the job of exporting multiple
datagrid's contents on one excel sheet, but the problem is all the data will come on one single sheet only (data will be appended one below another), i
want the data for each datagrid to be on seprate sheets in the same excel
file and secondlly i am using an ASP.NET application.
So, can you help me out further, in achiving that.

Thanks and Regards
Hitesh Jain

"Tarakeshwar L" wrote:
You could try something of this kind.

DataGridItemCollection dgItem1 = DataGrid1.Items;
DataGridItemCollection dgItem2 = DataGrid2.Items;
DataGridItemCollection dgItem3 = DataGrid3.Items;

System.IO.FileStream f = new
System.IO.FileStream("c:\\Text1.csv",System.IO.Fil eMode.OpenOrCreate,System. IO.FileAccess.Write);
System.IO.StreamWriter sr = new System.IO.StreamWriter(f);
string strOutput = "";

strOutput = "";
strOutput = strOutput + DataGrid1.Columns[1].HeaderText + ",";
sr.WriteLine(strOutput);

foreach(DataGridItem dgi1 in dgItem1)
{
strOutput = "";
strOutput = dgi1.Cells[0].Text + ",";
strOutput = strOutput + dgi1.Cells[1].Text ;
sr.WriteLine(strOutput);
}

foreach(DataGridItem dgi2 in dgItem2)
{
strOutput = "";
strOutput = dgi2.Cells[0].Text + ",";
strOutput = strOutput + dgi2.Cells[1].Text ;
sr.WriteLine(strOutput);
}

foreach(DataGridItem dgi3 in dgItem3)
{
strOutput = "";
strOutput = dgi3.Cells[0].Text + ",";
strOutput = strOutput + dg3i.Cells[1].Text ;
sr.WriteLine(strOutput);
}

sr.Close();

Regards,
--
Tarkeshwar
..Net Programmer
Fifth Generation Technologies

"Hitesh" <Hi****@discussions.microsoft.com> wrote in message
news:84**********************************@microsof t.com...
Hi,
I have three datagrid control on my aspx page and one export to excel
button, i want to export all the 3 datagrids contents in one excel
file. how
can i achive that?
--
Thanks
Hitesh


Nov 18 '05 #4
Hi Tarakeshwar,
Thank you very much for pointing to the right thing, finally what you had
suggested given me enough to do the task. One question that i want to ask is,
in this case we definetely needs the Microsoft Excel on the server Is there
anyway where we do not required the Microsoft Excel on the server and still
we can achive the task?
Thanks & Regards
Hitesh Jain

"Tarakeshwar L" wrote:
In that case you have to create an object for an excel application, create
an object for every sheet, and then add data to each sheet. You could go
thru msdn, which has examples on creating excel sheets in dotnet.

http://msdn.microsoft.com/office/und...l/excelobj.asp

Use this link to create workbook object and try using it from there.

--
Tarkeshwar
..Net Programmer
Fifth Generation Technologies

"Hitesh" <Hi****@discussions.microsoft.com> wrote in message
news:D7**********************************@microsof t.com...
Hi Tarakeshwar,
Thanks for your suggestion yaa that will do the job of exporting multiple
datagrid's contents on one excel sheet, but the problem is all the data

will
come on one single sheet only (data will be appended one below another), i
want the data for each datagrid to be on seprate sheets in the same excel
file and secondlly i am using an ASP.NET application.
So, can you help me out further, in achiving that.

Thanks and Regards
Hitesh Jain

"Tarakeshwar L" wrote:
You could try something of this kind.

DataGridItemCollection dgItem1 = DataGrid1.Items;
DataGridItemCollection dgItem2 = DataGrid2.Items;
DataGridItemCollection dgItem3 = DataGrid3.Items;

System.IO.FileStream f = new
System.IO.FileStream("c:\\Text1.csv",System.IO.Fil eMode.OpenOrCreate,System. IO.FileAccess.Write);
System.IO.StreamWriter sr = new System.IO.StreamWriter(f);
string strOutput = "";

strOutput = "";
strOutput = strOutput + DataGrid1.Columns[1].HeaderText + ",";
sr.WriteLine(strOutput);

foreach(DataGridItem dgi1 in dgItem1)
{
strOutput = "";
strOutput = dgi1.Cells[0].Text + ",";
strOutput = strOutput + dgi1.Cells[1].Text ;
sr.WriteLine(strOutput);
}

foreach(DataGridItem dgi2 in dgItem2)
{
strOutput = "";
strOutput = dgi2.Cells[0].Text + ",";
strOutput = strOutput + dgi2.Cells[1].Text ;
sr.WriteLine(strOutput);
}

foreach(DataGridItem dgi3 in dgItem3)
{
strOutput = "";
strOutput = dgi3.Cells[0].Text + ",";
strOutput = strOutput + dg3i.Cells[1].Text ;
sr.WriteLine(strOutput);
}

sr.Close();

Regards,
--
Tarkeshwar
..Net Programmer
Fifth Generation Technologies

"Hitesh" <Hi****@discussions.microsoft.com> wrote in message
news:84**********************************@microsof t.com...
> Hi,
> I have three datagrid control on my aspx page and one export to excel
> button, i want to export all the 3 datagrids contents in one excel file. how
> can i achive that?
> --
> Thanks
> Hitesh


Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Kevin | last post by:
I'm using a bit of code I wrote awhile ago to render datagrids to Excel spreadsheets through the browser. The code works great until the number of rows in the datagrid gets large (approx. 5000),...
3
by: Conrad F | last post by:
Hello All, I know how to import a specific named excel sheet into a datagrid using ADO.NET by setting up a JET connection and then SELECTing data from the sheet. However, for a real world...
4
by: mark | last post by:
(windows app not web) I have a procedure to populate a given datagrid (Datagrid1) with a dataset from an indexed data connection. It works: Globals: Dim FileName1 As String Dim DS As...
6
by: Kevin Humphreys | last post by:
Hi There, I am trying to export a recordset to an excel file using the Content Type below in the header. Response.ContentType = "application/vnd.ms-excel" Which works fine however the...
3
by: devolper | last post by:
I am devolping a web application which which .net reports to a excel work book .each report in one excel sheet.i am using the following code.......... Dim objDestinationExcel As New...
3
by: Hiranmoy | last post by:
I have created four query that gives four different output. Then I have created four macros from that query to export that reports to excel and it is giving four different excel file. Is it possible...
12
by: TARHEELS721 | last post by:
I am trying to send the results of a query that runs when I click a button on my form that is based on a parameter query. The code runs without any errors but nothing is exported into my excel...
2
by: atlbearcat | last post by:
Here's one that's been bugging me for about a week now... I have a form that allows users to filter records, simple enough. But I want to give them the option to export the filtered records to...
3
by: Tempalli | last post by:
I am exporting the data from ms access to excel where the error displays as Run-time error -2147467259(800004005) Method 'Copyfromrecordset' of object 'Range' faild. ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.