Rotated Text Solution

Last post 08-09-2007 11:40 AM by Leonscape. 0 replies.

Sort Posts:

  • Rotated Text Solution

    08-09-2007, 11:40 AM
    • Loading...
    • Leonscape
    • Joined on 08-09-2007, 11:21 AM
    • Posts 1

    Hi,

    This is a simple solution to solving the problem of displaying rotated text in the crystalreportviewer. It only works in IE but with some tweaking and this ( ) you could adapt it to do a some more.

    This first thing you need to do is create some css classes to do the rotation:

    /* Rotating Text 90 degrees */
    .reportView .rotate90 { writing-mode: tb-rl;    filter: flipv fliph; text-align: center; }
    .reportView .rotate90L { writing-mode: tb-rl;    filter: flipv fliph; text-align: left; }
    .reportView .rotate90R { writing-mode: tb-rl;    filter: flipv fliph; text-align: right; }
    .reportView .rotate90J { writing-mode: tb-rl;    filter: flipv fliph; text-align: justify; }

    /* Rotate Text 270 degrees */
    .reportView .rotate270 { writing-mode: tb-rl;    text-align: center; }
    .reportView .rotate270L { writing-mode: tb-rl; text-align: left; }
    .reportView .rotate270R {    writing-mode: tb-rl; text-align: right; }
    .reportView .rotate270J {    writing-mode: tb-rl; text-align: justify; }

    There are multiple versions of the classes to cope with the fact that crystal will remove formatting from the report if you set a cssclassname.

    Now at this point you could simply use these classes directly in the report, setting the class names in the rotated text, or you can do it
    magically server side in the BeforeObjectRender event of the viewer. example below for a viewer called c_viewer in VB.NET

    Protected Sub c_viewer_BeforeRenderObject(ByVal source As Object, ByVal e As CrystalDecisions.Web.HtmlReportRender.BeforeRenderObjectEvent) Handles c_viewer.BeforeRenderObject
            'Make sure where dealing with the right type of object
            If TypeOf e.Object Is ViewerObjectModel.ReportObjectInstance Then
                Dim ro As ViewerObjectModel.ReportObjectInstance = DirectCast(e.Object, ViewerObjectModel.ReportObjectInstance)
                Dim cls As String = String.Empty
               
                ' Check for rotation
                Select Case ro.ObjectFormat.Rotation
                    Case 90
                        cls = "rotate90"
                    Case 270
                        cls = "rotate270"
                End Select
               
                If cls <> String.Empty Then
                        ' addin for dealing with alignment
                    Select Case ro.ObjectFormat.HorizontalAlignment
                        Case Alignment.LeftAlign, Alignment.DefaultAlign
                            cls &= "L"
                        Case Alignment.RightAlign
                            cls &= "R"
                        Case Alignment.Justified
                            cls &= "J"
                    End Select
                   
                    'We already have a class
                    If Not String.IsNullOrEmpty(ro.ObjectFormat.StyleSheetName) Then
                            ' have we already been here before
                        If ro.ObjectFormat.StyleSheetName.Contains(cls) Then
                            cls = ro.ObjectFormat.StyleSheetName()
                        Else
                            cls = ro.ObjectFormat.StyleSheetName & " " & cls
                        End If
                    End If
                    ro.ObjectFormat.StyleSheetName = cls
                End If
            End If
        End Sub

Page 1 of 1 (1 items)
Microsoft Communities
Page view counter