0

I face this problem when I try the exe at the user's end. The user has MicosoftExcel 2000 and I have execel 2003. Can someone please help me.

I have created this tool in c# and have used COM

if( strDataSheetFile.Trim().EndsWith( ".xls" ) || strDataSheetFile.Trim().EndsWith( ".xlsx" ) )
        {
            System.IO.StreamWriter file = null;
            if (IfAbFile)
            {
                file = new System.IO.StreamWriter(AbaqusDeckFile.ToString(), true);
            }
            else
            {
                string[] strFILEnamesSplit = strDataSheetFile.Split(new Char[] { '\\' });
                string ExpFile = "";
                int ilnt = 0;
                foreach (string strVal in strFILEnamesSplit )
                {
                    if (ilnt < (strFILEnamesSplit.Length - 1))
                    {
                        ExpFile += strVal;
                        ExpFile += "/";
                    }
                    else
                        ExpFile += "Deck.inp";

                    ilnt += 1;
                }

                file = new System.IO.StreamWriter(ExpFile.ToString(), true);
            }

            List<List<double>> List_SheetValues = new List<List<double>>();

            Excel.Application objexcel;
            Excel.Workbook wbexcel;

            Excel.Worksheet wsheet;

            objexcel = new Excel.Application();

            //strDataSheetFile = @"C:\Ajoy\Demos\IsoMount\IsoMount_Springs_database_updated.xls";

            if (File.Exists(strDataSheetFile))
                wbexcel = objexcel.Workbooks.Open(strDataSheetFile);
            else
            {
                MessageBox.Show(" Please state the number of springs", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.UseWaitCursor = false;
                return;
            }
JMK
  • 27,273
  • 52
  • 163
  • 280
user2982029
  • 84
  • 11
  • It looks like, in your VBA code, you are using a type library which is registered on your machine, but not on the end users machine. Check the references dialogue for anything saying with **(missing)** at the end on the end user machine. – JMK Nov 14 '13 at 11:12
  • Hi JMK, i have coded this in C#. Do you have a suggesion please – user2982029 Nov 14 '13 at 11:16
  • Without actually putting your code into the question and identifying which lines are causing you trouble we don't have much to go on. – JMK Nov 14 '13 at 11:18
  • JMK, I have posted a part of my code where i am trying to open the excel file..... – user2982029 Nov 14 '13 at 11:22

2 Answers2

1

This is probably happening in you use early (compile time) binding to the Excel type library.

The user has a different version of the type library (2000 vs 2003 on your machine). Have you tried installing Excel 2000 on your machine & compiling your app by linking to the 2000 type library.

Alternatively, if you are not using any 2003 specific features AND the the functions & objects you are using have not changed between those 2 versions, you can try late (runtime) binding.

There'll be a slight performance hit & you lose intellisense in the IDE but should make your app portable across all Excel versions that support those objects & functions

Ashley Pillay
  • 868
  • 4
  • 9
  • Hi Robertdeniro, Thanks for the reply. Can you please tell me how do I do the late runtime binding. Moreover, I am looking at a generic way of solving this problem, since there could be multiple users of this app, and this app should be totally independent to the excel version the user may be using.... – user2982029 Nov 14 '13 at 11:19
  • Take a look at this article http://amri-mlee.com/articles/c-late-binding-excel-interop-tutorial-part-1/ This is probably a lot easier in VB (if it still has the CreateObject method) But basically involves calling Activator.CreateInstance(Type.GetTypeFromProgID("Excel.Application"). I've never used this in C# myself but am familiar with this error from my VB days. The samples on that site declare the return type as object & then use InvokeMember on that variable. It's much easier if you declare it as dynamic & then you can probably leave most of your code as it. – Ashley Pillay Nov 14 '13 at 11:39
  • Read through these as well https://www.google.co.za/search?q=c%23+late+binding+dynamic – Ashley Pillay Nov 14 '13 at 11:46
  • @robertdeniro : Thank you sir, i think we should follow the http://amri-mlee.com/articles/c-late-binding-excel-interop-tutorial-part-1/ link to solve this. – Sudhakar Tillapudi Nov 14 '13 at 12:07
0

i think the problem is you are compiling your Project as 'x64' 64bit instead of that compile it as x86 32 bit Application. Follow the below steps:

 ->Right click on Project
 ->Select Properties
 ->Select Build tab
 ->Change  "Platform Target" to "x86"
 ->now run the Project.
Sudhakar Tillapudi
  • 25,935
  • 5
  • 37
  • 67
  • Hi Sudhakar, thanks for the reply. I tried it but then i am getting the same error. The 32 bit made no difference. Can you please give me another suggesion please if any – user2982029 Nov 14 '13 at 11:11
  • could you please build your application by referring Excel 2000 Library instead of 2003? as your client has excel 2000. – Sudhakar Tillapudi Nov 14 '13 at 11:16
  • sure, that makes sense Sudhakar. I am actually looking out for a solution, that could be generic, since there could be another user who has someother version and I cant keep rebulding the app, right. – user2982029 Nov 14 '13 at 11:24
  • You are absolutely correct, we should not make our App to be dependant on particular version of Excel. – Sudhakar Tillapudi Nov 14 '13 at 11:25
  • So this code in c# has the COM facilitated in accessing the excel file and getting on the values from the cells. I wish there be a way where this facility, does not be excel version dependent after bulding it. Still hanging on for a solution, Sudhakar. May be this could be a scope for a new development need. Dont know – user2982029 Nov 14 '13 at 11:30
  • this link should help us : http://stackoverflow.com/questions/19023141/loading-all-com-types-of-excel-dynamically – Sudhakar Tillapudi Nov 14 '13 at 11:44