VB.net 调用excel文件的sort方法排序时报错
使用vs2015,调用excel,用sort方法对range对象排序,程序运行出错以下是代码:
Dim AppXls As Microsoft.Office.Interop.Excel.Application '声明Excel对象
Dim AppWorkBook As Microsoft.Office.Interop.Excel.Workbook '声明工作簿对象
Dim AppSheet As New Microsoft.Office.Interop.Excel.Worksheet '声明工作表对象
Dim rng_Data As Microsoft.Office.Interop.Excel.Range
AppXls = New Microsoft.Office.Interop.Excel.Application '实例化Excel对象
AppXls.Workbooks.Open("E:\test.xlsx") '打开已经存在的EXCEL文件
AppXls.Visible = True '使Excel可见
AppWorkBook = AppXls.Workbooks(1) 'AppWokBook对象指向工作簿
AppSheet = AppWorkBook.Sheets("Sheet1") 'AppSheet对象指向AppWokBook对象中的表“Sheet1”
rng_Data = AppSheet.Range("A1:G267")
AppSheet.Range("A1:G267").Sort(Key1:=AppSheet.Range(AppSheet.Range("E1").Value),
Order1:=XlSortOrder.xlAscending,
Header:=XlYesNoGuess.xlYes,
Orientation:=XlSortOrientation.xlSortColumns)
程序运行到下句时报错,
AppSheet.Range("A1:G267").Sort(Key1:=AppSheet.Range(AppSheet.Range("E1").Value),
Order1:=XlSortOrder.xlAscending,
Header:=XlYesNoGuess.xlYes,
Orientation:=XlSortOrientation.xlSortColumns)
报错信息:
引发的异常:“System.Runtime.”(位于 生成工具.exe 中)
求各位大老看下问题出在哪?
[此贴子已经被作者于2019-4-24 08:44编辑过]