惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Security Affairs
S
Secure Thoughts
P
Proofpoint News Feed
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Schneier on Security
V
Vulnerabilities – Threatpost
Security Archives - TechRepublic
Security Archives - TechRepublic
T
The Exploit Database - CXSecurity.com
A
Arctic Wolf
Latest news
Latest news
Hacker News - Newest:
Hacker News - Newest: "LLM"
AI
AI
T
Troy Hunt's Blog
H
Heimdal Security Blog
美团技术团队
Webroot Blog
Webroot Blog
P
Proofpoint News Feed
Hacker News: Ask HN
Hacker News: Ask HN
Google DeepMind News
Google DeepMind News
P
Privacy & Cybersecurity Law Blog
U
Unit 42
Google DeepMind News
Google DeepMind News
V2EX - 技术
V2EX - 技术
G
Google Developers Blog
N
News and Events Feed by Topic
Project Zero
Project Zero
The Register - Security
The Register - Security
N
Netflix TechBlog - Medium
IT之家
IT之家
月光博客
月光博客
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
N
News and Events Feed by Topic
Simon Willison's Weblog
Simon Willison's Weblog
L
Lohrmann on Cybersecurity
Schneier on Security
Schneier on Security
博客园_首页
Help Net Security
Help Net Security
AWS News Blog
AWS News Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
S
Security @ Cisco Blogs
PCI Perspectives
PCI Perspectives
Cisco Talos Blog
Cisco Talos Blog
C
Cybersecurity and Infrastructure Security Agency CISA
H
Hackread – Cybersecurity News, Data Breaches, AI and More
D
Docker
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
阮一峰的网络日志
阮一峰的网络日志
Spread Privacy
Spread Privacy
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The Hacker News
The Hacker News

博客园 - 戴玮

关于状态模式的思考 实在是忍受不了MSN的巨慢速度,重新换个地方 如果在网页中实现查找功能 asp.net2.0 页面生命周期方法 C#加密与解决 如何自定义一个模板列,并在后台加载 ASP.NET常用的代码集合 - 戴玮 - 博客园 触发器示例代码 ADO.NET2.0分页 - 戴玮 - 博客园 如何查找 Office Web 组件 (OWC) 编程文档和示例 如何将枚举定义翻译成DataTable 网页中调用MSN添加好友工具 如何在XP SP2下面使用DTC Javascript 复制与粘贴 - 戴玮 - 博客园 如何在Component中取得Page对象 使用TransactionScope进行COM+事务处理 - 戴玮 - 博客园 如何在C#中使用EVAL方法 - 戴玮 - 博客园 巨NB的JAVASCRIPT代码 - 戴玮 - 博客园 9月25日C#->WebService中如何传递文件
解决了一年多的问题,狂喜(一年之前)
戴玮 · 2006-11-15 · via 博客园 - 戴玮

今天用了一下午的时间,终于解决了C#通过WORD模板来自动生成WORD文档,以便于客户端打印的测试代码.

原理就是在WORD里面写宏,然后在C#里面调用这些宏.

晚上测试终于,心里很开心.

object oMissing = System.Reflection.Missing.Value;

   Microsoft.Office.Interop.Word.Application  oWord = new Microsoft.Office.Interop.Word.Application(); 

   oWord.Visible = false;
   Microsoft.Office.Interop.Word.Documents  oDocs = oWord.Documents;
   object oFile = @"c:\TestWord.doc";

   Microsoft.Office.Interop.Word.Document  oDoc = oDocs.Open(ref oFile, ref oMissing,
    ref oMissing, ref oMissing, ref oMissing,
    ref oMissing, ref oMissing, ref oMissing,
    ref oMissing, ref oMissing, ref oMissing,
    ref oMissing, ref oMissing, ref oMissing,
    ref oMissing, ref oMissing);

   // Run the macros.
   RunMacro(oWord, new Object[]{"test",this.textBox1.Text});
  

   // Quit Word and clean up.
   oDoc.Close(ref oMissing, ref oMissing, ref oMissing);
   System.Runtime.InteropServices.Marshal.ReleaseComObject (oDoc);
   oDoc = null;
   System.Runtime.InteropServices.Marshal.ReleaseComObject (oDocs);
   oDocs = null;
   oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
   System.Runtime.InteropServices.Marshal.ReleaseComObject (oWord);
   oWord = null;
   MessageBox.Show("ok");

private void RunMacro(object oApp, object[] oRunArgs)
  {
   oApp.GetType().InvokeMember("Run",
    System.Reflection.BindingFlags.Default |
    System.Reflection.BindingFlags.InvokeMethod,
    null, oApp, oRunArgs);
  }
http://support.microsoft.com/default.aspx?scid=kb;zh-cn;306683