invalid variant operation 错误!请指点!(50分)

  • 主题发起人 主题发起人 downage
  • 开始时间 开始时间
D

downage

Unregistered / Unconfirmed
GUEST, unregistred user!
运行到加粗的那行就出这个错误,谢谢!
procedure TForm1.ExcelToMdb(EXLfile: string);
var
sheet,XLApp,workbook:variant;
iRow,MaxRow:integer;
begin
screen.Cursor:=crHourGlass;
try
//创建对象
XLApp:=createOleObject('Excel.Application');
XLApp.displayAlerts:=false;
XLApp.ScreenUpdating:=false;
XLApp.WorkBooks.Add(EXLfile);
workbook:=XLApp.workbooks[1];
sheet:=workbook.worksheets[1];
//sheet:=XLApp.WorkBooks[1].worksheets[1];
//取得最大行数 maxRow
XLApp.ActiveCell.SpecialCells(xlLastCell).Select;
maxRow:=XLApp.ActiveCell.Row
//最大行数
//label1.Caption:=inttostr(maxrow);
//写数据到Access库
adotable1.open;
for iRow:=2 to MaxRow do
begin
showmessage(inttostr(iRow));
if sheet.cells[iRow,1]<>'' then//关键字不为空
begin

adotable1.Append;
label1.Caption:=inttostr(iRow);
adotable1.fieldByName('cp_xinghao').asString:=sheet.cells[iRow,1];
//adotable1.fieldByName('cp_shuliang').asInteger:=strToInt(sheet.cells[iRow,2]);
adotable1.fieldByName('cp_shuliang').asInteger:=123123 ;
 
倒数第7行!
 
if sheet.cells[iRow,1] <> varEmpty then


{
VarType Contents of variant

varEmpty The variant is Unassigned.
varNull The variant is Null.
varSmallint 16-bit signed integer (type Smallint in Delphi, short in C++ ).
varInteger 32-bit signed integer (type Integer in Delphi, int in C++).
varSingle Single-precision floating-point value (type Single in Delphi, float in C++).
varDouble Double-precision floating-point value (type double).
varCurrency Currency floating-point value (type Currency).
varDate Date and time value (type TDateTime).

varOleStr Reference to a dynamically allocated UNICODE string.
varDispatch Reference to an Automation object (an IDispatch interface pointer).
varError Operating system error code.
varBoolean 16-bit boolean (type WordBool).
varVariant A variant.
varUnknown Reference to an unknown object (an IInterface or IUnknown interface pointer).
varShortInt 8-bit signed integer (type ShortInt in Delphi or signed char in C++)
varByte A Byte
varWord unsigned 16-bit value (Word)

varLongWord unsigned 32-bit value (type LongWord in Delphi or unsigned long in C++)
varInt64 64-bit signed integer (Int64 in Delphi or __int64 in C++)
varStrArg COM-compatible string.
varString Reference to a dynamically allocated string (not COM compatible).
varAny A CORBA Any value.

}
 
后退
顶部