通行证: 用户 密码
http://www.pconline.cn/
汽车网 | 游戏网 | 时尚女性
分站:北京 上海 广州 深圳 香港
广西 重庆 山东 江苏 辽宁 福建
首 页 | 今日报价 | 产业资讯 | 数码世界 | 硬件资讯 | 软件资讯 | 下 载 | 游 戏 |
论 坛 | 产 品 库 | 渠道商情 | 招聘培训 | 二    手 | 评 测 室 | 导 购 | 社 区 |
摄影
部落
手 机
数码相机
随身听
 DIY配件
笔记本
 台式机
摄像机
精品廊
-
您现在的位置: 软件资讯 > 开发特区 > .net技术 > C# 免费新闻代码RSS新闻聚合
  C#的office操作[word&Excel] 出处:c#社区收集整理
[ 2005-07-27 10:07:46 ] 作者:inzaghizxm 责任编辑:moningfeng

  C#实现对Word文件读写

  手头上的一个项目报表相对比较简单,所以报表打印采用VBA引擎,通过定制Word模版,然后根据模版需要填充数据,然后OK,打印即可。

  实现方法:首先需要引用VBA组建,我用的是Office2003 Professional,Dll版本号为Microsoft Word11.0


  另外当然还需要引用Interop.Word.Dll.

  代码如下:

///#region 打开Word文档,并且返回对象wDoc,wDoc
///


/// 打开Word文档,并且返回对象wDoc,wDoc
///

/// 完整Word文件路径+名称
/// 返回的Word.Document wDoc对象
/// 返回的Word.Application对象

public static 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);
}

}
#endregion


Flash剧场全新改版,精品Flash让你看够玩够!


[1] [2] [3] [4] [下一页]

更多相关搜索: C#.. office.. word.. Excel..
正在加载评论,请稍候…

发给好友 我要报错 投稿给我们 加入收藏 返回顶部

本栏今日更新
相关文章
·FireTune新版:Firfox优化轻松搞定
·音效增强!DFX 7.500 for WMP发布
·微软恶意软件移除工具可杀Zotob
·Google或MSN地图?Flash Earth整合
·强力清除软件使用后的蛛丝马迹
·六大闪光点:QQ2005 beta 3泄漏版试用
·超酷!Mac系统播客工具提供Win版
·PConline联合超级兔子狂送注册码!
·C#+Oracle开发中执行存储过程问题
·用好Office 2003中的翻译功能
·用数字证书保护你的文档
·制作课件时获取图标的技巧
·如何使用 ASP.NET查询和显示 Excel 数据
·Excel格式填充为何失效
·c#多线程教学(5):Case 学习多线程
·轻松标注Excel表格中的无效数据

完美时尚娱乐:2004年腾讯QQ评测大观
精彩无限:MSN Shell4使用指南
亲手制作鲜花情人贺卡送给她
挑战伏明霞?企鹅跳水游戏,看你能得多少分?

新闻搜索
高级搜索
Flash排行榜
·快来看看!芙蓉姐姐进军歌坛
·动感漂移-头文字D赛车
·头文字D插曲-一路向北
·暴笑恶搞MV-《从良》
·笑谈广东话-叽叽噶噶
·恶搞!PP鸡打劫记之一
·下辈子如果我还记得你
·疯狂射击游戏-火凤凰号
·悲怆!披着羊皮的狼
·搞笑MV-亲爱的对不起
热点专题
·挑战十大Flash智益游戏
·QQ辅助软件使用指南
·向"流氓软件"大声说不!
·惜别!毕业十大必唱歌曲
·常用软件的另类用法集
·搜索技巧:网罗天下的乐趣
·电脑艺术设计大师之路连载
·老歌歪唱Flash MV爆笑欣赏
·超级兔子狂送注册码!
·引领时尚:K8翻唱上传技巧
·Photoshop立体光影魔术!
·Photoshop绘水果饕餮大餐
IT培训十大热门文章
-