当前单元格指的是 DataGridView 焦点所在的单元格,它可以通过 DataGridView 对象的 CurrentCell 属性取得。
如果当前单元格不存在的时候,返回Nothing(C#是null)[VBNET]
' 取得当前单元格内容
ConsoleWriteLine(DataGridView1CurrentCellValue)
' 取得当前单元格的列 Index
ConsoleWriteLine(DataGridView1CurrentCellColumnIndex)
' 取得当前单元格的行 Index
ConsoleWriteLine(DataGridView1CurrentCellRowIndex) [C#]
// 取得当前单元格内容
ConsoleWriteLine(DataGridView1CurrentCellValue);
// 取得当前单元格的列 Index
ConsoleWriteLine(DataGridView1CurrentCellColumnIndex);
// 取得当前单元格的行 Index
ConsoleWriteLine(DataGridView1CurrentCellRowIndex);
另外,使用 DataGridViewCurrentCellAddress 属性(而不是直接访问单元格)来确定单元格所在的行:DataGridViewCurrentCellAddressY 和列: DataGridViewCurrentCellAddressX 。
这对于避免取消共享行的共享非常有用。
你的图上看不出行吗和卡号的列,下面假设是C、D,你修改正确就可以使用
sub test()dim sum,i,arr,k1,k2,v;
'汇总
set sum=createobject("scriptingdictionary")
arr=sheets("a")usedrange
for i=2 to ubound(arr)
k1=arr(i,3) '3表示姓名的C列
k2=arr(i,4) '4表示卡号在D列
k=k1 & vbtab & k2
v=arr(i,2) '2表示产量在B列
sum(k)=sum(k)+v
next i
'显示
i=2
for each k in sumkeys
arr=split(k,vbtab)
k1=arr(0)
k2=arr(1)
v=sum(k)
sheets("b")cells(i,1)resize(1,3)=array(k1,k2,v)
i=i+1
next k
end sub
dim
myexcel
as
new
excelapplication
'定义进程
dim
workbook
as
excelworkbook
'定义工作簿
dim
sheet
as
excelworksheet
'定义工作表
' *** 作
myexcelvisible
=
false
'不显示excel
程序
workbook
=
myexcelworkbooksadd()
'
sheet
=
workbooksheets(1)
'获得第1个工作表的控制句柄
sheetcells(1,
3)
=
"好人一生幸福"
&
i
'对指定单元格赋值(读信息当然也没问题了)sheetcells(1,
3)
分类: 电脑/网络 >> 程序设计 >> 其他编程语言
问题描述:
最好详细点,兄弟笨笨的呢
解析:
Private Sub Form_Load()
Text1Text = AppPath & "\123xls"
Text2Text = AppPath & "\123mdb"
Text3Text = "sheet1"
Text4Text = "sheet1"
Data1DatabaseName = AppPath & "\123mdb"
End Sub
Private Sub Command1_Click()
Dim db As Database
Dim sheet As String, excelpath As String, AccessPath As String, AccessTable As String
AccessPath = Text2Text '数据库路径
excelpath = Text1Text '电子表格路经
AccessTable = Text4Text '数据库内表格
sheet = Text3Text '电子表格内工作表
Set db = OpenDatabase(excelpath, True, False, "Excel 50") '打开电子表格文件
SQL = ("Select into [;database=" & AccessPath & "]" & AccessTable & " FROM [" & sheet & "$]")
dbExecute (SQL) '将电子表格导入数据库
Data1RecordSource = "sheet1"
Data1Refresh
DBGrid1Refresh '显示电子表格导入到数据库的数据
End Sub
上面的是把EXCEL读取到数据库中,你做点修改就行了一个Data控件
读取写EXCEL文件的过程readExl
思路,给出文件名及其属性,将其读入二维数组,程序引用二维数组内数据即可
其中xlsPath为文件全名,包括路径和名称,CCOL为列总数,rrows为行总数,readexla为读写文件放置的数组,readYes为判断是读文件还是写文件,读文件为真,写文件为假。
-------------------------------------------------------------------------------------------------------------------------------
Option Explicit
Private Sub Command1_Click()
Dim b() As String
Call readExl(AppPath & "\1xlsx", 3, 3, b, True)
Call readExl(AppPath & "\2xlsx", 3, 3, b, False)
Print b(1, 1)
End Sub
Sub readExl(ByVal xlsPath As String, ByVal ccol As Integer, _
ByVal rrows As Integer, readEXLA() As String, _
ByVal readYes As Boolean)
Dim xls As ExcelApplication
Dim wkk As ExcelWorkbook
Dim sht As ExcelWorksheet
Dim i As Integer, j As Integer
Set xls = New ExcelApplication
xlsVisible = False
If readYes Then
Set wkk = xlsWorkbooksOpen(xlsPath)
Set sht = wkkActiveSheet
ReDim readEXLA(1 To ccol, 1 To rrows)
For i = 1 To rrows
For j = 1 To ccol
readEXLA(i, j) = shtCells(i, j)
Next j
Next i
Else
xlsSheetsInNewWorkbook = 1
xlsWorkbooksAdd
Set wkk = xlsActiveWorkbook
Set sht = wkkActiveSheet
For i = 1 To rrows
For j = 1 To ccol
shtCells(i, j) = readEXLA(i, j)
Next j
Next i
wkkSaveAs xlsPath
wkkClose
End If
Set wkk = Nothing
Set sht = Nothing
xlsQuit
Set xls = Nothing
End Sub
------------------------------------------------------------------------------------------------------------------------------
代码及注释如下:
Sub main()
f = Dir("D;\xls") '查找D盘根目录的所有Excel文件
Do While f <> ""
WorkbooksOpen ("D:\" & f) '依次D盘根目录的所有Excel文件
k = k + 1
Cells(k, 1) = Workbooks(f)Range("A1") '将打开的Excel文件中的A1单元格内容依次提取到当前工作表中
f = Dir
Loop
End Sub
以上就是关于vb.net中如何获得DataGridView单元格内容全部的内容,包括:vb.net中如何获得DataGridView单元格内容、用VB编辑表格A,达到提取表格B所需要内容的公式及 *** 作方法,请看图便于制作谢谢!、VB.NET获取Excel单元格内容等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)