Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to justify paragraph within TextBox of RDLC Page.
In RDLC only left, Right and Center align is possible. There is no any provision for Justify.
Can you Please help me with some code or trick to do this.
Posted
Updated 26-Oct-18 8:07am
Comments
/\jmot 24-Sep-14 11:01am    
set the position of the textbox to center align.i think this'll help you.

=Code.JustifyTheText(First(Fields!FieldValue.Value, "DATASET"),310,100,0)
 
Share this answer
 
Comments
Adityatwr 30-Sep-14 7:51am    
I tried but there is a compile time error comes
[BC30451]'Code' is not declared or it may be inaccessible due to protection.

Thanks
Adityatwr 5-Oct-14 7:15am    
Hello,
CAn you please share,what you write in your code. Plzzz
Leena 206 6-Oct-14 1:53am    
check this: http://williameduardo.com/development/ssrs/how-to-justify-text-in-ssrs/
Adityatwr 6-Oct-14 5:30am    
When I go through your given link follow instruction step by step below listed errors comes Please help me.

Error1:Error while loading code module: ‘Ledgex.SSRS.CRI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’. Details: Could not load file or assembly 'Ledgex.SSRS.CRI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified. D:\Project(06-10-2014)\AD\RDLC\reports.rdlc AD

Error 2:Error in class instance declaration for class Ledgex.SRS.CRI.JustifyText: [BC30002] Type 'Ledgex.SRS.CRI.JustifyText' is not defined. D:\Project(06-10-2014)\AD\RDLC\reports.rdlc AD

Error 3:There is an error on line 4 of custom code: [BC30002] Type 'Ledgex.SSRS.CRI.JustifyText' is not defined. D:\Project(06-10-2014)\AD\RDLC\reports.rdlc
Member 13245937 20-Jun-17 19:44pm    
help me please how to add Code.JustifyTheText(First(Fields!FieldValue.Value, "DATASET"),310,100,0) in my rdlc report. I need justify a text
I made a function that convert a string into a list of strings so you can use it in a table wuth no header, in courier new font (same width character)

C#
        public static List<string> GetText(string text, int width)
        {
            string[] palabras = text.Split(' ');
            StringBuilder sb1 = new StringBuilder();
            StringBuilder sb2 = new StringBuilder();
            int length = palabras.Length;
            List<string> resultado = new List<string>();
            for (int i = 0; i < length; i++)
            {
                sb1.AppendFormat("{0} ", palabras[i]);
                if (sb1.ToString().Length > width)
                {
                    resultado.Add(sb2.ToString());
                    sb1 = new StringBuilder();
                    sb2 = new StringBuilder();
                    i--;
                }
                else
                {
                    sb2.AppendFormat("{0} ", palabras[i]);
                }
            }
            resultado.Add(sb2.ToString());

            List<string> resultado2 = new List<string>();
            string temp;

            int index1, index2, salto;
            string target;
            int limite = resultado.Count;
            foreach (var item in resultado)
            {
                target = " ";
                temp = item.ToString().Trim();
                index1 = 0; index2 = 0; salto = 2;

                if (limite <= 1)
                {
                    resultado2.Add(temp);
                    break;
                }
                while (temp.Length <= width)
                {
                    if (temp.IndexOf(target, index2) < 0)
                    {
                        index1 = 0; index2 = 0;
                        target = target + " ";
                        salto++;
                    }
                    index1 = temp.IndexOf(target, index2);
                    temp = temp.Insert(temp.IndexOf(target, index2), " ");
                    index2 = index1 + salto;

                }
                limite--;
                resultado2.Add(temp);
            }
            return resultado2;
        }
</string></string></string></string></string>


hope it helps!
 
Share this answer
 
v2
Comments
Shuan Lu 26-Oct-18 14:12pm    
Thanks, your solution really works.
Member 14080731 20-Mar-19 2:08am    
in my rdlc file this Solution not working
Solution 3 really works:
1.	Convert c# code to VB.net code, add function to rdlc custom code:
  Function GetText(text As String, width As Integer) As String
        Dim palabras As String() = text.Split(" "c)  'text-->palabras
        Dim sb1 As New System.Text.StringBuilder()
        Dim sb2 As New System.Text.StringBuilder()
        Dim length As Integer = palabras.Length     'palabras
        Dim resultado As New System.Collections.Generic.List(Of String)()
        Dim i As Integer = 0
        While i < length
            sb1.AppendFormat("{0} ", palabras(i))   'palabras
            If sb1.ToString().Length > width Then
                resultado.Add(sb2.ToString())
                sb1 = New System.Text.StringBuilder()
                sb2 = New System.Text.StringBuilder()
                System.Math.Max(System.Threading.Interlocked.Decrement(i), i + 1)
            Else
                sb2.AppendFormat("{0} ", palabras(i))
            End If
            System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)
        End While
        resultado.Add(sb2.ToString())               'resultado

        Dim resultado2 As New System.Collections.Generic.List(Of String)()
        Dim temp As String

        Dim index1 As Integer, index2 As Integer, salto As Integer
        Dim target As String
        Dim limite As Integer = resultado.Count     'resultado
        For Each item As String In resultado        'resultado
            target = " "
            temp = item.ToString().Trim()
            index1 = 0
            index2 = 0
            salto = 2

            If limite <= 1 Then
                resultado2.Add(temp)
                Exit For
            End If
            While temp.Length <= width
                If temp.IndexOf(target, index2) < 0 Then
                    index1 = 0
                    index2 = 0
                    target = target + " "
                    System.Math.Max(System.Threading.Interlocked.Increment(salto), salto - 1)
                End If
                index1 = temp.IndexOf(target, index2)
                temp = temp.Insert(temp.IndexOf(target, index2), " ")

                index2 = index1 + salto
            End While
            System.Math.Max(System.Threading.Interlocked.Decrement(limite), limite + 1)
            resultado2.Add(temp)
        Next

        Dim builder As New System.Text.StringBuilder()
        For Each item As String In resultado2
            builder.Append(item).Append(chr(10))
       Next
        Return builder.ToString()
    End Function

2.	Call custom code in rdlc
    Textbox=Code.GetText("longtext….",77)

3.	Set rdlc textbox font to be one of monospace font such as BatangChe,Consolas, Courier New, DFKai-SB, DotunChe, GulimChe, GungSahChe, KaiTi,Lucida Console,MingLiU,MS Gothic,MS MinChe,NSimSun,SimHei,Simplified Arabic Fixed,SimSun,SimSun-ExtB
 
Share this answer
 
Comments
CHill60 26-Oct-18 16:26pm    
This should really have been a comment against solution 3. You're just restating a solution that was posted earlier
Member 13456138 23-Nov-22 3:17am    
WIDTH??

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900