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

Radgrid Export to Excel title and landscape mode

1 Answer 186 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Charlie Brown
Top achievements
Rank 1
Charlie Brown asked on 12 Aug 2010, 03:13 PM
Hi,

Problem : 1
I want to export rad grid and i want custom title on radgrid.
I did try to use caption and caption displayed on UI but didnt display on Export to excel.
I like to show on Export to excel Like "Report Name : abc , Report Date : 08/12/10 " And some other criteria. Also caption height should be 5 px when export to excel. Because report has 30 columns and 65 rows and i need to fit in one page.

Problem : 2
I want the grid to be export in landscape mode so can you send me example code for that.(please look at my code that i am currently using). I need tiltle and export in landscape mode. 

Radgrid.MasterTableView.Caption = lblCaption

Protected Sub rgFlash_DataBound(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rgFlash.DataBound
        If Export = True Then
            rgFlash.ExportSettings.ExportOnlyData = True
            rgFlash.ExportSettings.FileName = "Report Name"
            rgFlash.ExportSettings.IgnorePaging = True
            rgFlash.ExportSettings.HideStructureColumns = True
            rgFlash.FilterMenu.Visible = False

            rgFlash.HeaderContextMenu.Visible = False
            rgFlash.EnableHeaderContextMenu = False
            rgFlash.EnableHeaderContextFilterMenu = False
            rgFlash.AllowSorting = False
            rgFlash.AllowPaging = False
            rgFlash.AllowFilteringByColumn = False
            rgFlash.MasterTableView.AllowFilteringByColumn = False
            rgFlash.MasterTableView.AllowSorting = False
            rgFlash.MasterTableView.AllowPaging = False
            rgFlash.MasterTableView.EnableHeaderContextFilterMenu = False
            rgFlash.MasterTableView.EnableHeaderContextMenu = False
        End If

        lblRecordCount.Text = "Records : " & recordcount

    End Sub

  Protected Sub rgFlash_GridExporting(ByVal source As System.Object, ByVal e As Telerik.Web.UI.GridExportingArgs) Handles radgrid.GridExporting
        'rgFlash.MasterTableView.Caption = Caption
        ExportDataGridToExcel(radgrid, Response)
    End Sub


    Public Sub ExportDataGridToExcel(ByVal ctrl As System.Web.UI.Control, ByVal response As System.Web.HttpResponse)

        response.Clear()

        response.Buffer = True

        response.Cache.SetCacheability(HttpCacheability.NoCache)

        response.ContentType = "application/vnd.ms-excel"

        response.AddHeader("content-disposition", "attachment;filename=Flash Report.xls")

        response.Charset = ""

        Me.EnableViewState = False

        Dim oStringWriter As New System.IO.StringWriter()

        Dim oHtmlTextWriter As New System.Web.UI.HtmlTextWriter(oStringWriter)

        'this.ClearControls(ctrl);

        ctrl.RenderControl(oHtmlTextWriter)

        ' set content type and character set to cope with european chars like the umlaut.

        response.Write("<meta http-equiv=Content-Type content=""text/html; charset=utf-8"">" & vbLf)

        ' add the style props to get the page orientation

        response.Write(AddExcelStyling())

        response.Write(oStringWriter.ToString())
        response.Write("</body>")
        response.Write("</html>")

        response.[End]()

    End Sub

    Private Function AddExcelStyling() As String
        ' add the style props to get the page orientation
        Dim sb As New StringBuilder()

        sb.Append("<html xmlns:o='urn:schemas-microsoft-com:office:office'" & vbLf + "xmlns:x='urn:schemas-microsoft-com:office:excel'" & vbLf + "xmlns='http://www.w3.org/TR/REC-html40'>" & vbLf + "<head>" & vbLf)

        sb.Append("<style>" & vbLf)

        sb.Append("@page")

        'page margin can be changed based on requirement.....

        sb.Append("{margin:.10in .10in .10in .10in;" & vbLf)

        sb.Append("mso-header-margin:.10in;" & vbLf)

        sb.Append("mso-footer-margin:.10in;" & vbLf)

        sb.Append("mso-height-source:96.75pt;" & vbLf)

        sb.Append("mso-page-orientation:landscape;}" & vbLf)



        sb.Append("</style>" & vbLf)

        sb.Append("<!--[if gte mso 9]><xml>" & vbLf)

        sb.Append("<x:ExcelWorkbook>" & vbLf)

        sb.Append("<x:ExcelWorksheets>" & vbLf)

        sb.Append("<x:ExcelWorksheet>" & vbLf)

        sb.Append("<x:Name>Flash Report</x:Name>" & vbLf)

        sb.Append("<x:WorksheetOptions>" & vbLf)

        sb.Append("<x:Print>" & vbLf)

        sb.Append("<x:ValidPrinterInfo/>" & vbLf)

        sb.Append("<x:PaperSizeIndex>9</x:PaperSizeIndex>" & vbLf)

        sb.Append("<x:HorizontalResolution>600</x:HorizontalResolution" & vbLf)

        sb.Append("<x:VerticalResolution>600</x:VerticalResolution" & vbLf)

        sb.Append("</x:Print>" & vbLf)

        sb.Append("<x:Selected/>" & vbLf)

        sb.Append("<x:DoNotDisplayGridlines/>" & vbLf)

        sb.Append("<x:ProtectContents>False</x:ProtectContents>" & vbLf)

        sb.Append("<x:ProtectObjects>False</x:ProtectObjects>" & vbLf)

        sb.Append("<x:ProtectScenarios>False</x:ProtectScenarios>" & vbLf)

        sb.Append("</x:WorksheetOptions>" & vbLf)

        sb.Append("</x:ExcelWorksheet>" & vbLf)

        sb.Append("</x:ExcelWorksheets>" & vbLf)

        sb.Append("<x:WindowHeight>12780</x:WindowHeight>" & vbLf)

        sb.Append("<x:WindowWidth>19035</x:WindowWidth>" & vbLf)

        sb.Append("<x:WindowTopX>0</x:WindowTopX>" & vbLf)

        sb.Append("<x:WindowTopY>0</x:WindowTopY>" & vbLf)

        sb.Append("<x:ProtectStructure>False</x:ProtectStructure>" & vbLf)

        sb.Append("<x:ProtectWindows>False</x:ProtectWindows>" & vbLf)

        sb.Append("</x:ExcelWorkbook>" & vbLf)

        sb.Append("</xml><![endif]-->" & vbLf)

       sb.Append("</head>" & vbLf)

        sb.Append("<body>" & vbLf)

        Return sb.ToString()

    End Function


Thanks for your all previous support and look at this issue.

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 16 Aug 2010, 11:15 AM
Hello Charlie,

Problem : 1
It is possible to insert the caption/report name manually:
// add the style props to get the page orientation
response.Write(AddExcelStyling());
response.Write("<span style='font-size: 7pt; font-family: Arial Narrow;'>" + RadGrid1.MasterTableView.Caption + "</span>");
response.Write(oStringWriter.ToString());
response.Write("</body>");
response.Write("</html>");
 
response.End();

Problem 2:
You can find the desired demo attached to this post.

Best regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Charlie Brown
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or