新聞中心
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ù)獲得客戶的支持與信任!
- Dim excel As Excel.Application
- Dim xBk As Excel._Workbook
- Dim xSt As Excel._Worksheet
- Dim xRange As Excel.Range
- Dim xPivotCache As Excel.
PivotCache- Dim xPivotTable As Excel.
PivotTable- Dim xPivotField As Excel.
PivotField- Dim cnnsr As String, sql
As String- Dim RowFields() As String =
{"", "", ""}- Dim PageFields() As String =
{"", "", "", "", "", ""}- 'SERVER 是服務(wù)器名或服務(wù)器的IP地址
- 'DATABASE 是數(shù)據(jù)庫名
- 'Table 是表名
- Try
開始實(shí)現(xiàn)VB.NET導(dǎo)出數(shù)據(jù)
- cnnsr = "ODBC;DRIVER=SQL
Server;SERVER=" + SERVER- cnnsrcnnsr = cnnsr + ";UID=;
APP=Report Tools;WSID=ReportClient;
DATABASE=" + DATABASE- cnnsrcnnsr = cnnsr + ";
Trusted_Connection=Yes"- excel = New Excel.ApplicationClass
- xBk = excel.Workbooks.Add(True)
- xSt = xBk.ActiveSheet
- xRange = xSt.Range("A4")
- xRange.Select()
開始
- xPivotCache = xBk.PivotCaches
.Add(SourceType:=2)- xPivotCache.Connection = cnnsr
- xPivotCache.CommandType = 2
- sql = "select * from " + Table
- xPivotCache.CommandText = sql
- xPivotTable = xPivotCache.
CreatePivotTable(TableDestination:
="Sheet1!R3C1", TableName:=
"數(shù)據(jù)透視表1", DefaultVersion:=1)
準(zhǔn)備行字段
- RowFields(0) = "字段1"
- RowFields(1) = "字段2"
- RowFields(2) = "字段3"
準(zhǔn)備頁面字段
- PageFields(0) = "字段4"
- PageFields(1) = "字段5"
- PageFields(2) = "字段6"
- PageFields(3) = "字段7"
- PageFields(4) = "字段8"
- PageFields(5) = "字段9"
- xPivotTable.AddFields(RowFields
RowFields:=RowFields, PageFields
PageFields:=PageFields)- xPivotField = xPivotTable.
PivotFields("數(shù)量")- xPivotField.Orientation = 4
關(guān)閉工具條
- 'xBk.ShowPivotTableFieldList
= False- 'excel.CommandBars("PivotTable")
.visible = False- excel.Visible = True
- Catch ex As Exception
- If cnn.State = ConnectionState
.Open Then- cnn.Close()
- End If
- xBk.Close(0)
- excel.Quit()
- MessageBox.Show(ex.Message,
"報(bào)表工具", MessageBoxButtons.
OK, MessageBoxIcon.Warning)- End Try
VB.NET導(dǎo)出數(shù)據(jù)的具體代碼編寫就為大家介紹到這里。
【編輯推薦】
- VB.NET刪除控件具體應(yīng)用技巧分享
- VB.NET動(dòng)態(tài)屬性基本概念及應(yīng)用方法介紹
- VB.NET通知控件基本概念解析
- VB.NET消息隊(duì)列相關(guān)內(nèi)容詳細(xì)介紹
- 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


咨詢
建站咨詢
