473,385 Members | 1,602 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Export Vb.net Datagridview to Microsoft Excel 2013

54
Please I'm using vb.net 2013 and Microsoft office 2013. The below code is able to display the datagridview

into excel 2007. But the code does not display onto excel 2013 and no error gets reported. I suspect the

excel 2013 format could be the cause but i do not know how to go about it. Please help me out. Thanks, Ben

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim ExcelApp As Object, ExcelBook As Object
  3.         Dim ExcelSheet As Object
  4.         Dim i As Integer
  5.         Dim j As Integer
  6.  
  7.         'create object of excel
  8.         ExcelApp = CreateObject("Excel.Application")
  9.         ExcelBook = ExcelApp.WorkBooks.Add
  10.         ExcelSheet = ExcelBook.WorkSheets(1)
  11.  
  12.         With ExcelSheet
  13.             For i = 1 To Me.DataGridViewGCL.RowCount
  14.                 .cells(i, 1) = Me.DataGridViewGCL.Rows(i - 1).Cells("GclNo").Value
  15.                 For j = 1 To DataGridViewGCL.Columns.Count - 1
  16.                     .cells(i, j + 1) = DataGridViewGCL.Rows(i - 1).Cells(j).Value
  17.                 Next
  18.             Next
  19.         End With
  20.  
  21.         ExcelApp.Visible = True
  22.         '
  23.         ExcelSheet = Nothing
  24.         ExcelBook = Nothing
  25.         ExcelApp = Nothing
  26.  
  27.  
Aug 24 '15 #1
1 2761
Have you stepped through the code at all? Does it fail at a certain place?
Sep 30 '15 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Igor | last post by:
Hi everyone! I have a question about exporting data to Microsoft Excel. I am writing program in C# and have to export some data to excel workbook. It works very good using OLE technology, but...
0
by: artteam | last post by:
Hi All, I try to export the table in DataGridView control on my form to MS excel with the following code. private void fnExtractToExcel() { ...
2
by: Mike Wilson | last post by:
Dear all, I'm sure someone has already done this, so as not to wish to re-invent the wheel - and Google not turning up anything I can use, does anyone have a suitable function into which I can...
5
by: Mike Wilson | last post by:
Hello all, I'd like to export a DataGridView to Excel. I am using .NET 2.0 and VB.NET. But I don't know if the user has Excel on their machines, so can't use COM Excel object. Any ideas...
7
by: RafaulWolf | last post by:
Hi, anyone know how can i export the information in the datagridview to an Excel file? i understand that the crystal report tool has such a build in function for importing to pdf or execl, then...
1
by: TG | last post by:
Hi! I have an application in which I have some checkboxes and depending which ones are checked those columns will show in the datagridview from sql server or no. After that I have 2 buttons:...
5
by: leelaprasad9999 | last post by:
hi i'm trying to export datagridview data with image to excel , i'm using the below code, but image cannot be displayed. Microsoft.Office.Interop.Excel.Application ExcelApp = new...
0
by: dinitiae | last post by:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click DATAGRIDVIEW_TO_EXCEL((DataGridView1)) ' PARAMETER: YOUR DATAGRIDVIEW End Sub...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.