使用Selection.ListObject.QueryTable Intact将Excel VBA转换为VB.Net

我需要访问Selection.ListObject.QueryTable对象为了保留列的宽度。

代码如下:

  Range("B9").Select() With Selection.ListObject.QueryTable .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .BackgroundQuery = True .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = False .RefreshPeriod = 0 .PreserveColumnInfo = True End With 

什么是这个Excel的VB.Net版本生成的VBA代码?

这样的事情呢?

 Dim excelApp AS Object = CreateObject("Excel.Application") excelApp.Workbooks.Open(Filename:=_file) With excelApp.ActiveWorkbook.Worksheets(0).Cells(9, 2).QueryTable .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .BackgroundQuery = True .RefreshStyle = 1 .SavePassword = False .SaveData = True .AdjustColumnWidth = False .RefreshPeriod = 0 .PreserveColumnInfo = True End With 

其中_file是您的Excel文件的名称。