你就当那个XML是一个HTML不就行了?反正都差不多,只要格式符合规定就行了
解决方案 »
- 添加 引用 的 问题
- HttpWebRequest模拟post登录淘宝,貌似成功了,怎么保存不了Cookie啊!
- 新手请教在C#中怎样提取一个字符串中最右边的一个字符
- #######请教大家水晶报表的几个大问题####
- (菜鸟提问)string并不包含getfilename定义?
- 设计模式问题 - 这是什么模式?
- sqldatareader棘手问题!!!
- 80分!请问谁能够把孙三才著的《精通C#与ASP.NET程序设计》的光盘代码给我
- 有愿意和我们一起开发DirectX程序的朋友吗??留个名吧。呵呵。。。。
- 求教C# PPPOE拨号问题
- 请教:c#中的picturebox怎么实现自动重画?
- 关于 Graphics 类的问题
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;using System.Xml;using System.Drawing.Printing;namespace HaoHaoRemotePrint
{
/// <summary>
/// UserControl1 的摘要说明。
/// </summary>
public class HaoHaoReport : System.Windows.Forms.UserControl
{
private System.Drawing.Printing.PrintDocument printDocument1;
private System.Windows.Forms.PageSetupDialog pageSetupDialog1;
private System.Windows.Forms.PrintDialog printDialog1;
private XmlDocument doc = new XmlDocument(); public static int Pages = 1;
private System.Windows.Forms.PrintPreviewDialog printPreviewDialog1; public string ErrStr="";
private string XmlData="http://hhs/report/report.xml"; /// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public HaoHaoReport()
{
// 该调用是 Windows.Forms 窗体设计器所必需的。
InitializeComponent(); this.printDocument1.PrintPage += new PrintPageEventHandler(this.pd_PrintPage); // TODO: 在 InitializeComponent 调用后添加任何初始化 } /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
} #region Component Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(HaoHaoReport));
this.printDocument1 = new System.Drawing.Printing.PrintDocument();
this.pageSetupDialog1 = new System.Windows.Forms.PageSetupDialog();
this.printDialog1 = new System.Windows.Forms.PrintDialog();
this.printPreviewDialog1 = new System.Windows.Forms.PrintPreviewDialog();
//
// pageSetupDialog1
//
this.pageSetupDialog1.Document = this.printDocument1;
//
// printDialog1
//
this.printDialog1.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(44, 44);
this.printPreviewDialog1.MaximumSize = new System.Drawing.Size(0, 0);
this.printPreviewDialog1.Name = "printPreviewDialog1";
this.printPreviewDialog1.Opacity = 1;
this.printPreviewDialog1.TransparencyKey = System.Drawing.Color.Empty;
this.printPreviewDialog1.UseAntiAlias = true;
this.printPreviewDialog1.Visible = false;
//
// PrintControl
//
this.Name = "PrintControl";
this.Size = new System.Drawing.Size(32, 48);
this.Load += new System.EventHandler(this.PrintControl_Load); }
#endregion
private void SettingPrinter(XmlNode ps)
{
// 打印方向(纵/横)
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 PrintControl_Load(object sender, System.EventArgs e)
{
} private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
Graphics g = ev.Graphics;
bool HasMorePages = false;
PrintElement printElement = null;
foreach(XmlNode node in doc["root"]["reporttable"].ChildNodes)
{
printElement = Parser.CreateElement(node);//调用解析器生成相应的对象
printElement.PageHeight=ev.PageBounds.Height - 80;
try
{
HasMorePages = printElement.Draw(g);//是否需要分页
}
catch(Exception ex)
{
this.ErrStr= ex.Message;
//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)
{
// this.pageSetupDialog1.ShowDialog();
// this.printDocument1.DefaultPageSettings = this.pageSetupDialog1.PageSettings; } private void button2_Click(object sender, System.EventArgs e)
{
// try
// {
// Pages=1;
// this.printPreviewDialog1.ShowDialog();
// }
// catch(Exception ex)
// {
// this.label1.Text = ex.Message;
// } } private void button3_Click(object sender, System.EventArgs e)
{
//
// try
// { Pages=1;
// this.printDocument1.Print();
// }
// catch(Exception ex)
// {
// this.label1.Text = ex.Message;
// } } public bool LoadXml(string Xmlstr)
{ try
{ //装载报表XML数据
//this.label1.Text = "正在加载报表数据,请稍侯...";
doc.Load(Xmlstr);
// this.label1.Text = "报表数据加载完毕!";
SettingPrinter(doc["root"]["pagesetting"]);
// this.button1.Enabled = this.button2.Enabled = this.button3.Enabled = true;
this.ErrStr="在入完毕";
return true;
}
catch(Exception ex)
{
this.ErrStr= ex.Message.ToString();
return false;
}
} public bool Preview()
{ try
{
//this.LoadXml
Pages=1;
this.printPreviewDialog1.ShowDialog();
return true;
}
catch(Exception ex)
{
this.ErrStr=ex.Message.ToString();
return false;
}
} public void Seting()
{
this.pageSetupDialog1.ShowDialog();
this.printDocument1.DefaultPageSettings = this.pageSetupDialog1.PageSettings;
} public bool Print()
{
try
{
Pages=1;
this.printDocument1.Print();
return true;
}
catch(Exception ex)
{
this.ErrStr=ex.Message.ToString();
return false;
}
} public string PXmlData
{
get
{
return this.XmlData ;
}
set
{
this.XmlData=value;
}
} }
}
//我加了个方法, 写的很乱,你慢慢看 :(
引用<<续:利用XML实现通用WEB报表打印(实现篇)>>的一段话:
新建一个remoteprint.htm的HTML格式文件,在合适的地方加上:<object id="print" classid="http:RemotePrint.dll#RemotePrint.PrintControl" Width="100%" Height="60"> </object>
在aspx中html设计加入以上内容为什么不对?
然后 当你输入到classid时下面有一个ulr...的提示,用鼠标点击.在弹出的画面中选择RemotePrint.dll然后在后面输入#RemotePrint.PrintControl (在.net的IDE中编辑html)classid字段是最重要的.只要这段没有错误.就不会有问题.
另外.你的RemotePrint类的入口必须是PrintConrtol.