当前位置:首页>文章>c#操作word源代码(c语言读写word文档表格)

c#操作word源代码(c语言读写word文档表格)

在windows应用程序中打印是一项非常重要的功能,在实际运用中也较多,.net中的打印功能都以组件的方式提供,为程序员提供了很大的方便,打印操作通常包括以下四个功能 1打印设置设置打印机的一些参数比如更改打印机驱动程序等 2页面设置设置页面大小纸张类型等 3打印预览类似于word中的打印预览 4打印 下面以是一个简单的示例 1、打印机设置代码 PrintDialog printDial...

在windows应用程序中打印是一项非常重要的功能,在实际运用中也较多,.net中的打印功能都以组件的方式提供,为程序员提供了很大的方便,打印 操作通常包括以下四个功能

1 打印设置 设置打印机的一些参数比如更改打印机驱动程序等

2 页面设置 设置页面大小纸张类型等

3 打印预览 类似于word中的打印预览

4 打印

下面以是一个简单的示例

c#操作word源代码(c语言读写word文档表格)c#操作word源代码(c语言读写word文档表格)

1、打印机设置代码

PrintDialog printDialog = new PrintDialog();
printDialog.Document = printDocument;
printDialog.ShowDialog();

2、打印纸张设置代码

PageSetupDialog pageSetupDialog = new PageSetupDialog();
pageSetupDialog.Document = printDocument;
pageSetupDialog.ShowDialog();

3、打印预览代码

printDocument.PrintPage += PrintDocument_PrintPage;
PrintPreviewDialog printPreviewDialog = new PrintPreviewDialog { Document = printDocument };            
try
  {
     printPreviewDialog.ShowDialog();
   }
catch (Exception excep)
   {
      MessageBox.Show(excep.Message, \"打印出错\", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

4、打印内容设置代码

Graphics g = e.Graphics ;
Pen p_Line = new Pen(Color.Blue, 2f);
p_Line.DashStyle = DashStyle.Solid;
//
g.DrawRectangle(p_Line, new Rectangle(100, 50, 300, 200));
g.DrawLine(p_Line, new Point(100, 150), new Point(400, 150));
g.DrawLine(p_Line, new Point(100, 188), new Point(400, 188));
g.DrawLine(p_Line, new Point(100, 221), new Point(400, 221));
//
g.DrawLine(p_Line, new Point(200, 83), new Point(400, 83));
g.DrawLine(p_Line, new Point(200, 116), new Point(400, 116));
//竖线
g.DrawLine(p_Line, new Point(200, 50), new Point(200, 250));
g.DrawLine(p_Line, new Point(300, 50), new Point(300, 150));
//文字
Brush b_Text = new SolidBrush(Color.Black);
 
g.DrawString(\"姓名\", new Font(\"微软雅黑\", 12f, FontStyle.Regular), b_Text, new Point(230, 55));
g.DrawString(\"性别\", new Font(\"微软雅黑\", 12f, FontStyle.Regular), b_Text, new Point(230, 88));
g.DrawString(\"民族\", new Font(\"微软雅黑\", 12f, FontStyle.Regular), b_Text, new Point(230, 121));
 
g.DrawString(\"Lena\", new Font(\"微软雅黑\", 12f, FontStyle.Regular), b_Text, new Point(330, 55));
g.DrawString(\"女\", new Font(\"微软雅黑\", 12f, FontStyle.Regular), b_Text, new Point(340, 88));
g.DrawString(\"未知\", new Font(\"微软雅黑\", 12f, FontStyle.Regular), b_Text, new Point(330, 121));
 
g.DrawString(\"公司名称\", new Font(\"微软雅黑\", 12f, FontStyle.Regular), b_Text, new Point(115, 155));
g.DrawString(\"职位\", new Font(\"微软雅黑\", 12f, FontStyle.Regular), b_Text, new Point(130, 193));
g.DrawString(\"联系电话\", new Font(\"微软雅黑\", 12f, FontStyle.Regular), b_Text, new Point(115, 225));
pic = resizeImage(pic,new Size(92,92));
g.DrawImage(pic, 102, 52);

打印代码

printDocument.PrintPage += PrintDocument_PrintPage;
try
{
   printDocument.Print();
}
catch (Exception excep)
{
   MessageBox.Show(excep.Message, \"打印出错\", MessageBoxButtons.OK, MessageBoxIcon.Error);
   printDocument.PrintController.OnEndPrint(printDocument, new PrintEventArgs());
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

给TA打赏
共{{data.count}}人
人已打赏
文章

手机四核处理器怎么样(电脑双核好还是四核好)

2022-1-18 12:06:54

文章

影视大全播放器怎么投屏(免费影视app推荐)

2022-1-18 12:06:56

重要说明

本站资源大多来自网络,如有侵犯你的权益请联系管理员 青年人  或给邮箱发送邮件834379394@qq.com 我们会第一时间进行审核删除。 平台资源为网友个人学习或测试研究使用,未经原版权作者许可,禁止用于任何商业途径!请在下载24小时内删除!


如果你遇到支付完成,找不到下载链接,或者不能下载,或者解压失败,先不要忙,加管理员的QQ:834379394 (管理员有可能有事情或者在睡觉不能及时的回复您,QQ留言后,请耐心等待即可!)

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索