成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

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

開發(fā) 后端
VB.NET導(dǎo)出數(shù)據(jù)的實(shí)現(xiàn)可以通過本文介紹的這段代碼來進(jìn)行操作。初學(xué)者可以以此為參考對象,對這方面的知識(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菜單組件

2009-10-12 14:32:40

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

2010-01-08 15:41:36

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

2009-10-23 13:22:25

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

2009-10-13 10:21:58

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

2010-01-12 10:48:54

VB.NET LIST

2009-10-14 13:15:09

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

2010-01-12 16:39:26

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

2009-10-14 13:56:05

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

2010-01-15 18:24:14

VB.NET打開Not

2010-01-12 10:40:58

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

2009-10-29 14:02:24

VB和VB.NET比較

2009-10-20 14:21:55

VB.NET fnSi

2009-10-14 12:51:41

VB.NET Data

2011-06-17 11:05:22

VB.NET

2009-06-24 15:45:32

VB.NET

2010-01-13 13:53:32

VB.NET組件封裝
點(diǎn)贊
收藏

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

主站蜘蛛池模板: 9久久精品| 日本在线视频一区二区 | 伊人伊人| 久草视频观看 | 欧美大片久久久 | 国产激情视频在线 | 成人精品福利 | 日本天天操 | 新超碰97 | 国产成人免费视频网站视频社区 | 久久一| 欧美日韩在线一区二区三区 | 九九九视频在线观看 | 一区福利视频 | 欧美日韩在线观看视频网站 | 亚洲精品在线免费播放 | 亚洲在线电影 | 91视频精选 | 精品久久99| 亚洲欧美日韩一区二区 | 欧美极品在线视频 | 欧美一级大片免费看 | 伊人av在线播放 | 日本免费黄色 | 日韩中文字幕一区二区 | 日韩成人免费视频 | 天天搞夜夜操 | 男女羞羞免费视频 | 成人国产在线视频 | 免费一区二区三区 | 欧美一区二区三区在线免费观看 | 国产精品国产三级国产aⅴ中文 | 色av一区 | 亚洲国产精品99久久久久久久久 | 亚洲97| wwww.xxxx免费 | 久久亚洲精品久久国产一区二区 | 免费久久精品 | 日韩一区二区三区视频 | 女人天堂av | 色婷婷国产精品综合在线观看 |