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. Visual Basic
  4. how to pass from datagrid to EXCEL

how to pass from datagrid to EXCEL

Scheduled Pinned Locked Moved Visual Basic
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.
  • C Offline
    C Offline
    campbells
    wrote on last edited by
    #1

    anyone know how to pass some information from datagrid to EXCEL?? which from the row 1 of the datagrid to the last row.

    R 1 Reply Last reply
    0
    • C campbells

      anyone know how to pass some information from datagrid to EXCEL?? which from the row 1 of the datagrid to the last row.

      R Offline
      R Offline
      RichardBerry
      wrote on last edited by
      #2

      I can be somthing like this:

      Private Sub cmdCreateXLTemplate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCreateXLTemplate.Click
      Dim ColHeadings() As String = {"warehouse", "product", "alpha"}

          Dim xlApp As New Excel.Application
          Dim xlBook As Excel.Workbook
          Dim Row As Integer = 1
          Dim Col As Integer
      
          xlBook = xlApp.Workbooks.Add
          xlBook.Sheets(2).Name = "ErrorData"
          'Column Headings
          For Col = 1 To ColHeadings.GetUpperBound(0)
              xlBook.Sheets(1).cells(2, Col) = ColHeadings(Col - 1)
          Next
      
          'Actual Data
          For j As Integer = 0 To Me.dgExcelData.RowCount - 1
              xlBook.Sheets(1).cells(j+1, 1) = Me.dgExcelData.Item(0, j).ToString
          Next
          'Saving The Excel File
          Dim Filename As String
          Filename = Application.StartupPath & "\\Import.xls"
          Dim i As Integer = 1
          Do While IO.File.Exists(Filename)
              Filename = "C:\\Import" & i & ".xls"
          Loop
          Dim Save As New SaveFileDialog
          Save.FileName = Filename
          Dim Result As DialogResult
          Result = Save.ShowDialog
          If Result = Windows.Forms.DialogResult.OK Then
              xlBook.SaveAs(Filename)
          End If
      
          xlBook.Close()
          xlBook = Nothing
          xlApp.Quit()
          xlApp = Nothing
          GC.Collect()
      End Sub
      
      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