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

rad grid export to word - not able to attach content at the end

1 Answer 62 Views
Grid
This is a migrated thread and some comments may be shown as answers.
DHHS
Top achievements
Rank 1
DHHS asked on 30 Jun 2016, 02:19 AM

I have a rad grid and I am trying to export to word. I have few issue with it

1. I am able to export the grid and would like to add some extra content at the end of the document.  I have tried below code but the html is coming at the top of the document but I would like to get the content at the end of the document.

 

protected void alllGrid_Exporting(object sender, GridExportingArgs e)
    {
        if (e.ExportType == ExportType.Word)
        {
// this is for trying orientation landscape
            e.ExportOutput = e.ExportOutput.Replace("<body>", "<body><div class=WordSection1>");
            e.ExportOutput = e.ExportOutput.Replace("</body>", "</div></body>");
            string css = "<style> table @page{ mso-page-orientation:landscape;}</style>";
             
            StringBuilder pageBrk = new StringBuilder();
 
// this is for page break
            pageBrk.Append("<br clear='all' style='mso-special-character: line-break; page-break-before: always' />");
            pageBrk.Append(css);
 
// this actual html content which is rendering properly but at the top of the page
            var customHTML = AdHocFilterSummary().Append(pageBrk);
            e.ExportOutput = e.ExportOutput.Replace("<body>", "<body>" + customHTML);
        }
}

 

2. I am trying to do orientation as landscape but I am not able to make it work. I have used the below code given in one of the forums but couldn't make it work. Am I missing something here?

protected void alllGrid_HTMLExporting(object sender, GridHTMLExportingEventArgs e)
   {
        
       e.Styles.Append("th { text-align:center; font-color:green; }");
       if (Response.ContentType.Contains("excel"))
       {
           e.Styles.Append("<!--table @page { mso-page-orientation:landscape;} -->");
 
           e.XmlOptions = "<xml><x:ExcelWorkbook>" +
                           "<x:ExcelWorksheets><x:ExcelWorksheet><x:WorksheetOptions>" +
                           "<x:Print><x:ValidPrinterInfo/></x:Print>" +
                           "</x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets>" +
                           "</x:ExcelWorkbook></xml>";
       }
       else
       {
           e.Styles.Append("<!-- @page WordSection1 { size: 297mm 210mm; margin:1.0in 2.0in 1.0in 2.0in; }" +
                "div.WordSection1 {page:WordSection1;} -->");
       }
   }

 

 

 

 3. I am trying to get the same thing on excel too. No matter what i do, I am not getting anything on Excel. I am using ExcelML format. Is there any special way to do it?

 

Thanks.

1 Answer, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 04 Jul 2016, 12:32 PM
Hi,

Straight to your questions.
  1. In order to add additional content after the exported document you need to add it after the cosing body tag. Please try the following approach.
    e.ExportOutput = e.ExportOutput.Replace("</body>", "</body>" + customHTML)
  2. Note that not all global styles could be applied to both Word and Excel and some of them works only for the specific format. Nevertheless, you can try adding the style as follow.
    e.Styles.AppendFormat("@page{{mso-page-orientation:landscape;}}");
  3. If you are using ExcelML you could check out the following forum post which elaborates more on setting a page orientation. Nevertheless, this export format does not allow to insert additional information in the Export document since its engine builds the output directly from the datasource and not from the page. For this purpose you need to use HTML based export format when exporting the grid to Excel.


Regards,
Kostadin
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Grid
Asked by
DHHS
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Share this question
or