資源描述:
《C# 操作word表格、圖片、文字格式大全.doc》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫(kù)。
1、C#操作word表格圖片文字格式大全2010-05-2414:20usingWord;下面的例子中包括C#對(duì)Word文檔的創(chuàng)建、插入表格、設(shè)置樣式等操作:(例子中代碼有些涉及數(shù)據(jù)信息部分被省略,重要是介紹一些C#操作word文檔的方法)???????publicstringCreateWordFile(stringCheckedInfo)???????...{???????????stringmessage="";???????????try???????????...{???????????????ObjectNothing=System.Refle
2、ction.Missing.Value;???????????????Directory.CreateDirectory("C:/CNSI");//創(chuàng)建文件所在目錄???????????????stringname="CNSI_"+DateTime.Now.ToShortString()+".doc";???????????????objectfilename="C://CNSI//"+name;//文件保存路徑???????????????//創(chuàng)建Word文檔???????????????Word.ApplicationWordApp=newWord
3、.ApplicationClass();???????????????Word.DocumentWordDoc=WordApp.Documents.Add(refNothing,refNothing,refNothing,refNothing);???????????????//添加頁(yè)眉???????????????WordApp.ActiveWindow.View.Type=WdViewType.wdOutlineView;???????????????WordApp.ActiveWindow.View.SeekView=WdSeekView.wdS
4、eekPrimaryHeader;???????????????WordApp.ActiveWindow.ActivePane.Selection.InsertAfter("[頁(yè)眉內(nèi)容]");???????????????WordApp.Selection.ParagraphFormat.Alignment=Word.WdParagraphAlignment.wdAlignParagraphRight;//設(shè)置右對(duì)齊???????????????WordApp.ActiveWindow.View.SeekView=WdSeekView.wdSeekMa
5、inDocument;//跳出頁(yè)眉設(shè)置???????????????WordApp.Selection.ParagraphFormat.LineSpacing=15f;//設(shè)置文檔的行間距???????????????//移動(dòng)焦點(diǎn)并換行???????????????objectcount=14;???????????????objectWdLine=Word.WdUnits.wdLine;//換一行;????????????????WordApp.Selection.MoveDown(refWdLine,refcount,refNothing);//移
6、動(dòng)焦點(diǎn)????????????????WordApp.Selection.TypeParagraph();//插入段落????????????????//文檔中創(chuàng)建表格????????????????Word.TablenewTable=WordDoc.Tables.Add(WordApp.Selection.Range,12,3,refNothing,refNothing);????????????????//設(shè)置表格樣式????????????????newTable.Borders.OutsideLineStyle=Word.WdLineStyl
7、e.wdLineStyleThickThinLargeGap;????????????????newTable.Borders.InsideLineStyle=Word.WdLineStyle.wdLineStyleSingle;????????????????newTable.Columns[1].Width=100f;????????????????newTable.Columns[2].Width=220f;????????????????newTable.Columns[3].Width=105f;????????????????//填充表格內(nèi)
8、容????????????????newTable.Cell(1,1).Range.Text=