C#操作word文档
来源:互联网 发布:cad网络综合布线教程 编辑:程序博客网 时间:2024/04/30 05:53
C#与word文档的操作非常实用,其中为常见的内容除了读写操作外,就是打印预览、将word数据读取到数据库、将文本转换为网页文件等内容。
打印预览主要用到了PrintPreview方法,
其核心代码如下:
将word中的数据读取到SQL数据库中,首先将word中的数据读取到数据集合中,再将集合中的数据添加到SQL中。
使用SaveAs方法是将word转换为HTML网页的有效方法之一,实现如下:
打印预览主要用到了PrintPreview方法,
其核心代码如下:
btn_Open.Enabled=false; ThreadPool.QueueUserWorkItem (pp)—> {G_wa=new Microsoft.Ofice.Interop.Word.Application; G_wa.visible=true; ObjectP_FileName=G_OpenFileDialog.FileName; Word.Document P_Document=G_wa.Documents.Open( ref P_FileName,ref G_missing,ref G_missing,ref G_missing,ref G_missing, ref G_missing,ref G_missing,ref G_missing,ref G_missing,ref G_missing, ref G_missing); P_Document.PrintPreview(); }); }
将word中的数据读取到SQL数据库中,首先将word中的数据读取到数据集合中,再将集合中的数据添加到SQL中。
try{ G_wa.ActveDcument.Save(); object.Save-false; ((Word.Application)C_wa.Appication).Quit( ref P_Save.ref G_missing,ref G_missing);}catch(Exceoption ex){ MessageBox.show( ex.Message,"提示!")}try{ InsertData();}catch(Exception ex){ MessageBox.show( ex.Message,"提示!")}
使用SaveAs方法是将word转换为HTML网页的有效方法之一,实现如下:
try{ G_wa.ActiveDocument.Save(); ((Word.Application)C_wa.Appication).Quit( ref P_Save.ref G_missing,ref G_missing);}catch(Exceoption ex){ MessageBox.WrteLine(ex.Message)}SaveFileDialog P_SaveFileDialog=new SaveFileDialog();P_SaveFileDialog..Filter="*.html/*.html";DialogResult P_DialogResult-P_SaveFileDialog.ShowDialog();if(P_DialogResult==DialogResult.OK){ object P_str_path=P_SaveFleDialog.FileName; Threadpool.QueueUserWorkItem( (pp)—> {G_wa=new Microsoft.Ofice.Interop.Word.Application; G_wa.visible=true; Word.Document P_wd=G_wa.Document.Open; Word.Document P_Document=G_wa.Documents.Open( ref P_FilePath,ref G_missing,ref G_missing,ref G_missing,ref G_missing, ref G_missing,ref G_missing,ref G_missing,ref G_missing,ref G_missing, ref G_missing); oject P_Format=Word.SaveFormat.wdFormatHTML; P_wd.SaveAs( ref P_str_path ref P_Format,ref G_missing,ref G_missing,ref G_missing,ref G_missing, ref G_missing,ref G_missing,ref G_missing,ref G_missing,ref G_missing, ref G_missing,ref G_missing,ref G_missing); ((Word.Application)C_wa.Appication).Quit( ref P_missing.ref G_missing,ref G_missing); this.Invoke( (MethodInvoker)(()=> { messagebox.show("文件已创建","提示!") })) })}}
0 0
- c#操作word文档
- C#操作Word文档
- C#操作Word文档
- C#操作Word文档
- C# 操作word文档
- C#操作Word文档
- C#操作word文档
- C#操作Word文档
- C# 操作word文档
- C#操作word文档
- C#操作Word文档
- C#操作word文档
- C#操作word文档
- C# 操作Word文档
- C#操作Word文档
- C# 操作word文档
- C#操作Word文档
- c#操作Word文档
- Android系统开发(3)——Makefile的编写
- 话题13 --鞭辟入里 条件表达式的类型深入
- swjtu行政自动挂机工具
- C++在类模板中实现友元函数的方法
- 黑客攻击的一般过程
- C#操作word文档
- Jedis分片连接池(分布式)
- Maven构建一个多模块的Spring Boot + Spring MVC项目,完全基于java config
- JTAG各类接口针脚定义及含义
- canopen主站卡定义丨canopen主站卡特性
- IOS---加急审核
- iOS判断设备型号
- Redis资源
- Swift 的UIColor 类的详解使用和十六进制转RGB