0

我用 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(object index)

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

有谁知道如何像我在 C# 中那样选择工作表,或者我应该使用哪种方法而不是 get_item(object index)

4

1 回答 1

2

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

于 2013-10-24T14:08:52.257 回答