VB.net excel合并单元格范围 [英] VB.net excel merged cells range
问题描述
我有一个可以容纳一些尺寸的 Excel 电子表格.我想在运行时搜索这个文件.
I have a Excel spreadsheet that hold some sizes. And I would like to search this file at runtime.
此工作表包含一个表列 1 定义搜索必须出现的组.因此,我将搜索 A 列,直到找到包含我喜欢的组的单元格.
This Sheet contains a table column 1 defines the group within the search must occur. So I will search Column A until I find a cell containing the group I prefer.
该组是一个合并单元格,包含属于该组的所有行.
This group is a merged cell that contains all the rows that belong to this group.
我的问题:如何获取合并单元格消耗的行范围?需要此范围才能列出该组的所有可用评分.
My question: How can I get the range of rows consumed by the merged cell? This range is needed to list all available ratings for this group.
推荐答案
感谢 J. Chomel 的评论.我可以自己回答这个问题.这个链接向我展示了我需要的所有信息.
Thanks to the comment by J. Chomel. I could answer this question by myself. This Link showed me all the information I needed.
谢谢!
Public Sub GetRatings()
Dim oExcelLoc As String = "J:\EXCEL - Lijsten\NOZZLE SIZES.xlsx"
' Excel load data
Dim oExcelApp As New Application
Dim oWorkBook As Workbook
Dim oWorkSheet As Worksheet
oWorkBook = oExcelApp.Workbooks.Open(oExcelLoc, False, True)
oWorkSheet = oWorkBook.Worksheets(1)
For oRow As Integer = 1 To 100
If oWorkSheet.Range("A" & oRow).Value = GroupString Then
Dim oRange As Range
oRange = oWorkSheet.Range("A" & oRow)
' Check if merge cells
If oRange.MergeCells Then
Debug.Print("Group start row = " & oRow & " |Group end row = " & oRow + oRange.MergeArea.Rows.Count - 1)
Else
MsgBox("Error")
End If
Exit For
End If
Next
oWorkBook.Close()
'Release object references.
releaseObject(oWorkSheet)
releaseObject(oWorkBook)
releaseObject(oExcelApp)
End Sub
Private Sub releaseObject(ByVal obj As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
obj = Nothing
Catch ex As Exception
obj = Nothing
Finally
GC.Collect()
End Try
End Sub
这篇关于VB.net excel合并单元格范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!