我用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(对象索引)
答案 0 :(得分:2)
您可以使用Sheets(1)
引用该项目,因为Item是默认属性。因此,Sheets.Item(1)
也可以。