excel sort 排序问题 from Delphi servers-- excelworksheet Range(200分)

  • 主题发起人 主题发起人 cbsok
  • 开始时间 开始时间
C

cbsok

Unregistered / Unconfirmed
GUEST, unregistred user!
ExcelApplication,ExcelWorkBook,ExcelWorkSheet都能正确使用
怎样使用Range.Sort方法
procedure TDataModuleMyExcel.MySort;
var
DataRange:Range;
key1:OleVariant;
begin
ExcelWorksheet1.Activate;
DataRange:=ExcelWorksheet1.Range['A1','A1'].CurrentRegion;
DataRange.Select;
//Key1:='Range("M2")';
TvarData(Key1).VType:=varDispatch;
TvarData(Key1).VDispatch:='Range("A2")';
DataRange.Sort(key1,xlDescending,
Emptyparam,Emptyparam,Emptyparam,Emptyparam,Emptyparam,
xlGuess,1,False,xlTopToBottom,xlPinYin);
运行时报错

vba宏如下
{' cbsok 记录的宏 2004-6-3
Selection.Sort Key1:=Range("A2"), Order1:=xlDescending,Header:=xlGuess,_
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom,SortMethod_
:=xlPinYin, DataOption1:=xlSortTextAsNumbers}

查到的资料
IRange
function Sort(Key1: OleVariant; Order1: XlSortOrder; Key2: OleVariant; Type_: OleVariant;
Order2: XlSortOrder; Key3: OleVariant; Order3: XlSortOrder; Header: XlYesNoGuess;
OrderCustom: OleVariant; MatchCase: OleVariant; Orientation: XlSortOrientation;
SortMethod: XlSortMethod; out RHS: OleVariant): HResult; stdcall;

Excel Macro
Selection.Sort Key1:=Range("B2"), Order1:=xlAscending, Key2:=Range("C2") _
, Order2:=xlAscending, Key3:=Range("D2"), Order3:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom

Excel Range
function Sort(Key1: OleVariant; Order1: XlSortOrder; Key2: OleVariant; Type_: OleVariant;
Order2: XlSortOrder; Key3: OleVariant; Order3: XlSortOrder; Header: XlYesNoGuess;
OrderCustom: OleVariant; MatchCase: OleVariant; Orientation: XlSortOrientation;
SortMethod: XlSortMethod): OleVariant; dispid 880;

Any Help ?
 
后退
顶部