【问题标题】:Printing using ReportViewer in Chrome and Firefox在 Chrome 和 Firefox 中使用 ReportViewer 打印
【发布时间】:2013-11-19 18:22:56
【问题描述】:

我有 ASP.NET Webforms,它使用 ReportViewer 控件来打印报告 (LocalReport),并且由于直接打印在 Chrome 和 Firefox 中不起作用,我需要添加按钮,它可以在 Chrome 和 Firefox 中以某种方式完成。有什么想法吗?

【问题讨论】:

    标签: asp.net printing reportviewer


    【解决方案1】:

    我曾经遇到过同样的问题,发现明确指定应该显示 ReportViewer 控件中的哪些控件可以解决问题。我还在页面中添加了一个 ScriptManager。下面的代码适用于 FireFox 和 Chrome。此外,当与 UpdatePanels 结合使用时,ReportViewer 控件与其他浏览器存在问题。根据您的标记设置方式,这些可能是您的问题。

        <rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" Font-Size="8pt"
            InteractiveDeviceInfos="(Collection)" ProcessingMode="Remote" WaitMessageFont-Names="Verdana"
            WaitMessageFont-Size="14pt" ShowExportControls="true" Width="1280px" Height="700px"
            ShowBackButton="true" ShowToolBar="true" ShowParameterPrompts="true" ShowPageNavigationControls="true"
            ZoomMode="Percent" ZoomPercent="100" ShowReportBody="true" InternalBorderStyle="Solid">
        </rsweb:ReportViewer>
    

    旧版本的报告控件会出现一些问题,例如 ActiveX。您可以通过查看 web.config 文件找出哪个版本。版本 8 及更低版本存在此问题。

        <add assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="Microsoft.ReportViewer.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
    

    可在此处找到解决方法:ReportViewer Client Print Control “Unable to load client print control”?

    【讨论】:

    • 不,这不是问题,问题是打印按钮仅显示在 Internet Explorer 上,因为此控件显然使用 ActiveX。那么如果没有 ActiveX,我们怎么能做同样的事情呢?
    • 您使用的是哪个版本的 .Net Framework 和报告控件?版本 10 不使用 ActiveX 控件,因此可以在 FireFox 和 Chrome 中使用。
    • 刚刚用容易出问题的版本和堆栈中的解决方法更新了 OA。
    • 您的解决方法链接提到了 SQL 报告,但也许我需要提到我正在处理 LocalReport?
    • 如果是本地报告,该链接将无助于升级您的控件,但仍应能解决问题。
    【解决方案2】:

    我已经通过下面的 js 代码做到了: addPrintButton函数在报表查看器中添加了一个打印btn(ctl是reportviewer的id。'#ctl00_cphMain_rvReportMain_ctl05'是reportviewr控件中主div的id,可以根据控件的client id进行修改):

    function addPrintButton(ctl) {
    var innerTbody = '<tbody><tr><td><input type="image" style="border-width: 0px; padding: 2px; height: 16px; width: 16px;" alt="Print" src="/App/Reserved.ReportViewerWebControl.axd?OpType=Resource&Version=10.0.40219.1&Name=Microsoft.Reporting.WebForms.Icons.Print.gif" title="Print"></td></tr></tbody>';
    var innerTable = '<table title="Print" onclick="javascript:PrintFunc(\'' + ctl + '\'); return false;" id="do_print" style="cursor: default;">' + innerTbody + '</table>'
    var outerDiv = '<div style="display: inline-block; font-size: 8pt; height: 30px;" class=" "><table cellspacing="0" cellpadding="0" style="display: inline;"><tbody><tr><td height="28px">' + innerTable + '</td></tr></tbody></table></div>';
    $("#ctl00_cphMain_rvReportMain_ctl05 > div").append(outerDiv);}
    

    function PrintFunc() {
    var strFrameName = ("printer-" + (new Date()).getTime());
    var jFrame = $("<iframe name='" + strFrameName + "'>");
    jFrame
    .css("width", "1px")
    .css("height", "1px")
    .css("left", "-2000px")
    .css("position", "absolute")
    .appendTo($("body:first"));
    
    var objFrame = window.frames[strFrameName];
    var objDoc = objFrame.document;
    var jStyleDiv = $("<div>").append($("style").clone());
    var styles = '<style type="text/css">' + jStyleDiv.html() + "</style>";
    var docType = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
    var docCnt = styles + $("#VisibleReportContentctl00_cphMain_rvReportMain_ctl09").html();
    var docHead = '<head><title>...</title><style>body{margin:5;padding:0;}</style></head>';
    objDoc.open();
    objDoc.write(docType + '<html>' + docHead + '<body onload="window.print();">' + docCnt + '</body></html>');
    objDoc.close();
    

    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-04
      • 2012-01-29
      • 1970-01-01
      • 1970-01-01
      • 2010-09-22
      • 2014-07-06
      • 1970-01-01
      • 2015-06-03
      相关资源
      最近更新 更多