exporting mutiple datagrids on different sheets of a same excel fi

G

Guest

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?
 
T

Tarakeshwar L

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.FileMode.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,
 
G

Guest

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 said:
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.FileMode.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,
 
T

Tarakeshwar L

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/un...brary/en-us/odc_vsto2003_ta/html/excelobj.asp

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

--
Tarkeshwar
..Net Programmer
Fifth Generation Technologies

Hitesh said:
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 said:
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.FileMode.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 said:
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?
 
G

Guest

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 said:
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/un...brary/en-us/odc_vsto2003_ta/html/excelobj.asp

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

--
Tarkeshwar
..Net Programmer
Fifth Generation Technologies

Hitesh said:
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 said:
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.FileMode.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

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top