Reputation: 31
I have .net framework 2.0 . and I want to create an Excel sheet from vb.net programming. I have searched in google but didn't get the correct one. It was all for .net framework 3.5 or higher. Please show me code to generate a simple Excel file using vb.net programming.
Upvotes: 1
Views: 1811
Reputation: 3322
How's this look? This code has been around in one of my applications since pre-.NET 2.0 and should work for you.
'Grab data from the data grid view and put it on the clipboard
Clipboard.SetDataObject(Me.dgvData.GetClipboardContent())
'Create excel and workbook objects
Dim oExcel As Object
Dim oBook As Object
oExcel = CreateObject("Excel.Application")
oExcel.Visible = True
oBook = oExcel.Workbooks.Add
'Now paste in the data that was copied to the clipboard above
oBook.Worksheets(1).Range("A1").Select()
oBook.Worksheets(1).Paste()
You will likely need to include Interop.Excel.dll
in your project references.
Edit: Also, if you have time to read something, this is a pretty awesome write up on the more current version that may help you as well http://www.siddharthrout.com/vb-dot-net-and-excel/
Upvotes: 2