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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Export DataGridView to Excel And Word WithOut Ms Excel And Word

Export DataGridView to Excel And Word WithOut Ms Excel And Word

Scheduled Pinned Locked Moved Visual Basic
helpquestion
4 Posts 4 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.
  • M Offline
    M Offline
    mehrnoosh
    wrote on last edited by
    #1

    hi every body how can we export a datagridview data to excel and word when Ms excel and ms word is not instal in system... can you help me please?! :doh: :confused::confused:

    M.Alizadeh

    W A R 3 Replies Last reply
    0
    • M mehrnoosh

      hi every body how can we export a datagridview data to excel and word when Ms excel and ms word is not instal in system... can you help me please?! :doh: :confused::confused:

      M.Alizadeh

      W Offline
      W Offline
      Wendelius
      wrote on last edited by
      #2

      Whole lot of good articles found with simple search: http://www.codeproject.com/info/search.aspx?artkw=export++data+to+excel&sbo=kw[^]

      The need to optimize rises from a bad design.My articles[^]

      1 Reply Last reply
      0
      • M mehrnoosh

        hi every body how can we export a datagridview data to excel and word when Ms excel and ms word is not instal in system... can you help me please?! :doh: :confused::confused:

        M.Alizadeh

        A Offline
        A Offline
        Ashutosh Phoujdar
        wrote on last edited by
        #3

        Hi, You can use following library for exporting to Excel : CarlosAg Excel Xml Writer Library[^] And for exporting to word : Gios WORD .NET Library (using RTF specification)[^] For exporting to word/excel, you must have to iterate through Row of datagridview rows, using following code snippet

        For Each currentRow As DataRow In DataGridView1.Rows
        'Use the values in current cell using following syntax.
        currentRow.Cells(0).Value
        currentRow.Cells(1).Value
        currentRow.Cells(3).Value
        'until all cells are covered.
        Next

        Alternatively if you are looking for only copying the data to excel/word, just select the data copy using (ctrl+c) and paste to word/excel (This will work with .NET framework version 2.0 and greater). Hope I answered your query. :) Thanks, Ashu

        dnpro "Very bad programmer"

        1 Reply Last reply
        0
        • M mehrnoosh

          hi every body how can we export a datagridview data to excel and word when Ms excel and ms word is not instal in system... can you help me please?! :doh: :confused::confused:

          M.Alizadeh

          R Offline
          R Offline
          rohan_puranik
          wrote on last edited by
          #4

          You can do one thing. Write the data of your DGV to a CSV (comma separated value) file. Whenever a user opens a CSV (on a machine having MS-Office) it will get open in MS-Excel by default. Here's a raw code snippet for each row in DGV get value of cell and store it in string append , (i.e. comma) end for trim last character of string //(because it would contain last appended comma) write this string to file "file.csv" save the file Whenever user open this CSV it will get open in MS-Excel. If a user does not have MS-Excel he/she may do one thing. Right click the file and open it in notepad. Hope this help you out.

          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