ASPX页面后台代码:
- protected void Page_Load(object sender, EventArgs e)
- {
- SectionReport rpt = new SectionReport();
- System.Xml.XmlTextReader xtr = new System.Xml.XmlTextReader(@"C:\Users\pmway\Desktop\新建文件夹\32.rpx");
- rpt.LoadLayout(xtr);
- xtr.Close();
- WebViewer1.Report = rpt;
- WebViewer1.ClearCachedReport();
- WebViewer1.Report = rpt;
- if (Request["Task"] != null)
- {
- if (Request["Task"].ToString().Contains("Print"))
- {
- try
- {
- rpt.Restart();
- }
- catch (Exception eRunReport)
- {
- //If the report fails to run, report the error to the user
- Response.Clear();
- Response.Write("<h1>Error running report:</h1>");
- Response.Write(eRunReport.ToString());
- return;
- }
- //Buffer this page's output until the report output is ready.
- Response.Buffer = true;
- //Clear any part of this page that might have already been buffered for output.
- Response.ClearContent();
- //Clear any headers that might have already been buffered (such as the content
- //type for an HTML page)
- Response.ClearHeaders();
- //Tell the browser and the "network" that the resulting data of this page should
- //be cached since this could be a dynamic report that changes upon each request.
- Response.Cache.SetCacheability(HttpCacheability.NoCache);
- //Tell the browser this is an Html document so it will use an appropriate viewer.
- Response.ContentType = "text/html";
- //Create the HTML export object
- GrapeCity.ActiveReports.Export.Html.Section.HtmlExport htmlExport1 = new HtmlExport();
- //Export the report to HTML in this session's webcache
- MyCustomHtmlOutputter outputter = new MyCustomHtmlOutputter(this.Context);
- //String filePath = @"E:\demo\CustomHtml_Print\CustomHtml\ReportOutput" +
- // Guid.NewGuid().ToString("N") + ".pdf";
- //FileStream fs =
- // File.Create(filePath);
- htmlExport1.Export(rpt.Document, outputter, "");
- Response.Redirect("ReportOutput" + "/" + System.IO.Path.GetFileName(outputter.mainPage));
- }
- }
- }
复制代码
ASPX页面前台代码:
- <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="CustomHtml.WebForm1" %>
- <%@ Register Assembly="GrapeCity.ActiveReports.Web.v8, Version=8.1.414.0, Culture=neutral, PublicKeyToken=cc4967777c49a3ff" Namespace="GrapeCity.ActiveReports.Web" TagPrefix="ActiveReportsWeb" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title></title>
- <script type="text/javascript" src="Scripts/jquery-1.4.1.min.js">
-
- </script>
- <script type="text/javascript" language="javascript">
- $(document).ready(function fn() {
- $(".arvToolBar").append("<span><input id='btnPrint' type='Button' value='Print' onclick='print()'/></span>");
- });
- function print() {
- w = window.open("WebForm1.aspx?Task=Print");
- w.focus();
- $(w.document).ready(function () {
- window.setTimeout("w.print()", 2000);
- });
- };
- </script>
- </head>
- <body>
- <form id="form1" runat="server">
- <ActiveReportsWeb:WebViewer ID="WebViewer1" runat="server" Height="300px" Width="300px"></ActiveReportsWeb:WebViewer>
- </form>
- </body>
- </html>
复制代码 |