This is a migrated thread and some comments may be shown as answers.

Export to excel

3 Answers 34 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ramkumar
Top achievements
Rank 1
ramkumar asked on 14 Nov 2011, 06:34 AM
Hi All,

When we try to Export  radGrid  to Excel , we  need to export grid along with custom  header .
eg:
header:
name:dddd
age:28
place:chennai

then grid.....


Please advice.

3 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 14 Nov 2011, 07:09 AM
Hello ramkumar,

protected void RadGrid1_GridExporting(object source, GridExportingArgs e)
    {
        string customHTML = "<div width=\"100%\" style=\"text-align:center;font-size:12px;font-family:Verdana;\">Custom Report</div>";
       
 
        e.ExportOutput = e.ExportOutput.Replace("<body>", String.Format("<body>{0}", customHTML));
    }


Thanks,
Jayesh Goyani
0
ramkumar
Top achievements
Rank 1
answered on 30 Nov 2011, 04:45 AM
Thanks  for your Replay.

but it does not work with PDF

my code:

protected

 

void RadGrid1_GridExporting(object source, GridExportingArgs e)

 

{

#region

 

Grab Info from DB

 

 

string sql = "SELECT [GridNo],[ReportName],[Other],[GenerateBy] FROM [GridHeader] where Gid='1'";

 

 

SqlDataReader dr = DataAccess.ExecuteReader(CommandType.Text, sql, null);

 

 

if (dr.Read())

 

{

ReportName = dr.GetString(dr.GetOrdinal(

"ReportName"));

 

Other = dr.GetString(dr.GetOrdinal(

"Other"));

 

GenerateBy = dr.GetBoolean(dr.GetOrdinal(

"GenerateBy"));

 

}

 

#endregion

 

 

string customHTML = "<div width=\"100%\" style=\"text-align:center;font-size:8px;font-family:Tahoma;\">" +

 

 

" <table width='100%'border='0'>" +

 

 

"<tr><td colspan='7' style=\"text-align:left;font-size:12px;font-family:Tahoma;\" ><b>Company Name :</b>" + Session["CompanyName"].ToString() + "</td></tr> " +

 

 

"<tr><td colspan='7' style=\"text-align:left;font-size:12px;font-family:Tahoma;\" ><b>Report Name:</b>" + ReportName + "</td></tr> "+

 

 

"<tr><td colspan='7' style=\"text-align:left;font-size:12px;font-family:Tahoma;\" ><b>Date:</b>" + DateTime.Now.ToString("d",CultureInfo.CreateSpecificCulture("en-NZ")) +"</td></tr> ";

 

 

if (Other != "")

 

{

customHTML1 =

"<tr><td colspan='7' style=\"text-align:left;font-size:12px;font-family:Tahoma;\" ><b>Note :</b>" + Other + "</td></tr> ";

 

}

 

else

 

{

customHTML1 =

"";

 

}

 

if (GenerateBy)

 

{

customHTML2 =

"<tr><td colspan='7' style=\"text-align:left;font-size:12px;font-family:Tahoma;\" ><b>Generated By :</b>" + Session["Emp_Name"].ToString() + "</td></tr> ";

 

}

 

else

 

{

customHTML2 =

"";

 

}

 

customHTML3 =

"</table>"+

 

 

"</div>";

 

e.ExportOutput = e.ExportOutput.Replace(

"<body>", String.Format("<body>{0}", customHTML + customHTML1 + customHTML2+customHTML3));

 

}

Please help me in Exporting PDF.

0
Shinu
Top achievements
Rank 1
answered on 30 Nov 2011, 05:36 AM
Hello Ramkumar,

When exporting HTML tables, the table should define <colgroup> and <col> elements. Check the following help documentation which explains more about this.
PDF export

-Shinu.
Tags
Grid
Asked by
ramkumar
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
ramkumar
Top achievements
Rank 1
Shinu
Top achievements
Rank 1
Share this question
or