Here is what I use to access an excel spreadsheet:
procedure TMainForm.BtnCreateWkshtClick(Sender: TObject);
Var
Excel : Variant;
I, J, K, X, Y : Integer;
ContinueFlag : Boolean;
Str : String; //For testing only
begin
X := 1;
ContinueFlag := True;
try
Excel := CreateOleObject('Excel.Application');
except
ShowMessage('Excel could not initialize !');
ContinueFlag := False;
end;
If ContinueFlag = True then
Begin
//Open Doc
Excel.Workbooks.open('O:\Releasemanagement\Site logs\PilotList.Xls');
Excel.Cells[1,1] := 'SiteID'; //Load heading Row
Excel.Cells[1,2] := 'Domain';
Excel.Cells[1,3] := 'State';
Excel.Cells[1,4] := 'Contact';
Excel.Cells[1,5] := 'Phone No.';
Excel.Cells[1,6] := 'Installed?';
Excel.Cells[1,7] := 'Ticket No.';
Excel.Cells[1,8] := 'Description';
For I := 1 to LBxSelected.Items.Count - 1 do
Begin
X := X + 1;
Y := 1;
// Site ID Cell Entry -------------------------------------
J := Pos(',',LBxSelected.Items[I]);
Str := Copy(LBxSelected.Items[I],0,J-1);
Excel.Cells[X,Y] := Copy(LBxSelected.Items[I],0,J-1);
// Domain Cell Entry -------------------------------------
Y := Y + 1;
K := J + 1;
J :=
Pos(',',Copy(LBxSelected.Items[I],K,Length(LBxSelected.Items[I])-1));
Str := Copy(LBxSelected.Items[I],K,J-1);
Excel.Cells[X,Y] := Copy(LBxSelected.Items[I],K,J-1);
// State Cell entry --------------------------------------
Y := Y + 1;
K := K + J + 1;
J :=
Pos(',',Copy(LBxSelected.Items[I],K,Length(LBxSelected.Items[I])-1));
Str := Copy(LBxSelected.Items[I],K,J-1);
Excel.Cells[X,Y] := Copy(LBxSelected.Items[I],K,J-1);
// Contact Cell Entry -----------------------------------
Y := Y + 1;
K := K + J ;
J :=
Pos(',',Copy(LBxSelected.Items[I],K,Length(LBxSelected.Items[I])-1));
Str := Copy(LBxSelected.Items[I],K,J-1);
Excel.Cells[X,Y] := Copy(LBxSelected.Items[I],K,J-1);
// Phone No. Cell Entry ----------------------------------
Y := Y + 1;
K := K + J ;
Str := Copy(LBxSelected.Items[I],K,Length(LBxSelected.Items[I]));
Excel.Cells[X,Y] :=
Copy(LBxSelected.Items[I],K,Length(LBxSelected.Items[I]));
end;
Excel.Workbooks.Close; //Close worksheet. You will see a prompt to
save.
end;
end;
******************** End of Code *********************************
Look at Debra Pate's OLE Automation website for more sample code and
tutorials.
http://www.djpate.freeserve.co.uk/Automation.htm
Tom Nesler
Live long!... Code Well!... and Prosper!... V
-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Jonathan Taylor
Sent: Wednesday, March 22, 2006 8:37 AM
To: [email protected]
Subject: RE: [delphi-en] Accessing cells in Excel file
Have you tried ARExcelReport
(http://www.vector-ski.com/reports/arexcelreport_index.htm), allows you
to
write a code generated report using a .xls workbook as a 'template' with
<#tags> that are filled with vars or direct from data sets.
_____
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf
Of Dawood Nisha
Sent: 22 March 2006 11:23 AM
To: [email protected]
Subject: [delphi-en] Accessing cells in Excel file
Hi
I have a Report format in excel file. Please help me how to access a
particular cell and update the text in that cell thru delphi. Iam using
Delphi 7.
regards
nisha
-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: [EMAIL PROTECTED]
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/delphi-en/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/