Microsoft.Office.Interop.Excel doesn't work on 64 bit

后端 未结 1 1231
眼角桃花
眼角桃花 2020-12-17 23:23

I\'ve encountered a problem when developing on MS Visual Web Developer 2008 Express Ed. Developing ASP.NET C# on Windows7 64 bit OS.

I\'m trying to open an Excel doc

相关标签:
1条回答
  • 2020-12-18 00:04

    After digging the internet I found out that there is a bug in Microsoft Interop with COM objects (at least with my case which is MS Excel 2010).

    The bug is that .NET checks that your thread (C# or VB code) localization is suitable to MS Excel localization you installed earlier, and if not it tells that the Microsoft.Office.Interop library is old or invalid.

    Your thread localization is derived from your computer regional settings (from the control panel --> regional and language)

    Then there are two options to solve this problem:

    1. To change your thread localization (by code)
    2. Install language pack for your Office

    The first solution goes like this:

    using System.Threading;     // For setting the Localization of the thread to fit
    using System.Globalization; // the of the MS Excel localization, because of the MS bug
    
    Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
    excelFileName = System.IO.Path.Combine(excelPath, "Ziperty Buy Model for Web 11_11_2011.xlsm");
    

    Hope it helps :) gr8 day

    0 讨论(0)
提交回复
热议问题