asp.net 打印功能

zhangxiqing 2010-09-26 05:28:55
页面有一个gridview,还有一个打印按钮,点击打印按钮,打印gridview每一行对应的详细信息。

...全文
188 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuyq11 2010-09-26
  • 打赏
  • 举报
回复
gridview导出到excel ,word打印
document.all.WebBrowser.ExecWB(6,6)
Response.Clear();
Response.Buffer = true;
Response.Charset = "GB2312";
Response.AppendHeader("Content-Disposition", "attachment;filename=Result.xls");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.ContentType = "application/ms-excel";
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
this.gv.RenderControl(oHtmlTextWriter);
Response.Output.Write(oStringWriter.ToString());
Response.Flush();
Response.End();
lgz_asp_net 2010-09-26
  • 打赏
  • 举报
回复

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Printing;
using System.Data.SQLite;
using OpenNETCF.Desktop.Communication;
using Cobainsoft.Windows.Forms;
using System.Xml;


namespace TVTowerK3Print
{
public partial class Form1 : Form
{
BarcodeControl bc = new BarcodeControl();
DataView dDV = null;
int column = 0;

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
string pk;
for (int i = 0; i < PrinterSettings.InstalledPrinters.Count; i++)
{
pk = PrinterSettings.InstalledPrinters[i];
comboBox1.Items.Add(pk);
}

dDV="";//自己把datagridview赋上值
PrinterSettings ps = new PrinterSettings();
comboBox1.Text = ps.PrinterName;//获取打印机名称
}
private void btnPrint_Click(object sender, EventArgs e)
{
short copies = 1;//打印份数
try
{
copies = Convert.ToInt16(this.txtCount.Text.Trim());
if (copies < 1)
{
MessageBox.Show("打印数量必须大于0!");
return;
}
else
{
column = 0;
printDocument1.PrinterSettings.Copies = copies;
PaperSize ps = new PaperSize("a", 275, 157);
printDocument1.DefaultPageSettings.PaperSize = ps;
printDocument1.PrinterSettings.PrinterName = this.comboBox1.Text;//打印机名称
if (dDV != null)
{
foreach (DataRow dr in dDV.Table.Rows)
{
printDocument1.Print();
column += 1;
}
}
else
{
MessageBox.Show("请您先查询出需要打印的数据!");
}
//打印预览对话框
//PrintPreviewDialog ppd = new PrintPreviewDialog();
//ppd.Document = printDocument1;
//ppd.ShowDialog();
//printDocument1.Print();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
Graphics g = e.Graphics;
Rectangle rect = bc.ClientRectangle;
rect = new Rectangle(5, 45, this.bc.Width, this.bc.Height);
bc.Draw(g, rect, GraphicsUnit.Pixel, 1, 0, null);
g.DrawString("广州新电视塔建设有限公司", new Font("黑体", 12), Brushes.Black, new PointF(35, 5));
g.DrawString("经营管理分公司", new Font("黑体", 12), Brushes.Black, new PointF(75, 23));
g.DrawString(dDV.Table.Rows[column]["固定资产名称"].ToString(), new Font("黑体", 10), Brushes.Black, new PointF(30, 120));
g.DrawString("部门:" + dDV.Table.Rows[column]["使用部门"].ToString(), new Font("黑体", 10), Brushes.Black, new PointF(30, 140));

g.Dispose();
}
}
}

parverxiao 2010-09-26
  • 打赏
  • 举报
回复
还是水晶报表打印?
parverxiao 2010-09-26
  • 打赏
  • 举报
回复
用到打印机了吗
7/13初识web打印功能:    具体实现如下:    1.         将以上代码贴入aspx文件中,点击”打印预览“可调用本地打印预览界面,,     2.如果设置分页:在头部写入以下代码       

62,272

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