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

2 posts, 0 answers
  1. DHHS
    DHHS avatar
    59 posts
    Member since:
    Mar 2015

    Posted 29 Jun Link to this post

    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' />");
    // 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>" +
               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?



  2. Kostadin
    Kostadin avatar
    1693 posts

    Posted 04 Jul Link to this post


    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.
    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.

    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  3. DevCraft R3 2016 release webinar banner
Back to Top