Justify text in SQL Reporting Services
Asked Answered
C

7

13

Is there a way of fully-justifying text in SQL Reporting Services?

I've been searching around and it seems the feature is still not supported by Reporting Services, but are there any workarounds?

I know this question has been asked before, but maybe progress has been made in the mean time.

Cantatrice answered 21/6, 2012 at 7:41 Comment(5)
How do you mean? You can justify text in textbox/tablix controls just like you can in any other rich text editor.. I'm guessing I'm missing something - but what is it? edit: Note, I'm using SQL Server Reporting Services 2008R2Balkanize
Thanks for the reply. Can you please give me a link which confirms this feature? Because all the information I am finding says that it is still an unsupported feature e.g. social.msdn.microsoft.com/Forums/en-US/sqlreportingservices/…Cantatrice
Do you mean full-justification, as opposed to left or right justification?Fahrenheit
What versions are you after? In SSRS-2008 this is not possible.Lavonna
I'm after full justification of text. I couldn't find any support for it but was hoping there would be some workaroundCantatrice
L
7

This is not possible, at least not in SSRS 2008 and below. The only options for aligning text are Left, Center and Right.

The only workaround I could think of was enabling HTML tags in a text box, but the styling for Justify alignment is just ignored. So there really aren't any suitable workarounds AFAIK, short of using picture with justified text (~shudder!~).

You should keep an eye on the corresponding MS feedback item and perhaps vote on it as well. It used to have 527 votes, but was reset to 0 during the move from MS Connect to this new feedback site. I found the bug report through this social.msdn thread, which has been going on for quite some time.

Lavonna answered 22/6, 2012 at 13:42 Comment(0)
N
1

'picture with justified text in SSRS': you can create a AdvRichTextBox control (see code http://geekswithblogs.net/pvidler/archive/2003/10/14/182.aspx ) and use it in ssrs following these steps : http://binaryworld.net/Main/CodeDetail.aspx?CodeId=4049

Nor answered 17/7, 2013 at 15:42 Comment(0)
F
1

Here's a possible workaround : Full Text Just

It makes use of RS utility and OLE Automation to do the job.

Fancy answered 18/3, 2015 at 17:58 Comment(0)
N
0

In Standard, SSRS does not Support justify. There are possibilities to work around:

  1. Use a third party control doing this: (I was not able to get one to work.)
  2. Call a component via COM like Word. (Is a security issue, but possible.)
  3. Format the box in HTML and put small white spaces between the words. This can be done in a stored procedure.

The solution 3 is very long to describe in detail. This is the reason why I put my solution for free download on my web page.

The advantage of my solution is, that there is no installation necessary.

Here is the link to my solution: http://www.rupert-spaeth.de/justify/

Nonego answered 28/11, 2016 at 20:16 Comment(0)
E
0

If you use <p> try with:

$("[style*='padding-bottom:10pt']").css("text-align", "justify");
Edwardedwardian answered 20/5, 2017 at 22:46 Comment(0)
H
0

The following will work if you open the .rdl code file (which is xml).

You need a paragraph tag, if it doesn't already exist.

This formats a number to use commas (U.S. style) with two points after the decimal place.

It is then right-justified by the Right tag {I had been looking for a justify tag, but it is TextAlign}

         <Paragraph>
            <TextRuns>
              <TextRun>
                <Value>=Format( Sum(Fields!ourField.Value, "DataSet2") , "N2") </Value>
                <Style>
                  <FontFamily />
                  <Color>White</Color>
                </Style>
              </TextRun>
            </TextRuns>
            <Style>
              <TextAlign>Right</TextAlign>
            </Style>
          </Paragraph>     
Hermaphroditism answered 7/11, 2018 at 21:40 Comment(0)
T
0

Actually its possible to Justify text in SSRS report if you pass the value as HTML and use something to format the text into justify'ed html text before, in my case im using .NET C# to format the passed string to justified html text.

But before that we need to to configure our SSRS report to accept HTML for this we need to add a text box and create a placeholder.

to add a place holder click on the textbox until it lets you write text to it then right click and choose "Create placeholder..."

Create place holdder

After you created the place holder you will be prompted to enter the properties of the placeholder, all you need to specify is Value and Markup type

Placeholder properties

be sure to select the Markup type as HTML and for the value specify the variable that will have the justified html text in our case lets call it transformedHtml.

Now we need to create a function that trasforms our string to justified HTML text

    /// <summary>
    /// 
    /// </summary>
    /// <param name="text">The text that we want to justify</param>
    /// <param name="width">Justified text width in pixels</param>
    /// <param name="useHtmlTagsForNewLines">if true returns the output as justified html if false returns the ouput as justified string</param>
    /// <returns>Justified string</returns>
    public string GetText(string text, int width, bool useHtmlTagsForNewLines = false)
    {
        var palabras = text.Split(' ');
        var sb1 = new StringBuilder();
        var sb2 = new StringBuilder();
        var length = palabras.Length;
        var resultado = new List<string>();

        var graphics = Graphics.FromImage(new Bitmap(1, 1));
        var font = new Font("Times New Roman", 11);

        for (var i = 0; i < length; i++)
        {
            sb1.AppendFormat("{0} ", palabras[i]);
            if (graphics.MeasureString(sb1.ToString(), font).Width > width)
            {
                resultado.Add(sb2.ToString());
                sb1 = new StringBuilder();
                sb2 = new StringBuilder();
                i--;
            }
            else
            {
                sb2.AppendFormat("{0} ", palabras[i]);
            }
        }
        resultado.Add(sb2.ToString());

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

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

            if (limite <= 1)
            {
                resultado2.Add(temp);
                break;
            }
            while (graphics.MeasureString(temp, font).Width <= 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);
        }
        var res = string.Join(useHtmlTagsForNewLines ? "<br> " + Environment.NewLine : "\n", resultado2);

        if (useHtmlTagsForNewLines)
            res = $"<div>{res.Replace(" ", "&nbsp;").Replace("<br>&nbsp;", "<br>")}</div>";

        return res;
    }

By using this function we can transform any string to justified text and we can select if we want the output to be HTMl or simple string

then we can just call this method like

        string text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
        string transformedHtml = GetText(text, 350, true);

and we get the output as folows:

In C#

dotnet view

In SSRS

SSRS view

Now this example mainly shows how to get justified text if your passing the values from C# code to ssrs reports but you could acchieve this if you would make the same function in a stored procedure that formats any text the same way. Hope this helps someone.

Tidewaiter answered 20/5, 2020 at 11:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.