Manipulating Excel

Discussion in 'ASP .Net' started by Paulo, Sep 28, 2007.

  1. Paulo

    Paulo Guest

    using Excel;

    Excel.Application ExcelApp = new Excel.ApplicationClass();
    string workbookPath = Server.MapPath("excel\\produto1.xls");
    Excel.Workbook excelWorkbook = ExcelApp.Workbooks.Open(workbookPath,
    0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "",
    true, false, 0, true, false, false);
    string currentSheet = "Plan1";
    Excel.Sheets excelSheets = excelWorkbook.Worksheets;
    Excel.Worksheet excelWorksheet =
    (Excel.Worksheet)excelSheets.get_Item(currentSheet);


    Im using the code above, but how can I loop through all the columns and rows
    of the sheet? Can you help me?

    Using VS 2005 asp.net 2.0 C#

    Thanks!
     
    Paulo, Sep 28, 2007
    #1
    1. Advertisements

  2. "Paulo" <> wrote in message
    news:...

    > Excel.Application ExcelApp = new Excel.ApplicationClass();


    > Im using the code above, but how can I loop through all the columns and
    > rows of the sheet?


    You can't.

    Excel, like the rest of Office, is not designed to run via server-side
    Office automation - Microsoft won't support any solution which even attempts
    this, because it doesn't work:
    http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2

    To meet your requirements, you need this:
    http://www.aspose.com/Products/Aspose.Cells/Default.aspx


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Sep 28, 2007
    #2
    1. Advertisements

  3. Paulo

    sloan Guest

    You can use a System.Data.OleDb.OleDbConnection and get an IDataReader
    against the Excel spreadsheet.
    http://support.microsoft.com/kb/316934


    It would be best to avoid the excel object model, and as pointed out
    already, is a really bad idea server side.






    "Paulo" <> wrote in message
    news:...
    > using Excel;
    >
    > Excel.Application ExcelApp = new Excel.ApplicationClass();
    > string workbookPath = Server.MapPath("excel\\produto1.xls");
    > Excel.Workbook excelWorkbook = ExcelApp.Workbooks.Open(workbookPath,
    > 0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "",
    > true, false, 0, true, false, false);
    > string currentSheet = "Plan1";
    > Excel.Sheets excelSheets = excelWorkbook.Worksheets;
    > Excel.Worksheet excelWorksheet =
    > (Excel.Worksheet)excelSheets.get_Item(currentSheet);
    >
    >
    > Im using the code above, but how can I loop through all the columns and
    > rows of the sheet? Can you help me?
    >
    > Using VS 2005 asp.net 2.0 C#
    >
    > Thanks!
    >
     
    sloan, Sep 28, 2007
    #3
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SmltIEhlYXZleQ==?=

    Excel _WorkBook vs. Excel.Workbook

    =?Utf-8?B?SmltIEhlYXZleQ==?=, Sep 29, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    3,960
    Steve C. Orr [MVP, MCSD]
    Sep 29, 2004
  2. Luis Esteban Valencia
    Replies:
    1
    Views:
    1,605
    Carl Prothman [MVP]
    Jan 12, 2005
  3. =?Utf-8?B?Smlt?=

    Manipulating Excel data with ASP.NET

    =?Utf-8?B?Smlt?=, Nov 2, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    7,027
    =?Utf-8?B?Smlt?=
    Nov 3, 2005
  4. =?Utf-8?B?U3JpZGhhcg==?=

    using Microsoft Excel image for Export to Excel button

    =?Utf-8?B?U3JpZGhhcg==?=, Dec 9, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    3,418
    =?Utf-8?B?U3JpZGhhcg==?=
    Dec 9, 2005
  5. Anonieko
    Replies:
    2
    Views:
    7,633
    JackStraw73
    Feb 12, 2008
  6. =?Utf-8?B?SGVtYW50IFNpcGFoaW1hbGFuaQ==?=

    Export to Excel (Default File Type - Excel)

    =?Utf-8?B?SGVtYW50IFNpcGFoaW1hbGFuaQ==?=, Apr 24, 2006, in forum: ASP .Net
    Replies:
    15
    Views:
    18,350
    syed hassan
    May 21, 2009
  7. spirit
    Replies:
    4
    Views:
    714
    spirit
    Aug 3, 2007
  8. =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=

    Problem with Excel reports ::::Excel 2003 Migration To Excel 2007

    =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=, Oct 5, 2007, in forum: ASP .Net
    Replies:
    15
    Views:
    2,006
    =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=
    Oct 24, 2007
Loading...