VB.Net匯出Excel

 

Try
            Dim xlApp As New Excel.Application
            Dim xlBook As Excel.Workbook
            xlBook = xlApp.Workbooks.Add(True)
            Dim rowIndex As Integer = 1
            Dim colIndex As Integer = 0
            For colIndex = 0 To DataGridView1.Columns.Count - 1
                xlApp.Cells(1, colIndex + 1) = DataGridView1.Columns(colIndex).HeaderCell.Value
            Next
For rowIndex = 1 To DataGridView1.Rows.Count - 1
                For colIndex = 0 To DataGridView1.Columns.Count - 1
                    xlApp.Cells(rowIndex + 1, colIndex + 1) = DataGridView1.Rows(rowIndex - 1).Cells(colIndex).Value.ToString
                Next
            Next
            xlApp.Visible = True
            xlBook = Nothing
            xlApp = Nothing
        Catch ex As Exceptio

DotBlogs Tags: VB.NET
posted on 2008/3/20 14:55 | 我要推薦 | 閱讀數 : 1853 | 分類[ ASP.NET ] 訂閱

Feedback

# re: VB.Net匯出Excel 回覆

Left by 張成 at 2008/6/9 下午 02:14
讚!!我成功了

回應:




 
Please add 6 and 1 and type the answer here:

Copyright © YAUS

Design by Bartosz Brzezinski

Design by Phil Haack Based On A Design By Bartosz Brzezinski