打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
C# VS2012操作word文档 (一).创建文档
namespace PDFTest{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } object path; //声明文件路径变量 string wordstr; //声明word文档内容 MSWord.Application wordApp; //声明word应用程序变量 MSWord.Document worddoc; //声明word文档变量 //点击'创建'按钮实现创建word文件 private void button1_Click(object sender, EventArgs e) { if (textBox1.Text == '' || textBox2.Text == '') { MessageBox.Show('请输入路径和文档名信息'); } else { //初始化变量 object Nothing = Missing.Value; //COM调用时用于占位 object format = MSWord.WdSaveFormat.wdFormatDocument; //Word文档的保存格式 wordApp = new MSWord.ApplicationClass(); //声明一个wordAPP对象 worddoc = wordApp.Documents.Add(ref Nothing, ref Nothing,                     ref Nothing, ref Nothing); //向文档中写入内容 wordstr = textBox3.Text; worddoc.Paragraphs.Last.Range.Text = wordstr; //保存文档 path = textBox2.Text + '\\' + textBox1.Text; //设置文件保存路劲 worddoc.SaveAs(ref path, ref format, ref Nothing, ref Nothing,                     ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing,                     ref Nothing, ref Nothing, ref Nothing, ref Nothing);  //关闭文档 worddoc.Close(ref Nothing, ref Nothing, ref Nothing); //关闭worddoc文档对象 wordApp.Quit(ref Nothing, ref Nothing, ref Nothing); //关闭wordApp组对象 MessageBox.Show('文档创建成功!'); } } }}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
C#获取Word文档页数,并跳转到指定的页面获取页面信息
html在线显示word怎么在html中显示word
asp.net操作Word
c# 操作Word总结
[转]C#操作Word的超详细总结
关于c#操作word文档
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服