自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

VB.NET導(dǎo)出數(shù)據(jù)實(shí)現(xiàn)你想要的效果

開發(fā) 后端
VB.NET導(dǎo)出數(shù)據(jù)的實(shí)現(xiàn)可以通過本文介紹的這段代碼來進(jìn)行操作。初學(xué)者可以以此為參考對(duì)象,對(duì)這方面的知識(shí)點(diǎn)進(jìn)行一個(gè)充分的了解。

 VB.NET開發(fā)語言為我們平時(shí)的開發(fā)方式帶來了非常的改變。很多時(shí)候可以利用Excel的數(shù)據(jù)透視表導(dǎo)出你想要的報(bào)表格式。那么VB.NET導(dǎo)出數(shù)據(jù)該如何實(shí)現(xiàn)呢?下面的代碼可以從數(shù)據(jù)庫中取出數(shù)據(jù)然后導(dǎo)入Excel。

  1. Dim excel As Excel.Application  
  2. Dim xBk As Excel._Workbook  
  3. Dim xSt As Excel._Worksheet  
  4. Dim xRange As Excel.Range  
  5. Dim xPivotCache As Excel.
    PivotCache  
  6. Dim xPivotTable As Excel.
    PivotTable  
  7. Dim xPivotField As Excel.
    PivotField  
  8. Dim cnnsr As String, sql 
    As String  
  9. Dim RowFields() As String = 
    {"", "", ""}  
  10. Dim PageFields() As String = 
    {"", "", "", "", "", ""}  
  11. 'SERVER 是服務(wù)器名或服務(wù)器的IP地址  
  12. 'DATABASE 是數(shù)據(jù)庫名  
  13. 'Table 是表名  
  14. Try 

開始實(shí)現(xiàn)VB.NET導(dǎo)出數(shù)據(jù)

  1. cnnsr = "ODBC;DRIVER=SQL 
    Server;SERVER="
     + SERVER   
  2. cnnsrcnnsr = cnnsr + ";UID=;
    APP=Report Tools;WSID=ReportClient;
    DATABASE=" + DATABASE  
  3. cnnsrcnnsr = cnnsr + ";
    Trusted_Connection=Yes"  
  4. excel = New Excel.ApplicationClass  
  5. xBk = excel.Workbooks.Add(True)  
  6. xSt = xBk.ActiveSheet  
  7. xRange = xSt.Range("A4")  
  8. xRange.Select() 

開始

  1. xPivotCache = xBk.PivotCaches
    .Add(
    SourceType:=2)  
  2. xPivotCache.Connection = cnnsr 
  3. xPivotCache.CommandType = 2 
  4. sql = "select * from " + Table  
  5. xPivotCache.CommandText = sql 
  6. xPivotTable = xPivotCache.
    CreatePivotTable(
    TableDestination:
    ="Sheet1!R3C1"TableName:=
    "數(shù)據(jù)透視表1"DefaultVersion:=1

準(zhǔn)備行字段

  1. RowFields(0) = "字段1"  
  2. RowFields(1) = "字段2"  
  3. RowFields(2) = "字段3" 

準(zhǔn)備頁面字段

  1. PageFields(0) = "字段4"  
  2. PageFields(1) = "字段5"  
  3. PageFields(2) = "字段6"  
  4. PageFields(3) = "字段7"  
  5. PageFields(4) = "字段8"  
  6. PageFields(5) = "字段9"  
  7. xPivotTable.AddFields(RowFields
    RowFields:=RowFields, PageFields
    PageFields:=PageFields)  
  8. xPivotField = xPivotTable.
    PivotFields("數(shù)量")  
  9. xPivotField.Orientation = 4 

關(guān)閉工具條

  1. 'xBk.ShowPivotTableFieldList
     = False 
  2. 'excel.CommandBars("PivotTable")
    .visible = False 
  3. excel.Visible = True 
  4. Catch ex As Exception  
  5. If cnn.State = ConnectionState
    .Open Then  
  6. cnn.Close()  
  7. End If  
  8. xBk.Close(0)  
  9. excel.Quit()  
  10. MessageBox.Show(ex.Message,
     "報(bào)表工具", MessageBoxButtons.
    OK, MessageBoxIcon.Warning)  
  11. End Try 

VB.NET導(dǎo)出數(shù)據(jù)的具體代碼編寫就為大家介紹到這里。

【編輯推薦】

  1. VB.NET刪除控件具體應(yīng)用技巧分享
  2. VB.NET動(dòng)態(tài)屬性基本概念及應(yīng)用方法介紹
  3. VB.NET通知控件基本概念解析
  4. VB.NET消息隊(duì)列相關(guān)內(nèi)容詳細(xì)介紹
  5. VB.NET浮動(dòng)窗體創(chuàng)建技巧分享
責(zé)任編輯:曹凱 來源: IT168
相關(guān)推薦

2010-01-12 14:02:14

VB.NET數(shù)據(jù)實(shí)體層

2009-10-29 09:57:16

VB.NET實(shí)現(xiàn)數(shù)據(jù)綁

2010-01-11 17:40:36

VB.NET相框效果

2010-01-22 18:14:49

VB.NET菜單組件

2010-01-12 10:48:54

VB.NET LIST

2009-10-13 10:21:58

VB.NET實(shí)現(xiàn)Web

2009-10-12 14:32:40

VB.NET實(shí)現(xiàn)定時(shí)關(guān)

2009-10-23 13:22:25

VB.NET實(shí)現(xiàn)拖動(dòng)圖

2010-01-08 15:41:36

VB.NET窗口關(guān)閉

2010-01-12 10:40:58

VB.NET數(shù)據(jù)庫壓縮

2010-01-15 18:24:14

VB.NET打開Not

2009-10-14 13:56:05

VB.NET數(shù)據(jù)窗體

2010-01-12 16:39:26

VB.NET數(shù)據(jù)綁定

2009-10-14 13:15:09

VB.NET數(shù)據(jù)綁定

2009-10-23 15:35:42

VB.NET實(shí)用教程

2010-01-08 15:33:57

VB.NET文字寬度計(jì)

2009-11-03 10:18:46

VB.NET繼承

2009-10-29 16:23:42

VB.NET實(shí)現(xiàn)IEn

2009-11-10 16:20:25

VB.NET全局熱鍵

2010-01-08 18:31:45

VB.NET歷史菜單
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)