Wilder1626
asked on
Export DataGridView1 to Excel 15.0
HI
I have the below code that would tranfer my DataGridView1 into Excel.
Since i have Microsoft Office 15.0, the below code does not work.
Looks like this does not exist anymore:
Dim xlApp As Microsoft.Office.Interop.E xcel.Appli cation
Dim xlWorkBook As Microsoft.Office.Interop.E xcel.Workb ook
Dim xlWorkSheet As Microsoft.Office.Interop.E xcel.Works heet
How can i fix this.
Thanks again.
I have the below code that would tranfer my DataGridView1 into Excel.
Since i have Microsoft Office 15.0, the below code does not work.
Looks like this does not exist anymore:
Dim xlApp As Microsoft.Office.Interop.E
Dim xlWorkBook As Microsoft.Office.Interop.E
Dim xlWorkSheet As Microsoft.Office.Interop.E
How can i fix this.
Thanks again.
Dim xlApp As Microsoft.Office.Interop.Excel.Application
Dim xlWorkBook As Microsoft.Office.Interop.Excel.Workbook
Dim xlWorkSheet As Microsoft.Office.Interop.Excel.Worksheet
Dim misValue As Object = System.Reflection.Missing.Value
Dim i As Integer
Dim j As Integer
xlApp = New Microsoft.Office.Interop.Excel.Application
xlWorkBook = xlApp.Workbooks.Add(misValue)
xlWorkSheet = xlWorkBook.Sheets("Sheet1")
For i = 0 To Me.DataGridView1.RowCount - 1
For j = 0 To Me.DataGridView1.ColumnCount - 1
For k As Integer = 1 To Me.DataGridView1.Columns.Count
If Me.DataGridView1(j, i).Value IsNot Nothing Then
xlWorkSheet.Cells(1, k) = Me.DataGridView1.Columns(k - 1).HeaderText
xlWorkSheet.Cells(i + 2, j + 1) = Me.DataGridView1(j, i).Value.ToString()
xlWorkSheet.Cells(1, k).NumberFormat = "@" '<<<<<
xlWorkSheet.Cells(1, k) = Me.DataGridView1.Columns(k - 1).HeaderText
xlWorkSheet.Cells(i + 2, j + 1).NumberFormat = "@" '<<<<<
xlWorkSheet.Cells(i + 2, j + 1) = Me.DataGridView1(j, i).Value.ToString()
End If
Next
Next
Next
xlWorkSheet.SaveAs("C:\Users\XXXX\Desktop\vbexcel.xlsx")
xlWorkBook.Close()
xlApp.Quit()
releaseObject(xlApp)
releaseObject(xlWorkBook)
releaseObject(xlWorkSheet)
Dim res As MsgBoxResult
res = MsgBox("Process completed, Would you like to open file?", MsgBoxStyle.YesNo)
If (res = MsgBoxResult.Yes) Then
Process.Start("C:\Users\XXXX\Desktop\vbexcel.xlsx")
End If
ASKER
Hi
So if i have Office 365 Business , i understand that it would not work. correct?
So if i have Office 365 Business , i understand that it would not work. correct?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your help, i installed Office 2014 instead of 365
installing the .NET Programmability Support with your Office setup and then referencing the new
PIA's which you need.
the other thing is have you installed the Visual Studio tools for Microsoft Office. You need VS 2012 upwards to support Office 2013,.