标题:VB.net 调用excel文件的sort方法排序时报错
只看楼主
zblgd
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2019-4-23
 问题点数:0 回复次数:0 
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编辑过]

搜索更多相关主题的帖子: excel sort 对象 Microsoft Office 
2019-04-24 08:37



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-494379-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.210880 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved