Q&A

  • 분류먼저 해주시길 부탁드립니다.
DB를 Query해서 Excel로 열려고하는데 WorkBook 2개로는 열리는데

WorkSheet 2개로 열려면 어떻게 해야 하나요???

많은 조언 부탁 드리겠습니다...



procedure TForm1.Button1Click(Sender: TObject);

var V: Variant;

i,j : integer;

begin



screen.cursor := crHourGlass;

try

v:= CreateOleObject('Excel.Application');

except

MessageDlg('Excel이 설치되어 있지 않습니다.', MtWarning, [mbok], 0);

Exit;

End;



// 첫번째 Work Book

v.WorkBooks.add;

v.WorkBooks.ActiveSheet;



table1.DisableControls;

Table1.First;



for i := 0 to Table1.RecordCount do begin

for j := 1 to DBGrid1.FieldCount do begin

if i = 0 then

V.Cells[i+1,j].Value := DBGrid1.Columns.Items[j-1].Title.Caption;

V.Cells[i+2,j].Value := Table1.fields[j-1].AsString;

end;

Table1.Next;

end;

table1.EnableControls;

screen.cursor := crDefault;

V.Visible := True;





// 두번째 Work Book

v.WorkBooks.add;

table2.DisableControls;

Table2.First;



for i := 0 to Table2.RecordCount do begin

for j := 1 to DBGrid2.FieldCount do begin

if i = 0 then

V.Cells[i+1,j].Value := DBGrid2.Columns.Items[j-1].Title.Caption;

V.Cells[i+2,j].Value := Table2.fields[j-1].AsString;

end;

Table2.Next;

end;

table2.EnableControls;

screen.cursor := crDefault;

V.Visible := True;



end;

0  COMMENTS