{"id":24240,"date":"2024-05-27T15:40:56","date_gmt":"2024-05-27T07:40:56","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=24240"},"modified":"2024-05-27T15:40:56","modified_gmt":"2024-05-27T07:40:56","slug":"word%e5%ae%8f%e5%b0%81%e8%a3%85%e6%88%90exe%e8%a6%81%e6%80%8e%e4%b9%88%e5%81%9a%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/24240\/","title":{"rendered":"word\u5b8f\u5c01\u88c5\u6210exe\u8981\u600e\u4e48\u505a\uff1f"},"content":{"rendered":"

\u5c06 Word \u5b8f\u5c01\u88c5\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff08exe\uff09\u53ef\u4ee5\u65b9\u4fbf\u7528\u6237\u5728\u6ca1\u6709\u5b89\u88c5 Microsoft Office \u7684\u60c5\u51b5\u4e0b\u8fd0\u884c Word \u5b8f\u3002\u8fd9\u79cd\u65b9\u6cd5\u53ef\u4ee5\u51cf\u5c11\u7528\u6237\u7684\u64cd\u4f5c\u6b65\u9aa4\u5e76\u63d0\u9ad8\u7528\u6237\u4f53\u9a8c\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5c06 Word \u5b8f\u5c01\u88c5\u6210 exe \u6587\u4ef6\u3002<\/p>\n

\u9996\u5148\uff0c\u9700\u8981\u4f7f\u7528 Visual Studio \u5de5\u5177\u6765\u521b\u5efa C# \u7a0b\u5e8f\u3002\u5728 Visual Studio \u4e2d\uff0c\u65b0\u5efa\u4e00\u4e2a Windows \u7a97\u4f53\u5e94\u7528\u7a0b\u5e8f\uff0c\u5e76\u5728\u7a97\u4f53\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u201cButton\u201d\u6309\u94ae\u3002\u5728\u5355\u51fb\u6309\u94ae\u65f6\uff0c\u8be5\u7a0b\u5e8f\u5c06\u4f1a\u8c03\u7528 Word \u5b8f\u3002<\/p>\n

\u63a5\u4e0b\u6765\uff0c\u9700\u8981\u5c06 Word \u5b8f\u5d4c\u5165\u5230 C# \u7a0b\u5e8f\u4e2d\u3002\u9996\u5148\uff0c\u6253\u5f00 Word \u6587\u4ef6\u5e76\u542f\u7528\u5f00\u53d1\u5de5\u5177\u680f\u3002\u5728\u5f00\u53d1\u5de5\u5177\u680f\u4e2d\uff0c\u70b9\u51fb\u201cVisual Basic\u201d\u6309\u94ae\uff0c\u6253\u5f00 Visual Basic \u7f16\u8f91\u5668\u3002\u5728 Visual Basic \u7f16\u8f91\u5668\u4e2d\uff0c\u9009\u62e9\u201c\u63d2\u5165\u201d\u9009\u9879\u5361\uff0c\u7136\u540e\u9009\u62e9\u201c\u6a21\u5757\u201d\u4ee5\u521b\u5efa\u4e00\u4e2a\u65b0\u6a21\u5757\u3002\u5728\u6a21\u5757\u4e2d\u7f16\u5199 Word \u5b8f\u4ee3\u7801\u3002<\/p>\n

\u5728 C# \u7a0b\u5e8f\u4e2d\uff0c\u9700\u8981\u4f7f\u7528 Microsoft.Office.Interop.Word \u5e93\u6765\u8c03\u7528 Word \u5b8f\u3002\u5728\u7a97\u4f53\u4ee3\u7801\u4e2d\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n

“`<\/p>\n

using System.Reflection;<\/p>\n

using Word = Microsoft.Office.Interop.Word;<\/p>\n

private void button1_Click(object sender, EventArgs e)<\/p>\n

{<\/p>\n

Word.Application wordApp = new Word.Application();<\/p>\n

wordApp.Visible chm\u8f6cexe<\/a>= false;<\/p>\n

object missing = Missing.Value;<\/p>\n

object path = @”C:\\Users\\username\\Documents\\WordFile.docm”; \/\/ Word \u6587\u4ef6\u8def\u5f84<\/p>\n

object confirmConversions = false;<\/p>\n

object readOnly = false;<\/p>\n

object addToRecentFiles = false;<\/p>\n

object passwordDocument = Missing.Value;<\/p>\n

object passwordTemplate = Missing.Value;<\/p>\n

object revert = false;<\/p>\n

object writePasswordDocument = Missing.Value;<\/p>\n

object writePasswordTemplate = Missing.Value;<\/p>\n

object format = Missing.Value;<\/p>\n

object encoding = Missing.Value;<\/p>\n

object oVisible = true;<\/p>\n

object openAndRepair = false;<\/p>\n

object documentDirection = Missing.Value;<\/p>\n

object noEncodingDialog = true;<\/p>\n

object xmlTransform = Missing.Value;<\/p>\n

Word.Document wordDoc = wordApp.Documents.Open(ref path, ref confirmConversions, ref readOnly, ref addToRecentFiles, ref passwordDocument, ref passwordTemplate, ref revert, ref writePasswo<\/p>\n

<\/figure>\n<\/p>\n

rdDocument, ref writePasswordTemplate, ref format, ref encoding, ref oVisible, ref openAndRepair, ref documentDirection, ref noEncodingDialog, ref xmlTransform);<\/p>\n

wordApp.Run(“MacroName”); \/\/ Word \u5b8f\u540d\u79f0<\/p>\n

wordDoc.Close();<\/p>\n

wordApp.Quit();<\/p>\n

}<\/p>\n

“`<\/p>\n

\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u9996\u5148\u521b\u5efa\u4e86\u4e00\u4e2a Word \u5e94\u7528\u7a0b\u5e8f\u5bf9\u8c61\uff0c\u5e76\u5c06\u5176\u8bbe\u7f6e\u4e3a\u4e0d\u53ef\u89c1\u3002\u7136\u540e\uff0c\u4f7f\u7528 Microsoft.Office.Interop.Word \u5e93\u6253\u5f00 Word \u6587\u4ef6\uff0c\u5e76\u8fd0\u884c\u6307\u5b9a\u7684 Word \u5b8f\u3002\u6700\u540e\uff0c\u5173\u95ed Word \u6587\u6863\u5e76\u9000\u51fa Word \u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n

\u5b8c\u6210\u4e0a\u8ff0\u6b65\u9aa4\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528 Visual Studio \u5de5\u5177\u6765\u751f\u6210 exe \u6587\u4ef6\u3002\u5728 Visual Studio \u4e2d\uff0c\u9009\u62e9\u201c\u751f\u6210\u201d\u9009\u9879\u5361\uff0c\u7136\u540e\u9009\u62e9\u201c\u751f\u6210\u89e3\u51b3\u65b9\u6848\u201d\u3002<\/p>\n

\u5728\u751f\u6210 e\u5982\u4f55\u5236\u4f5c\u4e00\u4e2a\u7535\u8111\u8f6f\u4ef6<\/a>xe \u6587\u4ef6\u540e\uff0c\u7528\u6237\u53ef\u4ee5\u5c06\u8be5\u6587\u4ef6\u53d1\u9001\u7ed9\u5176\u4ed6\u4eba\u4f7f\u7528\u3002\u5f53\u7528\u6237\u53cc\u51fb exe \u6587\u4ef6\u65f6\uff0c\u7a0b\u5e8f\u5c06\u4f1a\u8fd0\u884c\u5e76\u81ea\u52a8\u8c03\u7528 Word \u5b8f\u3002<\/p>\n

\u603b\u4e4b\uff0c\u5c06 Word \u5b8f\u5c01\u88c5\u6210 exe \u6587\u4ef6\u53ef\u4ee5\u65b9\u4fbf\u7528\u6237\u5728\u6ca1\u6709\u5b89\u88c5 Microsoft Office \u7684\u60c5\u51b5\u4e0b\u8fd0\u884c Word \u5b8f\u3002\u9700\u8981\u4f7f\u7528 Visual Studio \u5de5\u5177\u521b\u5efa C# \u7a0b\u5e8f\uff0c\u5e76\u4f7f\u7528 Microsoft.Office.Interop.Word \u5e93\u6765\u8c03\u7528 Word \u5b8f\u3002\u6700\u540e\uff0c\u751f\u6210 exe \u6587\u4ef6\u5e76\u5c06\u5176\u53d1\u9001\u7ed9\u5176\u4ed6\u4eba\u4f7f\u7528\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5c06 Word \u5b8f\u5c01\u88c5\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff08exe\uff09\u53ef\u4ee5\u65b9\u4fbf\u7528\u6237\u5728\u6ca1\u6709\u5b89\u88c5 Microsoft Office \u7684\u60c5\u51b5\u4e0b\u8fd0\u884c Word \u5b8f\u3002\u8fd9\u79cd\u65b9\u6cd5\u53ef\u4ee5\u51cf\u5c11\u7528\u6237\u7684\u64cd\u4f5c\u6b65\u9aa4\u5e76\u63d0\u9ad8\u7528\u6237\u4f53\u9a8c\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5c06 Wor<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[7714,16,637,89,23069],"topic":[],"class_list":["post-24240","post","type-post","status-publish","format-standard","hentry","category-exekf","tag-rpm","tag-16","tag-exe","tag-89","tag-23069"],"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/24240","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/comments?post=24240"}],"version-history":[{"count":1,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/24240\/revisions"}],"predecessor-version":[{"id":24277,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/24240\/revisions\/24277"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=24240"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=24240"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=24240"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=24240"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}