如何在VB中选择工作簿的工作表

时间:2013-10-24 13:52:10

标签: .net vb.net excel

我用C#编写代码,然后使用在线转换工具

在VB中转换它

C#代码: -

ExcelObj = new ExcelShet.Application();
ExcelShet.Workbook theWorkbook = ExcelObj.Workbooks.Open(filepath);
ExcelShet.Sheets sheets = theWorkbook.Worksheets;
ExcelShet.Worksheet worksheet = (ExcelShet.Worksheet)sheets.get_Item(1);

已转换的VB代码

Dim ExcelObj As New ExcelShet.Application()
Dim theWorkbook As ExcelShet.Workbook = ExcelObj.Workbooks.Open(filepath)
Dim sheets As ExcelShet.Sheets = theWorkbook.Worksheets
Dim worksheet As ExcelShet.Worksheet = DirectCast(sheets.get_Item(1), ExcelShet.Worksheet)

现在问题是 - VB没有函数get_item(对象索引)

    Dim worksheet As ExcelShet.Worksheet = DirectCast(sheets.get_Item(1), ExcelShet.Worksheet)

是否有人知道如何选择工作表就像我在C#中所做的那样 要么 我应该使用哪种方法代替get_item(对象索引)

1 个答案:

答案 0 :(得分:2)

您可以使用Sheets(1)引用该项目,因为Item是默认属性。因此,Sheets.Item(1)也可以。