日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
VB.NET導(dǎo)出數(shù)據(jù)實(shí)現(xiàn)你想要的效果

 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。

成都創(chuàng)新互聯(lián)服務(wù)項(xiàng)目包括烏拉特后網(wǎng)站建設(shè)、烏拉特后網(wǎng)站制作、烏拉特后網(wǎng)頁制作以及烏拉特后網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢(shì)、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,烏拉特后網(wǎng)站推廣取得了明顯的社會(huì)效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到烏拉特后省份的部分城市,未來相信會(huì)繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!

 
 
 
  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)建技巧分享

新聞標(biāo)題:VB.NET導(dǎo)出數(shù)據(jù)實(shí)現(xiàn)你想要的效果
分享URL:http://m.5511xx.com/article/cddhphe.html