Answered Excel SpreadSheet

  • Sunday, March 25, 2012 5:14 PM
     
     
    I have some problems to open an excel spreadsheet in C#. I want to use OLE automation to get an excel object in my form. Therefore, I don't know how to use it. Does someone know how to get an OLE object to open an excel spreadsheet? (I don't want to use OLEDB).

    Qual é o caminho para ser um bom programador?! Resp: Estudar, estudar e estudar...

All Replies

  • Sunday, March 25, 2012 7:43 PM
     
     
    Somebody here might.

    Regards David R
    ---------------------------------------------------------------
    The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones.
    Object-oriented programming offers a sustainable way to write spaghetti code. - Paul Graham.
    Every program eventually becomes rococo, and then rubble. - Alan Perlis
    The only valid measurement of code quality: WTFs/minute.

  • Monday, March 26, 2012 9:39 AM
     
     

    Hi try this link it might help you.http://office.microsoft.com/en-us/powerpoint-help/set-up-an-ole-object-to-run-during-a-presentation-HA010199733.aspx

    If you don't want to use OLEDB then y do u wanna know about it??
    Anyways I friend of mine came across this simple tools for online spreadsheets operations its CollateBox http://www.collatebox.com/ have a look at thi one. It might also be of some help to u.

  • Monday, March 26, 2012 9:51 AM
     
     

    Check with this

    http://www.codeproject.com/Articles/8500/Reading-and-Writing-Excel-using-OLEDB 

    and 

    http://davidhayden.com/blog/dave/archive/2006/05/26/2973.aspx


    If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".

  • Tuesday, March 27, 2012 5:49 AM
    Moderator
     
     Answered Has Code

    Hi Flavio,

    Welcome to the MSDN forum!

    To implement an automation about Excel without using OLEDB, please take a look at the following steps:

    1. Add the reference.

    In the current project, in the solution explorer, right click on the "References" node, and go to the "Add Reference" item. In the "Add Reference" dialog, go to the COM tab, select "Microsoft Excel 14.0 Object Library".

    Notice: If you have Excel 2010 installed, select "Microsoft Excel 14.0 Object Library". For Excel 2007, "Microsoft Excel 12.0 Object Library"; And Excel 2003 ,"Microsoft Excel 11.0 Object Library".

    2. Import the namespace.

    Add the "Microsoft.Office.Interop.Excel" namespace. Here I set an alias "Excel" for the namespace by "using Excel= Microsoft.Office. Interop.Excel;"

    3. Open the Excel workbook.

    Below are some code snippets to open the excel workbook from the specified path:

            // using Excel = Microsoft.Office.Interop.Excel;
            // using System.Threading;
    
            static void Main(string[] args)
            {
                Excel._Application oApp = new Excel.Application();
                oApp.Visible = true;
    
                Excel.Workbook oWorkbook = oApp.Workbooks.Open("E:\\Test\\Test.xlsx");
                Excel.Worksheet oSheet = oWorkbook.Sheets[1];
    
                Thread.Sleep(2000);
    
                oWorkbook.Close();
                oApp.Quit();
    
                oSheet = null;
                oWorkbook = null;
                oApp = null;
    
    
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }

    Here we used the Excel object model. You can also refer this KB: http://support.microsoft.com/kb/302084 

    For further issues about excel development, you may try the following forum:

    http://social.msdn.microsoft.com/Forums/en/exceldev/threads

    Thanks for your understanding and have a nice day.

    yoyo


    Yoyo Jiang[MSFT]
    MSDN Community Support | Feedback to us


  • Thursday, April 05, 2012 2:17 AM
    Moderator
     
     

    Hi Flavio,

    I temporarily mark the reply as answer to close the thread and you can unmark it if it provides no help.

    For further questions about this issue, you can ask them at the Excel for Developers forum:

    http://social.msdn.microsoft.com/Forums/en/exceldev/threads

    Thanks for your understanding and have a nice day.

    yoyo


    Yoyo Jiang[MSFT]
    MSDN Community Support | Feedback to us

  • Thursday, April 05, 2012 2:50 AM