使用vb.net

时间:2016-08-30 07:40:38

标签: vb.net excel

使用下面的代码(VB.net)我可以在Excel工作表中过滤列'A','B'。但我没有得到如何读取列'C'过滤数据。请帮我。 提前谢谢。

Dim excel_app As New Excel.ApplicationClass()
Dim workbook As Excel.Workbook
Dim sheet As Excel.Worksheet

excel_app = New Excel.ApplicationClass()
excel_app.Visible = True
workbook = excel_app.Workbooks.Open(Filename:="C:\abc.xls", ReadOnly:=True)
sheet = DirectCast(workbook.Sheets(1), Excel.Worksheet)
sheet.Activate()
sheet.AutoFilterMode = False

Dim value_range As Excel.Range
value_range = sheet.Range("A1").CurrentRegion
value_range.Select()
'sheet.Range("A1").AutoFilter(Field:=1, Criteria1:="ABC", Operator:=Excel.XlAutoFilterOperator.xlFilterValues)
'sheet.Range("B1").AutoFilter(Field:=2, Criteria1:="XYZ", Operator:=Excel.XlAutoFilterOperator.xlFilterValues)
value_range.AutoFilter(Field:=1, Criteria1:="ABC", Operator:=Excel.XlAutoFilterOperator.xlFilterValues)
value_range.AutoFilter(Field:=2, Criteria1:="XYZ", Operator:=Excel.XlAutoFilterOperator.xlFilterValues) 

0 个答案:

没有答案