SSRS:2005,CSS 未应用于第一列

发布于 2024-07-26 21:29:44 字数 704 浏览 5 评论 0原文

我们的一些报告在 Firefox 中无法正确显示 - 第一列缺少任何 CSS。 经过调查,我发现:

<tr>
  <td style="HEIGHT:6.93mm" style="...">1st Column</td>
  <td style="...">2nd Column</td>
  <td style="...">3rd Column</td>
</tr>

当我删除 style="HEIGHT:6.93mm" 时,它在 Firefox 中正确呈现。

根据 JudyX 的帖子此处2006 年 2 月 13 日星期一晚上 11:54

报告中第一列的样式无法正确设置。 报表查看器控件要求为所有表行指定“高度”。 不幸的是,它不会将此应用于表行元素,而是应用于该行中的第一个表单元格。 当它将其应用为样式属性时,它与我们在其他地方设置的样式冲突。

有没有人找到解决这个问题的方法?

Some of our reports aren't displaying properly in Firefox - the first column lacks any css. After investigating, I'm finding:

<tr>
  <td style="HEIGHT:6.93mm" style="...">1st Column</td>
  <td style="...">2nd Column</td>
  <td style="...">3rd Column</td>
</tr>

When I remove the style="HEIGHT:6.93mm", it renders properly in Firefox.

Per JudyX's post here on Monday, February 13, 2006 11:54 PM:

The first column in reports cannot be styled correctly. The report viewer control requires a “height” be specified for all table rows. Unfortunately, it applies this not to the table-row element, but to the first table-cell within that row. When it applies that as a style attribute, it conflicts with the style that we set elsewhere.

Has anyone found a solution to this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

我乃一代侩神 2024-08-02 21:29:44

我可以确认 SSRS 2005 中仍然会发生这种情况。Firefox 并不是唯一不能按照报表设计者的预期呈现此情况的浏览器。 显然,如果一个元素上分配了多个样式属性,则 IE7(可能还有 IE6)会假定最后一个样式属性为“win”。 在这种情况下,标准模式下的 IE8 和 Firefox 假定第一个样式属性为“win”。 我假设所有符合标准的浏览器都会做出与 IE8 和 Firefox 相同的选择,尽管我们的团队尚未对此进行测试。

我还没有找到修复程序方面的解决方案,但我确实有办法防止错误的 HTML 进入浏览器。 OMG Ponies - 感谢您将链接发布到 JudyX 的帖子。 Wodeh 在该帖子的 3/4 处回复了一个很好的解决方案 - 不幸的是,并不完全清楚如何使用发布的代码。

该方法是使用响应过滤器在包含 报表查看器控件。 过滤器可以访问将发送到浏览器的原始 HTML,这提供了直接修改 HTML 的机会,而不必导致新的第一列技巧。 在 Page_Load 方法中,我们使用以下代码设置 Response.Filter 属性:

    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Filter = new CorrectSSRSIssuesResponseFilter(Response.Filter);
        if (!IsPostBack) {
            RenderReport();
        }
    }

CorrectSSRSIssuesResponseFilter 类定义如下,主要基于帖子中的 Wodeh 代码。 秘诀在于 Write() 方法,该方法使用正则表达式删除第一个样式属性:

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace Reports
{
    public class CorrectSSRSIssuesResponseFilter : Stream
    {
        private Stream _sink;
        private StringBuilder Output = new StringBuilder();

        public CorrectSSRSIssuesResponseFilter(Stream sink)
            : base()
        {
            _sink = sink;
        }

        public CorrectSSRSIssuesResponseFilter()
            : base()
        {
            _sink = new MemoryStream();
        }

        public override bool CanRead { get { return true; } }
        public override bool CanSeek { get { return true; } }
        public override bool CanWrite { get { return true; } }
        public override void Flush()
        {
            _sink.Flush();
        }
        public override long Length
        {
            get { return _sink.Length; }
        }
        public override long Position
        {
            get
            { return _sink.Position; }
            set
            { _sink.Position = value; }
        }

        public override int Read(byte[] buffer, int offset, int count)
        {
            return _sink.Read(buffer, offset, count);
        }

        public override long Seek(long offset, SeekOrigin origin)
        {
            return _sink.Seek(offset, origin);
        }

        public override void SetLength(long value)
        {
            _sink.SetLength(value);
        }

        public override void Write(byte[] buffer, int offset, int count)
        {
            string strBuffer = UTF8Encoding.UTF8.GetString(buffer, offset, count);
            //A Closing HTML tag indicates the response object has finished recieving the entire content of the page
            strBuffer = System.Text.RegularExpressions.Regex.Replace(
                strBuffer
                , "<TD style=\"[^\"]*\" style=(?<goodStyle>\"[^\"]*\")>"
                , "<TD style=${goodStyle}>"
                , System.Text.RegularExpressions.RegexOptions.Compiled
                );

            buffer = System.Text.Encoding.UTF8.GetBytes(strBuffer);
            _sink.Write(buffer, offset, buffer.Length);
        }

    }
}

I can confirm that this still happens with SSRS 2005. Firefox is not the only browser that will not render this as intended by the report designer. Apparently IE7 (and probably IE6) assume the last style attribute to "win" if there are multiple style attributes assigned on an element. IE8 in standards mode and Firefox assume the first style attribute to "win" in this situation. I would assume that all standards compliant browsers will make the same choice as IE8 and Firefox, although our team has not tested this.

