2012年12月9日 星期日

VB.NET: Write/Create an Excel File

引用來源
--
Dim OutputArray(200, 200) As String
Dim strFileName As String = "MyExl.xls"

'set ur OutputArray here

Dim excel As New Microsoft.Office.Interop.Excel.ApplicationClass
Dim wBook As Microsoft.Office.Interop.Excel.Workbook
Dim wSheet As Microsoft.Office.Interop.Excel.Worksheet

wBook = excel.Workbooks.Add()
Try
    wSheet = wBook.ActiveSheet()
    Dim Range As Microsoft.Office.Interop.Excel.Range = wSheet.Range("A1", wSheet.Cells(200, 200))
    Range.Value2 = OutputArray
    wBook.SaveAs(strFileName)
Catch ex As Exception
    msgbox("Some Error Occured !!!")
Finally
    wBook.Close()
    excel.Quit()
    excel = Nothing
End Try

沒有留言:

張貼留言