This is a migrated thread and some comments may be shown as answers.
export to excel header
8 Answers 103 Views
This is a migrated thread and some comments may be shown as answers.
Anjali
Top achievements
Rank 1
Anjali asked on 07 Jul 2011, 10:54 PM
Hello All,

  I exported the telerik grid to excel by using the command below

RadGrid_DetailsView.MasterTableView.ExportToExcel();

I want to set the header on each page that says
"This is the DRAFT Data".

How can I accomplish that.

Thanks.

8 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 1
answered on 08 Jul 2011, 05:04 AM
Hello Anjali,

Try the following code snippet in ExcelMLExportRowCreated event to set header for exported excel.

 

C#:
protected void RadGrid1_ExcelMLExportRowCreated(object sender, Telerik.Web.UI.GridExcelBuilder.GridExportExcelMLRowCreatedArgs e)
{
        if (e.RowType == Telerik.Web.UI.GridExcelBuilder.GridExportExcelMLRowType.HeaderRow)
        {
           e.Worksheet.WorksheetOptions.PageSetup.PageHeaderElement.Data = "This is the DRAFT Data";
        }
}

Thanks,
Princy.
0
Anjali
Top achievements
Rank 1
answered on 08 Jul 2011, 06:57 PM
Thanks Princy!! Everything worked like magic. I am also exporting the radgrid to MS word. I need to put the headers saying "This is draft data" on each page of the MS word document. How can I accomplish that?

Please let me know.

Thanks again for all your help.









0
Bruno
Top achievements
Rank 2
answered on 08 Jul 2011, 09:41 PM
Princy, this was a good one - thanks for that
I found that I can do the same in the ExcelMLWorkbookCreated event also but not sure if this is a better way
0
Accepted
Princy
Top achievements
Rank 1
answered on 11 Jul 2011, 05:30 AM
Hello Anjali,

Try the following code snippet to set header for exported Word.

C#:
protected void RadGrid1_PdfExporting(object sender, GridPdfExportingArgs e)
{
    e.RawHTML = "<div This is draft data</div>" + e.RawHTML;
}

Thanks,
Princy.
0
Anjali
Top achievements
Rank 1
answered on 11 Jul 2011, 10:06 PM
Thanks Princy!! Worked again.
0
Daniel
Telerik team
answered on 15 Jul 2011, 08:16 AM
Hello,

There are two minor issues in this code posted by Princy:
1) You have to use GridExporting event if you need to add code when exporting to Word
2) The starting tag of the DIV element is not closed properly.

Regards,
Daniel
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Anjali
Top achievements
Rank 1
answered on 15 Jul 2011, 05:35 PM
The div tag issue is minor. When i wrote the code, i fixed that in my code, but I tried to use Gridexporting event for expoting to word and i got the error that e.RawHTMl does not exists in GridExporting event so I ended up using pdfExporting event.

0
Daniel
Telerik team
answered on 18 Jul 2011, 10:44 AM
Hello Anjali,

PdfExporting event is meaningful only when exporting to PDF format. It is exposed to allow the user to access the HTML code before it is converted to binary.
GridExporting
event will be triggered for all export formats, including PDF export. Here, you can access the final output code before it is streamed to the file.
You can access the output code using:
- e.ExportOutput for GridExporting
- e.RawHTML for PdfExporting

Regards,
Daniel
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
Grid
Asked by
Anjali
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Anjali
Top achievements
Rank 1
Bruno
Top achievements
Rank 2
Daniel
Telerik team
Share this question
or