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. Editing Excel Worksheet Cells

Editing Excel Worksheet Cells

Scheduled Pinned Locked Moved C#
help
3 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.
  • S Offline
    S Offline
    StyrofoamSUV
    wrote on last edited by
    #1

    Hey all. I have been fooling around with Excel and can create Worksheets, files, etc, however, when I try to modify the contents of a cell, I get the following exception: An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll Additional information: Exception from HRESULT: 0x800A03EC. The code is: Excel.Application excel = new Excel.ApplicationClass(); Excel.Workbook workbook = null; Excel.Sheets sheets = null; Excel.Worksheet currentSheet = null; workbook = excel.Workbooks.Add( Excel.XlWBATemplate.xlWBATWorksheet ); sheets = workbook.Worksheets; currentSheet = (Excel.Worksheet)sheets[ 1 ]; ((Excel.Range)currentSheet.Cells[ 0, 0 ]).Value2 = "text"; I have researched this on the net but to no avail. My code seemed to have worked before, but it doesn't now and it's ticking me off. I have tried several variations to modify the contents of the cell, but nada. Any help would be greatly appreciated! Thanks, Josh

    C 1 Reply Last reply
    0
    • S StyrofoamSUV

      Hey all. I have been fooling around with Excel and can create Worksheets, files, etc, however, when I try to modify the contents of a cell, I get the following exception: An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll Additional information: Exception from HRESULT: 0x800A03EC. The code is: Excel.Application excel = new Excel.ApplicationClass(); Excel.Workbook workbook = null; Excel.Sheets sheets = null; Excel.Worksheet currentSheet = null; workbook = excel.Workbooks.Add( Excel.XlWBATemplate.xlWBATWorksheet ); sheets = workbook.Worksheets; currentSheet = (Excel.Worksheet)sheets[ 1 ]; ((Excel.Range)currentSheet.Cells[ 0, 0 ]).Value2 = "text"; I have researched this on the net but to no avail. My code seemed to have worked before, but it doesn't now and it's ticking me off. I have tried several variations to modify the contents of the cell, but nada. Any help would be greatly appreciated! Thanks, Josh

      C Offline
      C Offline
      Coding C
      wrote on last edited by
      #2

      Hi, ((Excel.Range)currentSheet.Cells[ 0, 0 ]).Value2 = "text"; cell[0,0] is an readonly cell:), you cant modify value in it. use ((Excel.Range)currentSheet.Cells[ 1, 1 ]).Value2 = "text"; hope this works. Nitin...

      S 1 Reply Last reply
      0
      • C Coding C

        Hi, ((Excel.Range)currentSheet.Cells[ 0, 0 ]).Value2 = "text"; cell[0,0] is an readonly cell:), you cant modify value in it. use ((Excel.Range)currentSheet.Cells[ 1, 1 ]).Value2 = "text"; hope this works. Nitin...

        S Offline
        S Offline
        StyrofoamSUV
        wrote on last edited by
        #3

        Thanks for the response. Interesting that you can't modify 0,0. Perhaps they should mention that somewhere. Anyway, I tried using different Cell coords, however, no data appeared, but I am not that concerned since I didn't receive an error. I ended up using this to modify cell contents: Excel.Range r = currentSheet.get_Range( "C1", Type.Missing ); r.Value2 = "Some Text"; r = currentSheet.get_Range( "D1", Type.Missing ); r.Value2 = "Some Text"; This seems to work fine. Thanks!

        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