在vb.net frame work 2.0中创建Excel文件 [英] Create excel file in vb.net frame work 2.0

查看:73
本文介绍了在vb.net frame work 2.0中创建Excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用vb.net Framework 2.0,并希望创建Excel文件.请给我发送代码以创建一个简单的Excel文件..

谢谢
Balmukund

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

推荐答案

在改进此代码之前,请添加参考文献
"Microsoft Excel 12.0对象库"

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

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


亲爱的朋友,

这些链接将对您有所帮助:-

http://blogs.msdn.com/b/erikaehrli/archive/2005/10/27/excelmanagedautofiltering.aspx [ ^ ]

http://vb.net-informations.com/excel-2007/vb.net_excel_2007_create_file.htm [^ ]

http://forums.asp.net/t/1038105.aspx/1 [ ^ ]

http://stackoverflow.com/questions/150339/generating-an-excel- file-in-asp-net [ ^ ]

以上更新的链接一定会对您有所帮助.

如果可以帮助您,请别忘了将此标记为您的答案.

谢谢
Dear friend,

These links will be helpful:-

http://blogs.msdn.com/b/erikaehrli/archive/2005/10/27/excelmanagedautofiltering.aspx[^]

http://vb.net-informations.com/excel-2007/vb.net_excel_2007_create_file.htm[^]

7,040,000 results on create excel file with vb net

More Links:-

http://forums.asp.net/t/1038105.aspx/1[^]

http://stackoverflow.com/questions/150339/generating-an-excel-file-in-asp-net[^]

The above updated links will definitely help you out.

Don''t forget to mark this as your answer if it helps you out.

Thanks


这篇关于在vb.net frame work 2.0中创建Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