I haven't found a solution in terms of a hotfix, but I do have a way to prevent the bad HTML from making it to the browser. OMG Ponies - thanks for posting that link to JudyX's post. Wodeh responded with a good solution about 3/4 of the way down that post - unfortunately, it was not entirely clear how to use the code that was posted.

The approach is to use a response filter on the page that contains the ReportViewer Control. The filter has access to the raw HTML that will be sent to the browser, and that provides the opportunity to modify the HTML directly without having to result to the new first column trick. In our Page_Load method, we set the Response.Filter property with the following code:

    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Filter = new CorrectSSRSIssuesResponseFilter(Response.Filter);
        if (!IsPostBack) {
            RenderReport();
        }
    }

The CorrectSSRSIssuesResponseFilter class is defined as follows, and is mostly based off of Wodeh's code from the post. The secret sauce is in the Write() method which uses the RegEx to wipe out the first style attribute:

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace Reports
{
    public class CorrectSSRSIssuesResponseFilter : Stream
    {
        private Stream _sink;
        private StringBuilder Output = new StringBuilder();

        public CorrectSSRSIssuesResponseFilter(Stream sink)
            : base()
        {
            _sink = sink;
        }

        public CorrectSSRSIssuesResponseFilter()
            : base()
        {
            _sink = new MemoryStream();
        }

        public override bool CanRead { get { return true; } }
        public override bool CanSeek { get { return true; } }
        public override bool CanWrite { get { return true; } }
        public override void Flush()
        {
            _sink.Flush();
        }
        public override long Length
        {
            get { return _sink.Length; }
        }
        public override long Position
        {
            get
            { return _sink.Position; }
            set
            { _sink.Position = value; }
        }

        public override int Read(byte[] buffer, int offset, int count)
        {
            return _sink.Read(buffer, offset, count);
        }

        public override long Seek(long offset, SeekOrigin origin)
        {
            return _sink.Seek(offset, origin);
        }

        public override void SetLength(long value)
        {
            _sink.SetLength(value);
        }

        public override void Write(byte[] buffer, int offset, int count)
        {
            string strBuffer = UTF8Encoding.UTF8.GetString(buffer, offset, count);
            //A Closing HTML tag indicates the response object has finished recieving the entire content of the page
            strBuffer = System.Text.RegularExpressions.Regex.Replace(
                strBuffer
                , "<TD style=\"[^\"]*\" style=(?<goodStyle>\"[^\"]*\")>"
                , "<TD style=${goodStyle}>"
                , System.Text.RegularExpressions.RegexOptions.Compiled
                );

            buffer = System.Text.Encoding.UTF8.GetBytes(strBuffer);
            _sink.Write(buffer, offset, buffer.Length);
        }

    }
}
笨笨の傻瓜 2024-08-02 21:29:44

解决方案并不是真正的解决方案;而是解决方案。 这是一个黑客行为。

当该行为出现时,定义新的第一列。 它应该具有以下属性:

  1. 空 - 无文本、无表达式等
  2. 设置最小宽度(0.03125 英寸)
  3. 如果其他单元格上有边框样式,则在设置白色/等时将新的第一个单元格的右边框样式设置为匹配对于其他人。

The solution isn't really a solution; it's a hack.

When the behavior appears, define a new first column. It should have the following attributes:

  1. Empty - no text, no expression, etc
  2. Set the minimum width (0.03125 inches)
  3. If there is border styling on the other cells, style the right border of the new first cell to match while setting white/etc for the others.
萧瑟寒风 2024-08-02 21:29:44

这是 CSS 样式问题。 我过去使用 这篇文章

您基本上必须找到报告服务的 css 文件(默认情况下,位于 C:\Program Files\Microsoft SQL Server\MSSQL .3\Reporting Services\ReportManager\Styles\ReportingServices.css(在报表服务器上),并向其中添加此类规则:

.DocMapAndReportFrame
{
min-height: 860px;
} 

This is a CSS styling issue. I have successfully implemented a fix for this in the past using the info from this post:

You basically have to locate the css file for reporting services (by default, located at C:\Program Files\Microsoft SQL Server\MSSQL.3\Reporting Services\ReportManager\Styles\ReportingServices.css on the report server), and add this class rule to it:

.DocMapAndReportFrame
{
min-height: 860px;
} 
独留℉清风醉 2024-08-02 21:29:44

ReportViewer 控件上尝试 AsyncRendering="true"

通过异步渲染,生成的 HTML 没有两个样式标签 - 它使用 sytle 标签作为高度,所有其他样式都通过 td 元素上的 class 属性应用。

Try AsyncRendering="true" on the ReportViewer control.

With async rendering the generated HTML does not have two style tags – it uses a sytle tag for the height and all other styles are applied through a class attribute on the td element.

长途伴 2024-08-02 21:29:44

在我的例子中,一个更简单的解决方法解决了这个问题。 只需在损坏的行下方添加另一行并设置 Visibility:Hidden = True。

祝你好运!

A much more simpler workaround fixed this issue in my case. Just added anoter row below the damaged one and set Visibility:Hidden = True.

Good luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文