467,182 Members | 1,009 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,182 developers. It's quick & easy.

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
  • viewed: 5901
Share:
4 Replies
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Kevin | last post: by
3 posts views Thread by Conrad F | last post: by
4 posts views Thread by mark | last post: by
6 posts views Thread by Kevin Humphreys | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.