这篇文章主要是介绍建立一个控间库实现WEB报表打印,我的问题是想给这个程序加一个入口参数,
请问大家该如何做啊?感激涕零!

解决方案 »

  1.   

    http://www.yesky.com/20030214/1652186.shtml我想加的入口参数是要打印的文档名,否则我怎么能控制它打印其他的报表呢?
      

  2.   

    利用XML实现通用WEB报表打印
    这个客户端要装.net环境
    大约据说ie7里把.net环境包括进去了
      

  3.   

    以前研究过。也按照你的方法写过打印。可代码写了一半发现一个问题(我现在也忘记是什么原因了。好像是因为会弹出ACTION或是什么)不建议按他的方法
      

  4.   

    蒋XML文件的URL以属性的方式公布出来:using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Drawing;
    using System.Data;
    using System.Windows.Forms;
    using System.Xml;
    using System.Drawing.Printing;namespace RemotePrint
    {
    /// <summary>
    /// UserControl1 的摘要说明。
    /// </summary>
    public class PrintControl : System.Windows.Forms.UserControl
    {
    private System.Windows.Forms.Button button1;
    private System.Windows.Forms.Button button2;
    private System.Windows.Forms.Button button3;
    private System.Windows.Forms.Label label1;
    private System.Drawing.Printing.PrintDocument printDocument1;
    private System.Windows.Forms.PageSetupDialog pageSetupDialog1; private string docName="";
    private bool isLoad=false; 
    private XmlDocument doc = new XmlDocument();
    public static int Pages = 1;
    private System.Windows.Forms.PrintPreviewDialog printPreviewDialog1; /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null; public PrintControl()
    {
    // 该调用是 Windows.Forms 窗体设计器所必需的。
    InitializeComponent();
    this.printDocument1.PrintPage += new PrintPageEventHandler(this.pd_PrintPage); // TODO: 在 InitComponent 调用后添加任何初始化 }
    public string XML_FileName
    {
    get{ return docName; }
    set{ docName = value; }
    }
    /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if( components != null )
    components.Dispose();
    }
    base.Dispose( disposing );
    } #region 组件设计器生成的代码
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器 
    /// 修改此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(PrintControl));
    this.button1 = new System.Windows.Forms.Button();
    this.button2 = new System.Windows.Forms.Button();
    this.button3 = new System.Windows.Forms.Button();
    this.label1 = new System.Windows.Forms.Label();
    this.printDocument1 = new System.Drawing.Printing.PrintDocument();
    this.pageSetupDialog1 = new System.Windows.Forms.PageSetupDialog();
    this.printPreviewDialog1 = new System.Windows.Forms.PrintPreviewDialog();
    this.SuspendLayout();
    // 
    // button1
    // 
    this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
    this.button1.Location = new System.Drawing.Point(192, 354);
    this.button1.Name = "button1";
    this.button1.TabIndex = 0;
    this.button1.Text = "设置";
    this.button1.Click += new System.EventHandler(this.button1_Click);
    // 
    // button2
    // 
    this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
    this.button2.Location = new System.Drawing.Point(288, 354);
    this.button2.Name = "button2";
    this.button2.TabIndex = 1;
    this.button2.Text = "预览";
    this.button2.Click += new System.EventHandler(this.button2_Click);
    // 
    // button3
    // 
    this.button3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
    this.button3.Location = new System.Drawing.Point(392, 354);
    this.button3.Name = "button3";
    this.button3.TabIndex = 2;
    this.button3.Text = "打印";
    this.button3.Click += new System.EventHandler(this.button3_Click);
    // 
    // label1
    // 
    this.label1.Anchor = System.Windows.Forms.AnchorStyles.Left;
    this.label1.Location = new System.Drawing.Point(16, 336);
    this.label1.Name = "label1";
    this.label1.TabIndex = 3;
    this.label1.Text = "label1";
    // 
    // pageSetupDialog1
    // 
    this.pageSetupDialog1.Document = this.printDocument1;
    // 
    // printPreviewDialog1
    // 
    this.printPreviewDialog1.AutoScrollMargin = new System.Drawing.Size(0, 0);
    this.printPreviewDialog1.AutoScrollMinSize = new System.Drawing.Size(0, 0);
    this.printPreviewDialog1.ClientSize = new System.Drawing.Size(400, 300);
    this.printPreviewDialog1.Document = this.printDocument1;
    this.printPreviewDialog1.Enabled = true;
    this.printPreviewDialog1.Icon = ((System.Drawing.Icon)(resources.GetObject("printPreviewDialog1.Icon")));
    this.printPreviewDialog1.Location = new System.Drawing.Point(402, 19);
    this.printPreviewDialog1.MinimumSize = new System.Drawing.Size(375, 250);
    this.printPreviewDialog1.Name = "printPreviewDialog1";
    this.printPreviewDialog1.TransparencyKey = System.Drawing.Color.Empty;
    this.printPreviewDialog1.Visible = false;
    // 
    // PrintControl
    // 
    this.Controls.Add(this.label1);
    this.Controls.Add(this.button3);
    this.Controls.Add(this.button2);
    this.Controls.Add(this.button1);
    this.Name = "PrintControl";
    this.Size = new System.Drawing.Size(480, 392);
    this.Load += new System.EventHandler(this.UserControl1_Load);
    this.ResumeLayout(false); }
    #endregion
      

  5.   

    private void UserControl1_Load(object sender, System.EventArgs e)
    {
    /*
    try
    {
    //装载报表XML数据
    this.label1.Text = "正在加载报表数据,请稍侯...";
    doc.Load("http://localhost/report.xml");
    this.label1.Text = "报表数据加载完毕!";
    this.button1.Enabled = this.button2.Enabled = this.button3.Enabled = true;
    }
    catch(Exception ex)
    {
    this.label1.Text = "出现错误:" + ex.Message;
    }
    */
    }

    public    void  LoadXMLFile()
    {
    if (docName.Length==0  ) 
    {
    isLoad= false;
    return;
    }

    try
    {
    //装载报表XML数据
    this.label1.Text = "正在加载报表数据,请稍侯...";
    doc.Load(docName);
    this.label1.Text = "报表数据加载完毕!";
    this.button1.Enabled = this.button2.Enabled = this.button3.Enabled = true;
    isLoad= true;
    }
    catch(Exception ex)
    {
    this.label1.Text = "出现错误:" + ex.Message;
    isLoad= false;
    }


    }
    private void SettingPrinter(XmlNode ps)
    {
    //打印方向(纵/横)
    if (!isLoad)
    {
    LoadXMLFile(); }
    if(!isLoad) return;
    this.printDocument1.DefaultPageSettings.Landscape = bool.Parse(ps["landscape"].InnerText);
    //设置纸张类型
    string papername = ps["paperkind"].InnerText;
    bool fitpaper = false;
    //获取打印机支持的所有纸张类型
    foreach(PaperSize size in this.printDocument1.PrinterSettings.PaperSizes)
    {
    if(papername == size.PaperName)//看该打印机是否有我们需要的纸张类型
    {
    this.printDocument1.DefaultPageSettings.PaperSize = size;
    fitpaper = true;
    }
    }
    if(!fitpaper)
    {
    //假如没有我们需要的标准类型,则使用自定义的尺寸
    this.printDocument1.DefaultPageSettings.PaperSize = 
    new PaperSize("Custom", int.Parse(ps["paperwidth"].InnerText), 
    int.Parse(ps["paperheight"].InnerText));
    }
    }
    private void pd_PrintPage(object sender, PrintPageEventArgs ev) 
    {
    if (!isLoad)
    {
    LoadXMLFile(); }
    if(!isLoad) return;
    Graphics g = ev.Graphics;
    bool HasMorePages = false;
    PrintElement printElement = null;
        
    foreach(XmlNode node in doc["root"]["reporttable"].ChildNodes)
    {
    printElement = Parser.CreateElement(node);//调用解析器生成相应的对象
    try
    {
    HasMorePages = printElement.Draw(g);//是否需要分页
    }
    catch(Exception ex)
    {
    this.label1.Text = ex.Message;
    }
    } //在页底中间输出页码
    Font font = new Font("黑体", 12.0f);
    Brush brush = new SolidBrush(Color.Black);
    g.DrawString("第 " + Pages.ToString() + " 页",
    font,brush,ev.MarginBounds.Width / 2 + ev.MarginBounds.Left - 30, 
    ev.PageBounds.Height - 60); if(HasMorePages)
    {
    Pages++;
    }
    ev.HasMorePages = HasMorePages;
    } private void button1_Click(object sender, System.EventArgs e)
    {
    if (!isLoad)
    {
    LoadXMLFile(); }
    if(!isLoad) return;
    this.pageSetupDialog1.ShowDialog();
    this.printDocument1.DefaultPageSettings = this.pageSetupDialog1.PageSettings; } private void button2_Click(object sender, System.EventArgs e)
    {
    if (!isLoad)
    {
    LoadXMLFile(); }
    if(!isLoad) return;
    try
    {
    this.printPreviewDialog1.ShowDialog();
    }
    catch(Exception ex)
    {
    this.label1.Text = ex.Message;
    } } private void button3_Click(object sender, System.EventArgs e)
    {
    if (!isLoad)
    {
    LoadXMLFile(); }
    if(!isLoad) return;
    try
    {
    this.printDocument1.Print();
    }
    catch(Exception ex)
    {
    this.label1.Text = ex.Message;
    } }
    }
    }
      

  6.   

    输入参数用javascript:<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplicationTestRemotPrint.WebForm1" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>WebForm1</title>
    <META content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
    <META content="C#" name="CODE_LANGUAGE">
    <META content="JavaScript" name="vs_defaultClientScript">
    <META content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
    <script language="javascript">
    function LoadXML()
    {
      el=document.getElementById("print"); 
      el.XML_FileName="http://localhost/report.xml";
    }
    </script>
    </HEAD>
    <BODY MS_POSITIONING="GridLayout">
    <FORM id="Form1" method="post" runat="server">
    &nbsp;
    <OBJECT id="print" style="WIDTH: 592px; HEIGHT: 208px" height="208" width="592" classid="RemotePrint.dll#RemotePrint.PrintControl"
    VIEWASTEXT>
    </OBJECT>
    <INPUT style="Z-INDEX: 102; LEFT: 552px; POSITION: absolute; TOP: 296px" type="button"
    value="Button" onclick="LoadXML()">
    </FORM>
    </BODY>
    </HTML>
      

  7.   

    那篇文章看过,没有源代码啊!后来给卢彦写email,也没有回音,楼主有代码吗?请email我一份:[email protected],多谢!
      

  8.   

    我是酱紫做的我另做了个xml 把要打印的文件名存在里面,每次运行前读而文件名是在生成报表xml时取出存进去的
      

  9.   

    原来看过,因为要求客户安装.net,还要做安全设置,挺麻烦,感觉已经失去了web程序的意义,不如用水晶报表方便
      

  10.   

    我搞定了.在控件中加入属性,然后在调用时如此使用即可:
    <OBJECT id="print" style="WIDTH: 592px; HEIGHT: 208px" height="208" width="592" classid="RemotePrint.dll#RemotePrint.PrintControl"
    VIEWASTEXT>
    <param name="Parameter" value="<%=YourUrl%>">
    </OBJECT>
    这种方式我已测试通过.