注册 登录
编程论坛 VB.NET论坛

急求各位大虾:谁能教我vb.net怎么生成excell表格

shizhibo 发布于 2008-03-09 15:49, 1419 次点击
我想学习生成excell表格,可是这方面的资料很少,那位大虾能帮帮小弟呀,不生感激。尽量说说详细步骤
2 回复
#2
fairy42008-03-10 12:01
隨便baidu下,包你看不完,
資料還很少!汗!
你搜索下  操作excel   看下
但要想在excel裡面做很多細節性的東西就要用到vba<操作宏>,自己慢慢找吧
#3
qlong07282008-03-12 11:40
Dim i, j, o As Integer
            o = DataGridView1.Columns.Count - 1
            If o < 0 Then
                MessageBox.Show("没数据可导到Excel哦!", Message_Title, MessageBoxButtons.OK, MessageBoxIcon.Warning)
                Exit Sub
            End If
            Dim xlApp As Excel.Application
            Dim xlBook As Excel.Workbook
            Dim xlSheet As Excel.Worksheet
            xlApp = CreateObject("Excel.Application")
            xlBook = xlApp.Workbooks.Add
            xlSheet = xlBook.Worksheets(1)
            xlApp.Visible = True
            xlApp.Columns("c:c").NumberFormatLocal = "@"
            xlApp.Columns("e:e").NumberFormatLocal = "@"
            xlApp.Columns("j:j").NumberFormatLocal = "@"
            For i = 0 To o
                xlSheet.Cells(1, i + 1).Value = DataGridView1.Columns(i).HeaderText
                xlApp.Cells(1, i + 1).HorizontalAlignment = 3
            Next
            With DataGridView1
                For i = 0 To .Rows.Count - 1
                    For j = 0 To .ColumnCount - 1
                        xlSheet.Cells(i + 2, j + 1).Value = .Rows(i).Cells(j).Value
                    Next j
                    xlSheet.Range("a" & i + 2).Select()
                Next i
            End With

            xlApp.Columns("a:at").EntireColumn.AutoFit()
            xlSheet.Range("a1").Select()

            xlSheet = Nothing
            xlBook = Nothing
            xlApp = Nothing
1