最近在网上寻找word输出语句,很杂。。。最后我弄出来之后就稍加整理了一下,现在贴出来供大家参考。
首先得添加引用,就是word的引用,一共是两个,一个是“Microsoft.Office.Interop.Word“,而另外一个是”
Office“这两个好像是不必要的一起添加,大家试一试吧,我现在是两个添加的就好使。
添加引用的方法:在“解决方案资源管理器”里边 --> 右键点击“引用”-->“添加引用”-->选择上边提到的引用就行了。
之后就是把代码贴上:··· ···
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Word = Microsoft.Office.Interop.Word; --------这个是后加上去的
private void btn浏览输出_Click(object sender, EventArgs e)
{
object Nothing = System.Reflection.Missing.Value;
object missing = System.Reflection.Missing.Value;
//创建word文档
Word.Application wordApp = new Word.ApplicationClass();
Word.Document wordDoc = wordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);
//设置文档宽度
wordApp.Selection.PageSetup.LeftMargin = wordApp.CentimetersToPoints(float.Parse("2"));
wordApp.ActiveWindow.ActivePane.HorizontalPercentScrolled = 11;
wordApp.Selection.PageSetup.RightMargin = wordApp.Cen