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. Exporting DataGrid contents to Excel

Exporting DataGrid contents to Excel

Scheduled Pinned Locked Moved C#
csharphelp
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.
  • I Offline
    I Offline
    Imthu
    wrote on last edited by
    #1

    Hai all, In my project i want to generate an excel report from datgrid... i just want to export my contents of datagrid to excel... can anyone help me with c# sample codings.......

    with Regards, Imthiyas Ahamed.A

    D 1 Reply Last reply
    0
    • I Imthu

      Hai all, In my project i want to generate an excel report from datgrid... i just want to export my contents of datagrid to excel... can anyone help me with c# sample codings.......

      with Regards, Imthiyas Ahamed.A

      D Offline
      D Offline
      debnathrubs
      wrote on last edited by
      #2

      at first you have to select the reference named:microsoft excel 10.0 object lib and microsofr office 10.0 object lib then u may use this or some thing like this ==> string Path = @fileName; // initialize the Excel Application class Excel.ApplicationClass app = new ApplicationClass(); // create the workbook object by opening the excel file. Excel.Workbook workBook = app.Workbooks.Open(Path,0,true,5,pass1,pass2, true, Excel.XlPlatform.xlWindows,"\t",false,false,0,true,1,0); // get the active worksheet using sheet name or active sheet Excel.Worksheet workSheet = (Excel.Worksheet)workBook.ActiveSheet; // This row,column index should be changed as per your need. // i.e. which cell in the excel you are interesting to read. int row=2; while ( ((Excel.Range)workSheet.Cells[row,1]).Value2 != null ) { for(int a=1;a<=col;a++) { if(((Excel.Range)workSheet.Cells[row,a]).Value2 != null ) totSiz[row-2,a]= ((Excel.Range)workSheet.Cells[row,a]).Value2.ToString(); } row++; }

      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