欢迎来到天天文库
浏览记录
ID:38757558
大小:55.50 KB
页数:7页
时间:2019-06-19
《C#操作word表格》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、做了一些关于c#操作word文档方面的工作usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingMSword=Microsoft.Office.Interop.Word;usingSystem.IO;usingSystem.
2、Drawing.Printing;usingSystem.Drawing.Drawing2D;usingSystem.Threading;namespaceHolter_print{publicpartialclassaaa:Form{publicaaa(){InitializeComponent();}privatevoidaaa_Load(objectsender,EventArgse){CreatWord();}publicvoidCreatWord(){stringstrtitle="C#生成word和
3、操作word表格";objectoEndOfDoc="\endofdoc";ObjectNothing=System.Reflection.Missing.Value;Objectfilename="E:\test.doc";//保存word文档路径if(File.Exists(filename.ToString()))//判断该文件是否存在{File.Delete(filename.ToString());//存在删除}//创建Word文档MSword.ApplicationWordApp=newMSwo
4、rd.ApplicationClass();WordApp.Visible=true;//设置动态建立的word文档可见MSword.DocumentWordDoc=WordApp.Documents.Add(refNothing,refNothing,refNothing,refNothing);WordApp.Selection.PageSetup.LeftMargin=WordApp.CentimetersToPoints(float.Parse("2"));//设置word文档的左边距WordApp.S
5、election.PageSetup.RightMargin=WordApp.CentimetersToPoints(float.Parse("2"));//设置word文档的右边距WordApp.ActiveWindow.HorizontalPercentScrolled=11;//设置文档的水平滑动距离WordApp.ActiveWindow.ActivePane.View.Zoom.Percentage=75;//设置文档的百分比例#regionword文档报告MSword.ParagraphoPara1
6、;oPara1=WordDoc.Content.Paragraphs.Add(refNothing);oPara1.Range.Text=strtitle;oPara1.Range.Font.Bold=0;oPara1.Range.Font.Name="宋体";oPara1.Range.Font.Size=12;oPara1.Range.ParagraphFormat.Alignment=MSword.WdParagraphAlignment.wdAlignParagraphCenter;oPara1.Form
7、at.SpaceAfter=5;oPara1.Range.InsertParagraphAfter();//描述信息Microsoft.Office.Interop.Word.ParagraphoPara4;oPara4=WordDoc.Content.Paragraphs.Add(refNothing);oPara4.Range.Text="word文档报告";oPara4.Range.Font.Bold=1;oPara4.Range.Font.Name="宋体";oPara4.Range.Font.Size
8、=20;oPara4.Range.ParagraphFormat.Alignment=Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;oPara4.Format.SpaceAfter=5;oPara4.Range.InsertParagraphAfter();//描述Microsoft.
此文档下载收益归作者所有