DataGridView控件,放一個(gè)DataGridView1和Button1到窗體,下面是按鈕下代碼
成都創(chuàng)新互聯(lián)主營(yíng)石阡網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,App定制開(kāi)發(fā),石阡h5微信小程序搭建,石阡網(wǎng)站營(yíng)銷(xiāo)推廣歡迎石阡等地區(qū)企業(yè)咨詢(xún)
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.DataGridView1.AllowUserToAddRows = False
DataGridView1.RowTemplate.Height = 200
DataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None
For i = 1 To 3
Me.DataGridView1.Columns.Add("列" i.ToString, "列" i.ToString)
Me.DataGridView1.Rows.Add()
Next
Me.DataGridView1.Columns(0).Width = 100
Me.DataGridView1.Columns(1).Width = 500
Me.DataGridView1.Columns(0).Width = 300
End Sub
'自己設(shè)置相關(guān)需要的屬性即可
1.新建一張表格,在表格中導(dǎo)入學(xué)生的成績(jī)表,如圖所示,將建立一個(gè)按鈕,通過(guò)它來(lái)實(shí)現(xiàn)查找。
2.單擊菜單欄中的“開(kāi)發(fā)工具”——插入——表單控件——按鈕,在出現(xiàn)的十字箭頭上拖住畫(huà)出一個(gè)按鈕,如圖所示。
3.在彈出的查找紅對(duì)話(huà)框中選擇“錄制”,在彈出的“錄制新宏”對(duì)話(huà)框中,修改宏名稱(chēng)為“查找”,單擊確定。
4. 單擊“開(kāi)發(fā)工具”——查看代碼,打開(kāi)VBA編輯器,如圖所示。
5.現(xiàn)在輸入代碼:
Sub 查找()
Dim jieguo As String, p As String, q As String
Dim c As Range
jieguo = Application.InputBox(prompt:="請(qǐng)輸入要查找的值:", Title:="查找", Type:=2)
If jieguo = "False" Or jieguo = "" Then Exit Sub
Application.ScreenUpdating = False
Application.DisplayAlerts = False
With ActiveSheet.Cells
? Set c = .Find(jieguo, , , xlWhole, xlByColumns, xlNext, False)
? If Not c Is Nothing Then
? ? ? p = c.Address
? ? ? Do
? ? ? ? ? c.Interior.ColorIndex = 4
? ? ? ? ? q = q c.Address vbCrLf
? ? ? ? ? Set c = .FindNext(c)
? ? ? Loop While Not c Is Nothing And c.Address p
? End If
End With
MsgBox "查找數(shù)據(jù)在以下單元格中:" vbCrLf vbCrLf _
? q, vbInformation + vbOKOnly, "查找結(jié)果"
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
6.現(xiàn)在回到EXCEL表格,右擊按鈕,選擇“編輯文字”,修改按鈕名稱(chēng)為“查找按鈕”。
7. 現(xiàn)在單擊查找按鈕,出現(xiàn)對(duì)話(huà)框“請(qǐng)輸入要查找的值”,在方框中輸入“男”,單擊確定,出現(xiàn)對(duì)話(huà)框“查找數(shù)據(jù)在一下單元格中”,單擊確定,對(duì)應(yīng)單元格就變成了亮色。
表格?table?
table
tr
td
單元格內(nèi)容
/td
/tr
/table
還是asp:DataGrid ID="dgdDataVita"/DataGrid
‘首先,創(chuàng)建一個(gè)VB.NET項(xiàng)目,再點(diǎn)擊菜單”項(xiàng)目“-”添加引用“,在”Com“-”類(lèi)型庫(kù)“里,選擇Microsoft.Word?14.0?Object?Library(對(duì)應(yīng)Office版本為2010),將以下代碼復(fù)制粘貼到Form1窗體替換原代碼。
’PS:以下代碼僅創(chuàng)建表格,將第行2至4列合并,添加1個(gè)文字,其他的你自己分析。
Imports?Microsoft.Office.Interop
Imports?Microsoft.Office.Interop.Word??'引入Word
Public?Class?Form1
Private?Sub?Form1_Load(sender?As?Object,?e?As?EventArgs)?Handles?MyBase.Load
Dim?DWrd?As?New?Word.Application,?DDoc?As?Word.Document?'定義Word及文檔對(duì)象
DDoc?=?DWrd.Documents.Add?'新增文檔
Dim?DTbl?As?Word.Table??'定義表格對(duì)象
DTbl?=?DDoc.Tables.Add(DDoc.Range,?7,?4)??'新增表格
DTbl.Style?=?"網(wǎng)格型"??'表格的樣式
DTbl.Cell(1,?2).Select()??'選擇起始單元格為第1行/第2列
DWrd.Selection.MoveRight(,?2,?SelectionMode.MultiExtended)??'向右擴(kuò)展兩個(gè)單元格(即選擇第1行的第2至4列)
DWrd.Selection().Cells.Merge()??'單元格合并
DTbl.Cell(1,?1).Range.Text?=?1??'在第1個(gè)單元格填寫(xiě)文本
DWrd.Visible?=?True?'顯示W(wǎng)ord
End?Sub
End?Class
現(xiàn)在工程里添加引用Microsoft.Office.Interop.Excel,然后可以使用如下代碼輸出。
Dim oXl As Excel.Application = New Excel.Application()
Dim oWb As Excel.Workbook
Dim oWs As Excel.Worksheet
On Error GoTo Morn
oWb = oXl.Workbooks.Add()
oWs = oWb.Worksheets(1)
With oWs
.Cells._Default(1, 1).Value ="a"
.Cells._Default(1, 2).Value ="b"
.Cells._Default(1, 3).Value ="c"
.Cells._Default(1, 4).Value ="d"
.Cells._Default(2, 1).Value ="32"
.Cells._Default(2, 2).Value ="1"
.Cells._Default(2, 3).Value ="90"
.Cells._Default(2, 4).Value ="合格"
End With
oWs.Parent.Names.Add("CostRange", "=" "A1:B39")
oWs.SaveAs(sFileName)
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
If MsgBox("已將數(shù)據(jù)輸出到Excel文件中! 現(xiàn)在打開(kāi)該文件?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "已完成") = MsgBoxResult.No Then
oXl.Quit()
Else
oXl.Visible = True
End If
oXl = Nothing
oWs = Nothing
oWb = Nothing
你應(yīng)該在調(diào)試的時(shí)候在你的把一條帶入了參數(shù)值的insert語(yǔ)句弄來(lái)看看,就能很快看出問(wèn)題在哪里。另外[date]字段(這個(gè)地方最好用個(gè)中括號(hào)擴(kuò)起來(lái),敏感字符串喲!
如果實(shí)在不好弄寫(xiě)各存儲(chǔ)過(guò)程吧。在Acess里面寫(xiě)一個(gè)添加查詢(xún)吧。用
網(wǎng)頁(yè)標(biāo)題:vb.net添加表格,vb如何添加表格
標(biāo)題網(wǎng)址:http://chinadenli.net/article36/hdoepg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站排名、微信小程序、網(wǎng)站改版、服務(wù)器托管、企業(yè)建站、小程序開(kāi)發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)