欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

關于vb.net導出xls的信息

vb.net 輸出 excel

這里有段VB6.0的,你可以參考。

為科爾沁左翼等地區(qū)用戶提供了全套網(wǎng)頁設計制作服務,及科爾沁左翼網(wǎng)站建設行業(yè)解決方案。主營業(yè)務為成都網(wǎng)站設計、網(wǎng)站制作、科爾沁左翼網(wǎng)站設計,以傳統(tǒng)方式定制建設網(wǎng)站,并提供域名空間備案等一條龍服務,秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務。我們深信只要達到每一位用戶的要求,就會得到認可,從而選擇與我們長期合作。這樣,我們也可以走得更遠!

注意添加引用。

Private Sub Command6_Click()

Dim i, j As Integer

Dim xlApplication As Excel.Application, xlWorkbook As Excel.Workbook, xlSheet

Dim xlApp As Excel.Application

On Error Resume Next

Set xlApplication = GetObject(, "Excel.Application")

Set xlApp = CreateObject("Excel.Application")

If MsgBox("確認將文件信息導出到EXCEL中??", vbExclamation + vbYesNo, "警告") = vbYes Then

If Err.Number 0 Then Set xlApplication = CreateObject("Excel.Application")

Set xlWorkbook = xlApplication.Workbooks.Add

Set xlSheet = xlWorkbook.ActiveSheet

xlSheet.Cells(1, 2) = lblcl.Caption

xlSheet.Range("A1:E1").MergeCells = True

xlSheet.Range("A1:E1").HorizontalAlignment = xlCenter

xlSheet.Cells(2, 2).ColumnWidth = 18

For i = 1 To DataGrid1.Columns.Count

xlSheet.Cells(2, 1) = "編號"

xlSheet.Cells(2, i + 1) = DataGrid1.Columns(i).Caption

For j = 0 To DataGrid1.VisibleRows - 1

xlSheet.Cells(j + 3, 1) = j + 1

xlSheet.Cells(j + 3, i + 1) = DataGrid1.Columns(i).CellText(DataGrid1.RowBookmark(j))

Next j

Next i

xlApplication.Visible = True

Set xlSheet = Nothing

Set xlWorkbook = Nothing

Set xlApplication = Nothing

'xlApp.Range("A2:L2").Columns.Interior.ColorIndex = 40

'xlApp.Range("A2:L2").Borders.LineStyle = xlContinuous

'xlApp.Visible = True

'xlApp.Range(xlSheet.Cells(2 + PartsRs.RecordCount + 1, 1), xlSheet.Cells(2 + PartsRs.RecordCount + 1, 8)).Columns.Interior.ColorIndex = 40

'xlApp.Range(xlSheet.Cells(2 + PartsRs.RecordCount + 1, 1), xlSheet.Cells(2 + PartsRs.RecordCount + 1, 8)).Borders.LineStyle = xlContinuous

Else

MsgBox "無信息可供您導出,請確認!", vbExclamation + vbOKOnly, "警告"

End If

End Sub

VB.NET怎么將DataGridview里的內(nèi)容導出到EXCEL去

不好意思 現(xiàn)在才看到;Private Sub 導出EXCEL_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

Dim xlApp, xlBook, xlSheet As Object

xlapp = CreateObject("Excel.Application")

xlbook = xlapp.Workbooks.Add

xlsheet = xlbook.Worksheets(1)

'Dim xlapp As New Excel.Application

'Dim xlbook As Excel.Workbook

'Dim xlsheet As Excel.Worksheet

Dim rowindex, colindex As Integer rowindex = 1 '行

colindex = 0 '列

'xlbook = xlapp.Workbooks.Open("c:\EXCEL.xls") '打開EXCEL文件

xlsheet = xlapp.Worksheets("sheet1") '打開sheet1那頁 Dim a As New DataSet

Dim table As New System.Data.DataTable table = DataSet11.Tables("INVMATLISTA") '填充表 Dim row As DataRow '定義row為表格的行

Dim col As DataColumn '定義col為表格的列 '把表格的每一列寫到EXCEL去

For Each col In table.Columns

colindex = colindex + 1

xlapp.Cells(1, colindex) = col.ColumnName Next

'把表格的每一行寫到EXCEL去

For Each row In table.Rows

rowindex = rowindex + 1

colindex = 0

For Each col In table.Columns

