在SQL Reporting Services中对齐文本

时间:2012-06-21 07:41:05

标签: sql reporting-services report

有没有办法在SQL Reporting Services中完全证明文本?

我一直在搜索,似乎Reporting Services仍然不支持该功能,但是有没有解决方法?

我之前已经问过这个问题,但也许平均时间已经取得了进展。

7 个答案:

答案 0 :(得分:6)

这是不可能的,至少在SSRS 2008及更低版本中没有。对齐文本的唯一选项是“左”,“中”和“右”。

我能想到的唯一解决方法是在文本框中启用HTML标记,但忽略了Justify对齐的样式。所以没有任何合适的解决方法AFAIK,没有使用带有合理文本的图片(〜颤抖!〜)。

你应该留意corresponding MS feedback item,也许也要对它进行投票。它过去有527票,但在从MS Connect迁移到这个新的反馈站点时被重置为0。我通过this social.msdn thread找到了错误报告,该报告已经持续了一段时间。

答案 1 :(得分:1)

'SSRS中带有对齐文本的图片':您可以创建一个AdvRichTextBox控件(请参阅代码http://geekswithblogs.net/pvidler/archive/2003/10/14/182.aspx)并按照以下步骤在ssrs中使用它:http://binaryworld.net/Main/CodeDetail.aspx?CodeId=4049

答案 2 :(得分:1)

以下是可能的解决方法:Full Text Just

它利用RS实用程序和OLE自动化来完成这项工作。

答案 3 :(得分:0)

在标准中,SSRS不支持对齐。有可能解决这个问题:

  1. 使用第三方控件执行此操作:(我无法让其中一个工作。)
  2. 通过COM调用组件,如Word。 (这是一个安全问题,但可能。)
  3. 在HTML中格式化框并在单词之间放置小的空格。这可以在存储过程中完成。
  4. 解决方案3很详细地描述。这就是我将我的解决方案免费下载到我的网页上的原因。

    我的解决方案的优点是,无需安装。

    以下是我的解决方案的链接:http://www.rupert-spaeth.de/justify/

答案 4 :(得分:0)

如果您使用<p>尝试使用:

$("[style*='padding-bottom:10pt']").css("text-align", "justify");

答案 5 :(得分:0)

如果打开.rdl代码文件(即xml),则以下内容将起作用。

您需要一个段落标记(如果尚不存在)。

这会格式化数字以使用逗号(美式风格),小数点后两位。

然后通过Right标签对它进行右对齐{我一直在寻找对齐标签,但是它是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>     

答案 6 :(得分:0)

实际上,如果您将值作为HTML传递,并且之前使用某种格式将文本格式化为辩解html文本,则有可能在SSRS报告中对文本进行对齐,在我的情况下,我使用.NET C#将传递的字符串格式化为对正html文字。

但是在此之前,我们需要配置SSRS报告以接受HTML,为此,我们需要添加一个文本框并创建一个占位符。

要添加占位符,请在文本框上单击,直到它允许您向其中写入文本,然后右键单击并选择“创建占位符...”

Create place holdder

创建占位符后,系统将提示您输入占位符的属性,您只需指定“值”和“标记类型”

Placeholder properties

请确保将标记类型选择为HTML,并为该值指定在我们的示例中具有合理的html文本的变量,将其命名为transformdHtml。

现在,我们需要创建一个函数,将字符串转换为合理的HTML文本

    /// <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;
    }

通过使用此功能,我们可以将任何字符串转换为对齐的文本,并且可以选择是否要输出为HTMl或简单字符串

然后我们可以像

一样调用此方法
        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);

我们得到以下输出:

在C#中

dotnet view

在SSRS中

SSRS view

现在,此示例主要说明如果将值从C#代码传递到ssrs报告,如何获取对齐的文本,但是如果您在以相同方式格式化任何文本的存储过程中使用相同的功能,则可以实现此目的。希望这对某人有帮助。