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. Open Excel Project

Open Excel Project

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

    Dear friends, I have to write a project that's able to read & write data to an excel file. Just simply like a data base program. do you have any hints or example?

    S 1 Reply Last reply
    0
    • A azusakt

      Dear friends, I have to write a project that's able to read & write data to an excel file. Just simply like a data base program. do you have any hints or example?

      S Offline
      S Offline
      sean_mufc
      wrote on last edited by
      #2

      I had a big headache trying to do this myself. There may be a way to read and write to a file, but I found I a diffent way to write to Excel, and a different was of reading from, with some help from one of our friends on the CodeProject. Here is a simple example of writing to Excel. It creates a new Excel book and writes a string in the 1st cell. /**************************************************/ using System; using Excel; using System.IO; using System.Text; using System.Data.OleDb; namespace Writing_to_Excel_example { class Class1 { static void Main(string[] args) { bool xlsError = false; int rowCount = 0; int counter = 0; int counter2 = 0; Console.WriteLine("Working..."); Excel.Application ExcelObj = new Excel.Application(); Excel.Workbook workbook = ExcelObj.Workbooks.Add(Type.Missing); if (ExcelObj == null) { Console.WriteLine("\nERROR: EXCEL couldn't be started!"); xlsError = true; } // activate the active worksheet in the workbook Worksheet ws = (Worksheet)ExcelObj.ActiveSheet; ws.Activate(); try { //To enter text to a specific row and column: ((Range)ws.Cells[1, 1]).Value2 = ("This is Row 1, Column 1"); //To set an entire row as Bold. ((Range)ws.Cells[rowCount, 1]).EntireRow.Font.Bold = true; }//end try catch(Exception e) { Console.Write(e); } //Make Excel visible. ExcelObj.Visible = true; } } } /***************************************************************/ DONT FORGET TO ADD REFERENCE TO EXCEL 11.0 OBJECT LIBRARY!! As for reading from excel, I tried to apply the same sort of logic as above but it didn't work. So have a look at this link: http://www.codeproject.com/csharp/FasterExcelAccessTOC.asp[^] Great tips there, a great help to me, Thanks to Dusty Candland, great help mate!! t-seanm

      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