By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,137 Members | 2,209 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,137 IT Pros & Developers. It's quick & easy.

exporting mutiple datagrids on different sheets of a same excel fi

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.