[英]How to check for a specific text in excel worksheet name using VB.NET? (What is wrong in this code?)
I want to achieve following, 我想实现以下目标,
I have an excel file that contains worksheets with different names. 我有一个Excel文件,其中包含具有不同名称的工作表。 Some of the sheets are named as A1, A2, B1, B2, C1, C2 etc.
某些工作表被命名为A1,A2,B1,B2,C1,C2等。
If the sheet name contains "A" then export A3:A70 to a different workbook called "range.xlsx" 如果工作表名称包含“ A”,则将A3:A70导出到另一个名为“ range.xlsx”的工作簿中
If the sheet name contains "B" then export range B3:B70 to "range.xlsx" 如果工作表名称包含“ B”,则将范围B3:B70导出到“ range.xlsx”
If the sheet name contains "C" then export range C3:C70 to "range.xlsx" 如果工作表名称包含“ C”,则将范围C3:C70导出到“ range.xlsx”
Any help will be really appreciated. 任何帮助将不胜感激。
This is what I tried: 这是我尝试的:
Created a list of sheet names and looped through this list to do what I want to do. 创建工作表名称的列表,并遍历该列表以执行我想做的事情。
Thanks 谢谢
Untested code, but should get you going in the right direction... 未经测试的代码,但是应该让您朝正确的方向前进...
Dim wkbk As Excel.Workbook = ...
Dim regxp As New Regex("[abc]")
For Each wkst In wkbk.Worksheets
If Not regxp.Match(wkst.Name) = "" Then
...
End If
Next
I think, now I know how to deal with this issue. 我想,现在我知道如何处理这个问题了。 Apparently, if I can create a list of all excel worksheet names then I will be able to loop through this list.
显然,如果我可以创建所有excel工作表名称的列表,则可以遍历该列表。 I will try to write it and post it.
我将尝试编写并发布它。
Thanks 谢谢
Following code works. 以下代码有效。
Dim sheets As Excel.Worksheet
Dim slist As String = ""
For Each sheets In oWB1.Worksheets
slist += sheets.Name
Next
RichTextBox1.Text = slist
For i = 1 To num
If slist.Contains("C" & i) Then
'loops to export values
End If
Next
Thanks. 谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.