var i,j:integer;
begin
opendialog1.InitialDir:=ExtractFileDir(paramstr(0));//文件的打存放初始路径
opendialog1.Execute;
Try
ExcelApplication1.Connect;//EXCEL应用程序
Except
MessageDlg('Excel may not be installed',mtError, [mbOk], 0);
Abort;
End;
ExcelApplication1.Visible[0]:=True;
ExcelApplication1.Caption:='Excel Application';
try
excelapplication1.Workbooks.Open(opendialog1.FileName,
null,null,null,null,null,null,null,null,null,null,null,null,0);//打开指定的EXCEL 文件
except
begin
ExcelApplication1.Disconnect;//出现异常情况时关闭
ExcelApplication1.Quit;showmessage('请选择EXCEL电子表格!');
exit;
end;
end;
ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks[1]);//ExcelWorkbook1与Eexcelapplication1建立连接
ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Worksheets[1] as _Worksheet);//Excelworksheet1与Excelworkbook1建立连接
//开始从EXCEL中取数,放到stringgrid1中,取完数后关闭EXCEL
for i:=1 to 1000 do//最大取值1000
for j:=1 to 6 do
begin
if trim(excelworksheet1.cells.item[i+1,1])<>'' then
begin
stringgrid1.rowCount:=i+1;
stringgrid1.Cells[j,i]:=ExcelWorksheet1.Cells.Item[i+1,j];
end
else
begin
label3.caption:=inttostr(i-1);
ExcelApplication1.Disconnect;
ExcelApplication1.Quit; 报错如下
[Error] Unit1.pas(69): Not enough actual parameters
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'提示 null,null,null,null,null,null,null,null,null,null,null,null,0);//打开指定的EXCEL 文件 提示出错在这行代码处,兄弟们,有没有办法,或者excel导入其它表格也行
begin
opendialog1.InitialDir:=ExtractFileDir(paramstr(0));//文件的打存放初始路径
opendialog1.Execute;
Try
ExcelApplication1.Connect;//EXCEL应用程序
Except
MessageDlg('Excel may not be installed',mtError, [mbOk], 0);
Abort;
End;
ExcelApplication1.Visible[0]:=True;
ExcelApplication1.Caption:='Excel Application';
try
excelapplication1.Workbooks.Open(opendialog1.FileName,
null,null,null,null,null,null,null,null,null,null,null,null,0);//打开指定的EXCEL 文件
except
begin
ExcelApplication1.Disconnect;//出现异常情况时关闭
ExcelApplication1.Quit;showmessage('请选择EXCEL电子表格!');
exit;
end;
end;
ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks[1]);//ExcelWorkbook1与Eexcelapplication1建立连接
ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Worksheets[1] as _Worksheet);//Excelworksheet1与Excelworkbook1建立连接
//开始从EXCEL中取数,放到stringgrid1中,取完数后关闭EXCEL
for i:=1 to 1000 do//最大取值1000
for j:=1 to 6 do
begin
if trim(excelworksheet1.cells.item[i+1,1])<>'' then
begin
stringgrid1.rowCount:=i+1;
stringgrid1.Cells[j,i]:=ExcelWorksheet1.Cells.Item[i+1,j];
end
else
begin
label3.caption:=inttostr(i-1);
ExcelApplication1.Disconnect;
ExcelApplication1.Quit; 报错如下
[Error] Unit1.pas(69): Not enough actual parameters
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'提示 null,null,null,null,null,null,null,null,null,null,null,null,0);//打开指定的EXCEL 文件 提示出错在这行代码处,兄弟们,有没有办法,或者excel导入其它表格也行
var
ExcelApp : Variant;
sheet : Variant;
ExcelRowCount : integer; //Excel行数
ExcelColCount : integer; //Excel列数
i : integer; //行变量
j : integer; //列变量
str : String;
WBK : OleVariant;
begin
if Edit1.Text = '' then
showmessage('首先选择要导入的Excel文件')
else
begin
//导入数据到DBGrid
ExcelApp:=CreateOleObject('Excel.Application'); //建立Excel对象
WBK := ExcelApp.WorkBooks.Open(Edit1.Text); //打开指定文件
sheet := ExcelApp.WorkSheets[1];
ExcelApp.Visible := False; //不显示Excel
ExcelRowCount := ExcelApp.WorkSheets[1].UsedRange.Rows.Count; //行数
ExcelColCount := ExcelApp.WorkSheets[1].UsedRange.Columns.Count; //列数
showmessage(inttostr(ExcelColCount));
for i := 1 to ExcelRowCount do
begin
for j := 1 to ExcelColCount do
begin
str := sheet.cells[j,i];
showmessage('第'+inttostr(i)+'行,第'+inttostr(j)+'列的值为'+str);
stringgrid1.Cells[j-1,i-1] := str;
end;
stringgrid1.RowCount := StringGrid1.RowCount + 1;
end;
WBK.Close(SaveChanges := True);
end;
end;
提示[Error] Unit1.pas(70): Undeclared identifier: 'CreateOleObject'
怎么定义呀