Click here to Skip to main content
15,885,919 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
i am using vb.net framework 2.0 and want to create excel file. please send me code to create a simple excel file..

thanks
Balmukund
Posted
Comments
Varun Sareen 1-Mar-12 3:27am    
always try google search dear.
Balmukund Dewangan 1-Mar-12 5:25am    
Hi.. thanks to reply. but my problem is still not solved. you have sent me 3 links
1. is about creating excel file in C#
2. is for desktop based application in vb.net
3. is link to search in google

I have tried in google so many times but coundnt get correct one..

What i need is "creating excel file in vb.net framework 2.0 in web based tech"

Thanks
Balmukund
Varun Sareen 1-Mar-12 23:44pm    
i have updated my solution.

Before Improve this code add reference
"Microsoft Excel 12.0 Object Library"

VB
Imports Excel = Microsoft.Office.Interop.Excel
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object,_
	 ByVal e As System.EventArgs) Handles Button1.Click

        Dim xlApp As Excel.Application
        Dim xlWorkBook As Excel.Workbook
        Dim xlWorkSheet As Excel.Worksheet
        Dim misValue As Object = System.Reflection.Missing.Value

        xlApp = New Excel.ApplicationClass
        xlWorkBook = xlApp.Workbooks.Add(misValue)
        xlWorkSheet = xlWorkBook.Sheets("sheet1")
        xlWorkSheet.Cells(1, 1) = "http://neerajsinghandroid.blogspot.in"
        xlWorkSheet.SaveAs("C:\vbexcel.xlsx")

        xlWorkBook.Close()
        xlApp.Quit()

        releaseObject(xlApp)
        releaseObject(xlWorkBook)
        releaseObject(xlWorkSheet)

        MsgBox("Excel file created , you can find the file c:\")
    End Sub

    Private Sub releaseObject(ByVal obj As Object)
        Try
            System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
            obj = Nothing
        Catch ex As Exception
            obj = Nothing
        Finally
            GC.Collect()
        End Try
    End Sub

End Class
 
Share this answer
 
v5
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900