{"id":753,"date":"2017-12-05T14:46:04","date_gmt":"2017-12-05T06:46:04","guid":{"rendered":"http:\/\/www.mrtblog.cn\/?p=753"},"modified":"2023-03-06T22:02:28","modified_gmt":"2023-03-06T14:02:28","slug":"c%e5%a4%9a%e7%89%88%e6%9c%acoffice%e5%9c%a8winform%e5%ba%94%e7%94%a8%e4%b8%ad%e7%9a%84%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"http:\/\/www.mrtblog.cn\/?p=753","title":{"rendered":"[C#]\u591a\u7248\u672cOffice\u5728WinForm\u5e94\u7528\u4e2d\u7684\u4f7f\u7528"},"content":{"rendered":"<div class='epvc-post-count'><span class='epvc-eye'><\/span>  <span class=\"epvc-count\"> 2,422<\/span><span class='epvc-label'> Views<\/span><\/div><p>\u539f\u672c\u5728\u4e3aWinform\u505aExcel\u5bfc\u51fa\u5de5\u4f5c\u65f6\uff0c\u4f7f\u7528\u7684Office2010\u7248\u672c\u3002<\/p>\n<p>\u521b\u5efaExcel\u5bf9\u8c61\u65b9\u5f0f\u4e3a\uff1a<\/p>\n<pre class=\"highlight\"><code class=\"language-csharp line-numbers\">Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.ApplicationClass()<\/code><\/pre>\n<p>\u4f46\u662f\u670d\u52a1\u5668\u5b89\u88c5\u7684\u7248\u672c\u4e3aoffice2003\uff0c\u53c2\u8003<a href=\"http:\/\/blog.csdn.net\/baidu_27474941\/article\/details\/52410693\">http:\/\/blog.csdn.net\/baidu_27474941\/article\/details\/52410693<\/a><\/p>\n<p>\u4fee\u6539\u5d4c\u5165\u4e92\u64cd\u4f5c\u7c7b\u578b\u4e3aTrue\uff0c\u7279\u5b9a\u7248\u672c=false\u3002\u679c\u7136\u5982\u9884\u6599\u7684\u62a5\u9519\u3002\u5c06\u521b\u5efa\u65b9\u5f0f\u6539\u4e3a:<\/p>\n<pre class=\"highlight\"><code class=\"language-csharp line-numbers\">Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application()<\/code><\/pre>\n<p>\u62a5\u9519:<strong>Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: \u201cobject\u201d\u672a\u5305\u542b\u201cget_Range\u201d\u7684\u5b9a\u4e49<\/strong><\/p>\n<p>\u518d\u4fee\u6539\u51fd\u6570:<\/p>\n<pre class=\"highlight\"><code class=\"language-csharp line-numbers\">get_Range(worksheet.Cells[1, 1], worksheet.Cells[1, columnCount])\n-&gt;\nRange[worksheet.Cells[1, 1], worksheet.Cells[1, columnCount]]\n<\/code><\/pre>\n<p>\u7f16\u8bd1\u4e0a\u5c31\u6ca1\u6709\u95ee\u9898\u4e86\u3002<\/p>\n<p>\u4f46\u662f\u5728\u591a\u6b21\u5220\u9664\u91cd\u88c5Office wps\u4e4b\u540e\u53ea\u4fdd\u7559Office2003\u62a5\u9519\uff1a<strong>System.InvalidCastException: \u65e0\u6cd5\u5c06\u7c7b\u578b\u4e3a\u201cSystem.__ComObject\u201d\u7684 COM \u5bf9\u8c61\u5f3a\u5236\u8f6c\u6362\u4e3a\u63a5\u53e3\u7c7b\u578b\u201cMicrosoft.Office.Interop.Excel.Application\u201d\u3002\u6b64\u64cd\u4f5c\u5931\u8d25\u7684\u539f\u56e0\u662f\u5bf9 IID \u4e3a\u201c{000208D5-0000-0000-C000-000000000046}\u201d\u7684\u63a5\u53e3\u7684 COM \u7ec4\u4ef6\u8c03\u7528 QueryInterface \u56e0\u4ee5\u4e0b\u9519\u8bef\u800c\u5931\u8d25: \u52a0\u8f7d\u7c7b\u578b\u5e93\/DLL \u65f6\u51fa\u9519\u3002 (\u5f02\u5e38\u6765\u81ea HRESULT:0x80029C4A (TYPE_E_CANTLOADLIBRARY))<\/strong><\/p>\n<p>\u53c2\u8003<a href=\"https:\/\/www.cnblogs.com\/bile\/p\/3520439.html\">https:\/\/www.cnblogs.com\/bile\/p\/3520439.html<\/a><\/p>\n<p>\u5728\u6ce8\u518c\u8868\u4e2d\u627e\u5230\uff1aHKEY_CLASSES_ROOT\\TypeLib\\{00020813-0000-0000-C000-000000000046}\\1.6&nbsp;\u5220\u9664<\/p>\n<p>office&nbsp;2003\u5bf9\u5e94\u7684\u662f1.5\uff0c\u6240\u4ee5\u5220\u96641.6<br \/>\noffice&nbsp;2007\u5bf9\u5e94\u7684\u662f1.6\uff0c\u6240\u4ee5\u8981\u6839\u636e\u60c5\u51b5\u5224\u65ad<br \/>\nWPS2016\u4f30\u8ba1\u548coffice2007\u5bf9\u5e94\u4e00\u6837\uff0c\u6240\u4ee5\u5b8c\u5168\u5220\u9664\u5c31\u80fd\u89e3\u51b3\u95ee\u9898<\/p>\n","protected":false},"excerpt":{"rendered":"<p>2,422 Views\u539f\u672c\u5728\u4e3aWinform\u505aExcel\u5bfc\u51fa\u5de5\u4f5c\u65f6\uff0c\u4f7f\u7528\u7684Office2010\u7248\u672c\u3002 \u521b\u5efaEx [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[92],"tags":[],"class_list":["post-753","post","type-post","status-publish","format-standard","hentry","category-project"],"_links":{"self":[{"href":"http:\/\/www.mrtblog.cn\/index.php?rest_route=\/wp\/v2\/posts\/753","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.mrtblog.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.mrtblog.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.mrtblog.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.mrtblog.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=753"}],"version-history":[{"count":3,"href":"http:\/\/www.mrtblog.cn\/index.php?rest_route=\/wp\/v2\/posts\/753\/revisions"}],"predecessor-version":[{"id":1235,"href":"http:\/\/www.mrtblog.cn\/index.php?rest_route=\/wp\/v2\/posts\/753\/revisions\/1235"}],"wp:attachment":[{"href":"http:\/\/www.mrtblog.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=753"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.mrtblog.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=753"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.mrtblog.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=753"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}