excel问题,急啊,在线等待!!!(300分)

M

mylixin

Unregistered / Unconfirmed
GUEST, unregistred user!
var
xlApp, xlBook, xlSheet, xlRange: Variant;
begin
printForm.ocJHHZB.Run;
xlBook := printForm.ocJHHZB.OleObject; //ocjhhzb :TOleContainer
try
xlBook.windows[1].Visble := True; //开始出错!!
xlBook.Activate;
xlSheet := xlBook.WorkSheet['Sheet1'];
xlSheet.Activate;
xlBook.Application.DisplayAlers := False;
except
raise;
end;
end;
其中ocJHHZB已经insert object了一张excel表!!

提示"EOleErr with Message 'method 'visble' not supported by aotomation object'"
急啊,在线等待!!!!!!
 
没人回答吗?[:(]
 
xlBook.windows[1].Visble[0] := True;
0 //
 
不行,也不对
 
->EOleErr with Message 'method 'visble' not supported by aotomation object'
它的提示就是这个对象不支持visble这个方法,你试试可不可以换一种方法实现你想要的结果?
 
晕,大哥,如果可以的话,我何必贴贴子,不过谢你帮我顶了以下
 
你是要做什么?
 
汇总报表,用EXCEL作模版,自定义报表,以前用EXCEL97搞定,
现在用户要求改为2000,就出现问题了。。。。
还是自己先看看,希望大家能帮上忙
 
将xlBook.windows[1].Visble := True; 改为:xlApp.Visible[0] := False ;
 
我做了一个例子,你可以试试,其实Delphi与Excel通信的最好方法是用ADO而不是用OLE,
用ADO速度要快N倍!
unit print;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, DB, ADODB, ActiveX, Excel_TLB, ComObj, uMsg;

type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
qrStation: TADOQuery;
cbStation: TComboBox;
cbProfessor: TComboBox;
Label1: TLabel;
Label2: TLabel;
BitBtn1: TBitBtn;
BitBtn3: TBitBtn;
qrSort: TADOQuery;
qrStationStation: TWideStringField;
BitBtn2: TBitBtn;
cbFile: TCheckBox;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure BitBtn3Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
private
Ready : Boolean ;
DocNo : Integer ;
WorkPath : String ;
Excel : TExcelApplication ;
procedure PrintOne(Depart, Prof :String);
procedure Prepare;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin

WorkPath := ExtractFilePath(Application.ExeName);

With QrStation do begin
if Active then Close ;
Open ;
cbStation.Items.Clear ;
cbStation.Items.Add('全部');
While not eof do begin
cbStation.Items.Add(Fields[0].AsString);
Next;
end;
Close ;
end;
cbStation.ItemIndex := 0;
cbProfessor.ItemIndex := 0;
Excel := TExcelApplication.Create(Self) ;
Excel.Visible[0] := False ;
DocNo := 1; Ready := False;
end;

procedure TForm1.PrintOne(Depart, Prof :String);
var
i : integer;
XlBook : Variant ;
XlSheet : Variant ;
begin
With qrSort do begin
if Active then Close;
Parameters.ParamByName('Station').Value := Depart ;
Parameters.ParamByName('Professor').Value := Prof;
Open ; First; i:=5 ;
if Eof then begin
Close;
Exit;
end;
Form2.Caption := '正在处理 '+Depart+' '+Prof ;
form2.Show ;
xlBook := Excel.WorkBooks.Add(WorkPath+'2002远程教育注册表.xls',0);
xlSheet := Excel.WorkSheets[1];
xlSheet.Cells(2,1) := '教学单位:'+Depart ;
xlSheet.Cells(2,6) := '教学点:'+Fields[13].AsString;
xlSheet.Cells(2,8) := '专业代码:'+Fields[12].AsString ;
xlSheet.Cells(2,10) := '专业名称:'+Prof ;
While not Eof do begin
Form2.Label1.Caption := '正在处理第 '+IntToStr(i-4)+' 条记录!';
Form2.ProgressBar1.Position := (i-4)*100 div RecordCount ;
Form2.Refresh ;
xlSheet.Cells(i, 1) := i-4 ;
xlSheet.Cells(i, 2) := Trim(Fields[0].AsString);
xlSheet.Cells(i, 3) := Trim(Fields[1].AsString);
xlSheet.Cells(i, 4) := Trim(Fields[2].AsString);
xlSheet.Cells(i, 5) := Trim(Fields[3].AsString);
xlSheet.Cells(i, 6) := Trim(Fields[4].AsString);
xlSheet.Cells(i, 7) := Trim(Fields[5].AsString);
xlSheet.Cells(i, 8) := Trim(Fields[6].AsString);
xlSheet.Cells(i, 9) := Trim(Fields[7].AsString);
xlSheet.Cells(i, 10) := Trim(Fields[8].AsString);
xlSheet.Cells(i, 11) := Trim(Fields[9].AsString);
xlSheet.Cells(i, 12) := Trim(Fields[10].AsString);
xlSheet.Cells(i, 13) := Trim(Fields[11].AsString);
Next ; Inc(i);
end;
i:=(i div 16 +1)*16;
xlSheet.PageSetup.PrintArea := 'A1:M'+IntToStr(i+4);
if cbFile.Checked then
xlBook.SaveAs(WorkPath+Trim(Depart)+Trim(Prof)+'.xls', xlNormal, '', '',False,False);
Close ;
Form2.Close ;
end;
Ready := True ;
end;

procedure TForm1.Prepare ;
var
i, k : Integer ;
begin
if cbStation.ItemIndex = 0 then begin
for i:= 1 to cbStation.Items.Count do
if cbProfessor.ItemIndex = 0 then
for k:=1 to cbProfessor.Items.Count do
PrintOne(cbStation.Items,cbProfessor.Items[k])
else PrintOne(cbStation.Items,cbProfessor.Text);
end else
if cbProfessor.ItemIndex = 0 then
for k:=1 to cbProfessor.Items.Count do
PrintOne(cbStation.Text,cbProfessor.Items[k])
else PrintOne(cbStation.Text,cbProfessor.Text);
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
xlBook : Variant ;
i : integer;
begin
for i:= Excel.Workbooks.Count downto 1 do begin
xlBook := Excel.Workbooks.Item;
if cbFile.Checked then xlBook.Close(True)
else xlBook.Close(False);
end;
Excel.Quit ;
end;

procedure TForm1.BitBtn3Click(Sender: TObject);
begin
Close ;
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
var
xlBook : Variant ;
i : integer ;
begin
if not Ready then Prepare ;
For i := 1 to Excel.Workbooks.Count do begin
xlBook := Excel.Workbooks.Item;
xlBook.PrintOut;
end;
end;

procedure TForm1.BitBtn2Click(Sender: TObject);
begin
if not Ready then prepare ;
Excel.Visible[0] := True ;
end;

end.
 
请继续。。。。
 
var ExcelApp: Variant;
ExcelApp := CreateOleObject( 'Excel.Application' );
ExcelApp.Visible := True;

试试上面的。
 
>>不会吧
什么意思,您试过了没有???
 
你没有创建Excel对象


 
我跟你說用xlReport吧,xlReport可以先做成模板,定義變量。比你寫代碼來的快,人家給你寫好了,
下載4.0的不受限制,不用注冊。
 
xlReport 在哪下载??
 
xlapp你创建了没有???
 
xlReport 在哪下载??
 
xlReport 在哪下载??
 
顶部