Ask a questionAsk a question
 

QuestionCan somebody help me in writing data to excel 2007 using c#.net?

  • Tuesday, November 03, 2009 10:40 AMcheckoutsree Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi,
    I need assistance in writing data to excel 2007 using c#.net. Previously in vsts 2010 beta 1 release, i wrote code for the same which is not working in beta 2. I am not able to add reference to microsoft.excel.library 12.0

    please help

    Microsoft.Office.Interop.Excel.Application objApp = new Microsoft.Office.Interop.Excel.Application();
                Microsoft.Office.Interop.Excel.Workbook objBook = objApp.Workbooks.Open("C:\\Result1.xls",0,false,5,"","",true,"","\t",false,false,0,1,true,1);
                Microsoft.Office.Interop.Excel.Sheets objSheets = objBook.Worksheets;
                Microsoft.Office.Interop.Excel.Worksheet objSheet = (Microsoft.Office.Interop.Excel.Worksheet)objSheets.get_Item(1);

                //objSheet.Cells[2, 2] = "PASS";
                //objSheet.get_Range("B2").Interior.Color = System.Drawing.Color.Green;
                //objSheet.get_Range("B2").Font.Color = System.Drawing.Color.White;
                //objSheet.get_Range("B2").Font.Bold = true;


    This code is not working . it reports error as
    Error 1 Predefined type 'Microsoft.CSharp.RuntimeBinder.Binder' is not defined or imported TestProject5
    Error 2 One or more types required to compile a dynamic expression cannot be found. Are you missing references to Microsoft.CSharp.dll and System.Core.dll? C:\Documents and Settings\Administrator\My Documents\Visual Studio 2010\Projects\TestProject5\CodedUITest1.cs 36 65 TestProject5

All Replies

  • Thursday, November 05, 2009 7:36 PMBen Cline1MVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    What happens when you try to add the reference to the Excel Interop?

    Those errors sound like maybe you reimported your project from Beta 1 and there might have been a conversion problem. You might try recreating the project and references rather than doing a conversion.

    Thanks,
    If this answers your question, please use the "Answer" button to say so | Ben Cline