简体   繁体   English

如何使用VB.NET检查Excel工作表名称中的特定文本? (此代码有什么问题?)

[英]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.

相关问题 使用 vb.net 在 excel 工作表中找到特定文本并返回它所在的行或列 - Locate a specific text in excel worksheet using vb.net and returning the row or column it’s in VB.Net Excel Addin,如何按名称将数据写入特定工作表? - VB.Net Excel Addin, how to write data to specific worksheet by name? 如何在Excel文件工作表中选择特定列,然后使用vb.net将它们存储到SQL Server数据库中 - How to select a specific column in an excel file worksheet and then store them into an SQL Server database using vb.net 使用VB.net更新Excel工作表 - Update an Excel worksheet using VB.net 使用VB.NET将公式写入excel单元格(此代码有什么问题?) - Write formula to excel cell using VB.NET (What is wrong with this code?) 使用VB.NET无法为excel中“命名”范围内的单元格添加值(此代码有什么问题?) - Unable to add value to cells in a “named” range in excel using VB.NET (what is wrong with this code?) 无法从VB.NET打开指定的工作表(此代码有什么问题?) - Unable to open a specif worksheet from VB.NET (What is wrong with this code?) 我这个vb.net代码有什么问题 - what is wrong in my this vb.net code VB.NET如何检查是否打开了具有特定文本的表单 - VB.NET how to check if a form with a specific text is opened 如何使用vb.net代码从现有的excel文件中删除某些特定的工作表? - How to delete some specific sheets from an existing excel file using vb.net code?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM