如何使用后期绑定从vb.net对excel中的数据进行排序? [英] How to sort data in excel from vb.net using late binding?
本文介绍了如何使用后期绑定从vb.net对excel中的数据进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要排序两列数据。我使用的代码给了我一个错误;
I have two columns of data that I wish to sort. The code I have used gives me an error of;
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll
Additional information: Exception from HRESULT: 0x800A03EC
当我使用早期绑定时,代码工作正常!
排序前A列和B列中的数据如下所示
The code worked okay when I was using early binding!
Data looks like this in columns A and B before sorting
1 Alan Wicks
9 Alan Wicks
10 Alan Wicks
1 Bernard McTernan
9 Bernard McTernan
1 Bob Horne
2 Bob Horne
3 Bob Horne
我尝试了什么:
What I have tried:
'List of Imports
Imports System
Imports System.IO
Imports System.Xml
Imports System.Data.OleDb
'List of Public Const
Public Const dbAscending = 1
Public Const dbSortNormal = 0
Public Const dbSortColumns = 3
Public Const dbYes = 1
'bit of code causing the failure
oSheet.Range(oSheet.Cells(a, 1), oSheet.Cells(b, 2)).Sort(
Key1:=oSheet.Columns(1), Order1:=dbAscending,
Key2:=oSheet.Columns(2), Order2:=dbAscending,
Header:=dbYes,
OrderCustom:=1, MatchCase:=False,
Orientation:=dbSortColumns,
DataOption1:=dbSortNormal,
DataOption2:=dbSortNormal)
推荐答案
决定前进的方法是将数据放入数据表并在那里排序;然后将已排序的数据传输到excel表。
Decided that the way forward is to put the data into a datatable and sort there; then transfer sorted data to excel sheet.
这篇关于如何使用后期绑定从vb.net对excel中的数据进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文