Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. reading excel contents

reading excel contents

Scheduled Pinned Locked Moved C#
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mist_psycho
    wrote on last edited by
    #1

    I tried using this code for reading excel data using c# : bt the following part of the code is giving errors and is not being executed.... plz help !!!! using System; using System.Collections.Generic; using System.Text; using Excel; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string Path = @"c:\gg.xls"; Excel.ApplicationClass app = new ApplicationClass(); Excel.Workbook workBook = app.Workbooks.Open(Path,0,true,5,"","",true,Excel.XlPlatform.xlWindows,"\t",false,false,0,true,1,0); Excel.Worksheet workSheet = (Excel.Worksheet)workBook.ActiveSheet; int index = 0; object rowIndex = 2; object colIndex1 = 1; object colIndex2 = 2; try { while (((Excel.Range)workSheet.Cells[rowIndex, colIndex1]).Value2 != null) { rowIndex = 2 + index; string firstName = ((Excel.Range)workSheet.Cells[rowIndex, colIndex1]).Value2.ToString(); string lastName = ((Excel.Range)workSheet.Cells[rowIndex, colIndex2]).Value2.ToString(); Console.WriteLine("Name : {0},{1} ", firstName, lastName); index++; } } catch (Exception ex) { app.Quit(); Console.WriteLine(ex.Message); } } } } the error is at "Excel.Workbook workBook = app.Workbooks.Open" : Error 1 No overload for method 'Open' takes '15' arguments C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\ConsoleApplication1_trytry\ConsoleApplication1_trytry\Program.cs 16 39 ConsoleApplication1_trytry

    R 1 Reply Last reply
    0
    • M mist_psycho

      I tried using this code for reading excel data using c# : bt the following part of the code is giving errors and is not being executed.... plz help !!!! using System; using System.Collections.Generic; using System.Text; using Excel; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string Path = @"c:\gg.xls"; Excel.ApplicationClass app = new ApplicationClass(); Excel.Workbook workBook = app.Workbooks.Open(Path,0,true,5,"","",true,Excel.XlPlatform.xlWindows,"\t",false,false,0,true,1,0); Excel.Worksheet workSheet = (Excel.Worksheet)workBook.ActiveSheet; int index = 0; object rowIndex = 2; object colIndex1 = 1; object colIndex2 = 2; try { while (((Excel.Range)workSheet.Cells[rowIndex, colIndex1]).Value2 != null) { rowIndex = 2 + index; string firstName = ((Excel.Range)workSheet.Cells[rowIndex, colIndex1]).Value2.ToString(); string lastName = ((Excel.Range)workSheet.Cells[rowIndex, colIndex2]).Value2.ToString(); Console.WriteLine("Name : {0},{1} ", firstName, lastName); index++; } } catch (Exception ex) { app.Quit(); Console.WriteLine(ex.Message); } } } } the error is at "Excel.Workbook workBook = app.Workbooks.Open" : Error 1 No overload for method 'Open' takes '15' arguments C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\ConsoleApplication1_trytry\ConsoleApplication1_trytry\Program.cs 16 39 ConsoleApplication1_trytry

      R Offline
      R Offline
      Rob Philpott
      wrote on last edited by
      #2

      Well, that's saying you've got the wrong number of arguments in the open method. Check the documentation on 'Open'.

      Regards, Rob Philpott.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups