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. Excel Automation in C#

Excel Automation in C#

Scheduled Pinned Locked Moved C#
csharptestingtoolshelp
1 Posts 1 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.
  • A Offline
    A Offline
    AZBugsBunny
    wrote on last edited by
    #1

    I want to open an Excel file in my C# application and read the contents . I tried the msdn samples. But most of them deal with writing back values into Excel file. Also since the range of values that I have to read from the Excel file is dynamic, I would like to know how this can be done. The foll. is the code that I have written and I get error while instatiating an Excel aplication obejct as it is not able to understand my typecasting. Excel.Application objApp=null ; Excel.Workbooks objBooks=null; Excel.Workbook objBook= null; Excel.Range range; string str=""; try { // Instantiate Excel and start a new workbook. objApp = (Excel.Application)new Excel._ExcelApplicationClass(); objBooks = (Workbooks)objApp.Workbooks(1); objBook = (Workbook)objBooks.Open(DataFile,null,null,null,null,null,null,null,null,null,null,null); Excel.Worksheet ws= (Worksheet)objBook.Worksheets(1); if (ws == null) Console.WriteLine ("ERROR: worksheet == null"); Excel.Range rng=(Excel.Range)ws.Cells(1,1); str=rng.Value.ToString();

    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