colindex = colindex + 1

xlapp.Cells(rowindex, colindex) = row(col.ColumnName)

Next

Next

xlapp.Visible = True

End Sub 前提要先引用一個Microsoft.Office.Interop.Excel.dll然后在最上面先輸入Imports Microsoft.Office.Interop; 就可以了

vb中如何將數(shù)據(jù)導出到excel

介紹

下面通過一步一步的介紹,如何通過VB.NET來讀取數(shù)據(jù),并且將數(shù)據(jù)導入到Excel中。

第一步:

打開VS開發(fā)工具,并且添加引用。

然后選擇。

Microsoft Excel 12.0 object library and。

Microsoft Excel 14.0 object library。

第二步:

創(chuàng)建一個Excle在你的電腦中。

第三步:

在VS中寫入如下代碼:

Imports System.Data

Imports System.Data.SqlClient

Imports Excel = Microsoft.Office.Interop.Excel。

Public Class excel

‘添加按鈕

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _

? Handles Button1.Click

Try

?? ?'創(chuàng)建連接

?? ?Dim cnn As DataAccess = New DataAccess(CONNECTION_STRING)

?? ?

?? ?Dim i, j As Integer

?? ?'創(chuàng)建Excel對象

?? ?Dim xlApp As Microsoft.Office.Interop.Excel.Application

?? ?Dim xlWorkBook As Microsoft.Office.Interop.Excel.Workbook

?? ?Dim xlWorkSheet As Microsoft.Office.Interop.Excel.Worksheet

?? ?Dim misValue As Object = System.Reflection.Missing.Value

?? ?xlApp = New Microsoft.Office.Interop.Excel.ApplicationClass

?? ?xlWorkBook = xlApp.Workbooks.Add(misValue)

?? ?' 打開某一個表單

?? ?xlWorkSheet = xlWorkBook.Sheets("sheet1")

?? ?' sql查詢

?? ?'??xlWorkBook.Sheets.Select("A1:A2")

?? ?Dim sql As String = "SELECT * FROM EMP"

?? ?' SqlAdapter

?? ?Dim dscmd As New SqlDataAdapter(sql, cnn.ConnectionString)

?? ?' 定義數(shù)據(jù)集

?? ?Dim ds As New DataSet

?? ?dscmd.Fill(ds)

?? ? ‘添加字段信息到Excel表的第一行

?? ?xlWorkSheet.Cells(1, 1).Value = "First Name"

?? ?xlWorkSheet.Cells(1, 2).Value = "Last Name"

?? ?xlWorkSheet.Cells(1, 3).Value = "Full Name"

?? ?xlWorkSheet.Cells(1, 4).Value = "Salary"

?? ?' 將數(shù)據(jù)導入到excel

?? ???For i = 0 To ds.Tables(0).Rows.Count - 1

?? ?? ? 'Column

?? ?? ? For j = 0 To ds.Tables(0).Columns.Count - 1

?? ?? ?? ???' this i change to header line cells

?? ?? ?? ???xlWorkSheet.Cells(i + 3, j + 1) = _

?? ?? ?? ???ds.Tables(0).Rows(i).Item(j)

?? ?? ? Next

?? ?Next

?? ?'HardCode in Excel sheet

?? ?' this i change to footer line cells??

???xlWorkSheet.Cells(i + 3, 7) = "Total"

?? ?xlWorkSheet.Cells.Item(i + 3, 8) = "=SUM(H2:H18)"

?? ?' 保存到Excel

?? ?xlWorkSheet.SaveAs("D:\vbexcel.xlsx")

?? ?xlWorkBook.Close()

?? ?xlApp.Quit()

?? ?releaseObject(xlApp)

?? ?releaseObject(xlWorkBook)

?? ?releaseObject(xlWorkSheet)

?? ?'彈出對話框顯示保存后的路徑

?? ?MsgBox("You can find the file D:\vbexcel.xlsx")

Catch ex As Exception

End Try

End Sub

' Function of Realease Object in Excel Sheet

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

復制代碼。

第四步:

看到如下導出結果。

新聞名稱:關于vb.net導出xls的信息
本文鏈接:http://chinadenli.net/article22/doddejc.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化、響應式網(wǎng)站、ChatGPT、品牌網(wǎng)站設計、營銷型網(wǎng)站建設、網(wǎng)站排名

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

綿陽服務器托管