2012/4/26——第一次项目小记(一)
2012-04-26 20:54
141 查看
PS:写这篇文章的时候,我负责的项目模块基本上已经完工了,除了个别难点的地方还没写完。。。(留着扔给老温解决去吧~~!哇哈哈~!)总之。。。收获良多啊。。基本上已经能熟练的用C#编点小东西了。对于用惯了VC++6.0的小菜鸟VS2010真是能让人抹泪的东西。。。
//--需要解决的问题
*1.用c#打开word文件,并进行简单的读取和写入操作
//--test1.cs要求解决该问题
//--解决时间 2012/4/18凌晨1:20
//********************************
//--项目名称:mytest
//--保存路径:C:\Users\Administrator\Desktop\项目库\work\text
//--作者:小狼
//--最后一次修改时间:2012/4/18
//********************************
Ps:第一次用windows form来做东西。。。蹒跚学步的东西也蛮好玩的。
1.1 添加引用
操作word
和操作excel的原理是差不多的
首先是在引用的类库中添加 Microsoft.Office.Interop.Word
1.2 添加命名空间
//--然后在代码中添加命名空间
1.3 基本对象定义
//--需要用的时候,定义
//------则生成应用
//--定义文件对象
//------------则生成文件对象
1.4 应用代码
1.4.1 文件打开
//--以下代码用于文件的打开
//--需要解决的问题
*1.用c#打开word文件,并进行简单的读取和写入操作
//--test1.cs要求解决该问题
//--解决时间 2012/4/18凌晨1:20
//********************************
//--项目名称:mytest
//--保存路径:C:\Users\Administrator\Desktop\项目库\work\text
//--作者:小狼
//--最后一次修改时间:2012/4/18
//********************************
Ps:第一次用windows form来做东西。。。蹒跚学步的东西也蛮好玩的。
1.1 添加引用
操作word
和操作excel的原理是差不多的
首先是在引用的类库中添加 Microsoft.Office.Interop.Word
1.2 添加命名空间
//--然后在代码中添加命名空间
using Word = Microsoft.Office.Interop.Word;
1.3 基本对象定义
using Word = Microsoft.Office.Interop.Word;
//--需要用的时候,定义
Word.Application m_objWord =new Word.Application();
//------则生成应用
//--定义文件对象
Word.Document oDocument1_key ;
//------------则生成文件对象
1.4 应用代码
1.4.1 文件打开
//--以下代码用于文件的打开
public void CreateWordDocument(string FileName, ref Word.Document wDoc, ref Word.Application WApp) { if (FileName == "") return; Word.Document thisDocument = null; Word.FormFields formFields = null; Word.Application thisApplication = new Word.ApplicationClass(); thisApplication.Visible = true; thisApplication.Caption = ""; thisApplication.Options.CheckSpellingAsYouType = false; thisApplication.Options.CheckGrammarAsYouType = false; Object filename = FileName; Object ConfirmConversions = false; Object ReadOnly = true; Object AddToRecentFiles = false; Object PasswordDocument = System.Type.Missing; Object PasswordTemplate = System.Type.Missing; Object Revert = System.Type.Missing; Object WritePasswordDocument = System.Type.Missing; Object WritePasswordTemplate = System.Type.Missing; Object Format = System.Type.Missing; Object Encoding = System.Type.Missing; Object Visible = System.Type.Missing; Object OpenAndRepair = System.Type.Missing; Object DocumentDirection = System.Type.Missing; Object NoEncodingDialog = System.Type.Missing; Object XMLTransform = System.Type.Missing; try { Word.Document wordDoc = thisApplication.Documents.Open(ref filename, ref ConfirmConversions, ref ReadOnly, ref AddToRecentFiles, ref PasswordDocument, ref PasswordTemplate, ref Revert, ref WritePasswordDocument, ref WritePasswordTemplate, ref Format, ref Encoding, ref Visible, ref OpenAndRepair, ref DocumentDirection, ref NoEncodingDialog, ref XMLTransform); thisDocument = wordDoc; wDoc = wordDoc; WApp = thisApplication; formFields = wordDoc.FormFields; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
相关文章推荐
- Flex 4.6 手机项目第一次开发小记
- 团队项目第一次冲刺(7)
- cocos2dx项目在android平台第一次安装的一个奇怪的bug
- IDEA中文项目问题解决小记
- 实训的第一次考核项目 基于socket 的客户与服务端 在线购物管理系统
- 第一次项目开发
- 菜鸟第一次wp项目总结
- 编程之路始:第一次画板项目感想
- 第一次新建maven项目后报错:Failure to transfer org.codehaus.plexus:plexus:pom:3.0.1
- 校招总结+最近的项目小记
- 第一次项目二-1c++上机报告
- 第一次eclipse部署web项目到tomcat流程
- 软件项目第一次Sprint评价
- 第一次在项目中使用JQuery遇到的一点问题
- 团队作业4——第一次项目冲刺(Alpha版本)2017.4.24
- 团队作业4——第一次项目冲刺(Alpha版本) Day2
- 第一次上机实践 项目一 宣告主权
- 团队作业4——第一次项目冲刺(Alpha版本)4th day
- 团队作业4——第一次项目冲刺(Alpha版本)2017.4.26