BillKilgore
Programmer
Hello,
I've been trying to develop a Delphi 7 app that will read data from a
text or csv file, perform some basic functions, load it into an array,
and append the array contents below the current last row in an existing
Excel (XLS) file.
The pace is slow as documentation is somewhat sketchy so it's strictly
cut and paste, trial and error.
As it stands now, the code as shown will compile but if I try run it I get
the error message,
Project AccessingXL raised exception class EClassNotFound with message,
"class TExcelWorkbook Not Found."
When I remove the comment slashes from 'TExcelWorkbook' and 'TExcelWorkSheet'
under 'type' the compiler rejects with the message,
"Incompatible types: ' TExcelWorkbook' and '_Workbook'" and the same for TExcelWorksheet.
I think my problem is that I'm getting examples from different versions of Delphi, possibly 3 through 5.
I'm using 7 Professional and there is, of course, nothing in "help" or in my copy of Excel 2000, that I can determine. It seems like parts of some examples conflict with parts of others.
I've gotten most of my examples here, from the Dorothy Pate site, and numerous other sites as well. The LCID reference in 'var' is from a previous try and other than 1033 for the US I have no idea what it's here for.
In the interest of brevity I've included what I take to be the pertinent code. I think I get the Range stuff all right though I may need a hint on finding the last row.
I've included code from the unit declaration down for clarity. Thank you very much for sticking with me this far. Any help would be greatly appreciated.
Thank you, Bill Kilgore
UNIT TryAccessingXL;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Excel2000, OleServer, StdCtrls, ComObj,
AccessExcelSpecific; //Unit for basic Functions and Procedures unique to this application.
type
TAccess_Excel = class(TForm)
MyXLApplication: TExcelApplication;
// MyXLWorkbook: TExcelWorkbook;
// MyXLWorksheet: TExcelWorksheet;
btnOpenXL: TButton;
btnCloseXL: TButton;
procedure OpenXLFile(Sender: TObject);
procedure btnOpenTickersClick(Sender: TObject);
procedure btnReadCloseClick(Sender: TObject);
procedure CloseProgram(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
LCID,Rowe,Colmn : integer;
ticker_symbol, close_data, close_price, close_date, close_volume : string;
Access_Excel: TAccess_Excel;
ATryoutFile : TextFile;
MyXLWorkbook,MyXLWorksheet,RawData : OleVariant;
ArrayOfClose,SortedArrayOfClose : variant;
implementation
{$R *.dfm}
procedure TAccess_Excel.OpenXLFile(Sender: TObject);
Begin
MyXLApplication.Connect;
MyXLWorkbook.ConnectTo(MyXLApplication.ActiveWorkbook);
MyXLWorksheet.ConnectTo(MyXLApplication.ActiveSheet as _Worksheet);
MyXLWorksheet.ConnectTo(MyXLApplication.Worksheets.Item['RawData'] as _Worksheet);
MyXLWorkbook := MyXLApplication.Workbooks.Open('C:\AccessingXL\8.5 TEST TryOut.xls',
EmptyParam,EmptyParam,EmptyParam,
EmptyParam, EmptyParam,EmptyParam,
EmptyParam,EmptyParam,EmptyParam,
EmptyParam,EmptyParam,EmptyParam,0);
MyXLWorksheet := MyXLWorkbook.Worksheets.Item['RawData'];
MyXLWorksheet.Activate;
MyXLWorksheet.Cells.SpecialCells(xlCellTypeLastCell,EmptyParam).Activate;
// Get last row value
Rowe := MyXLApplication.ActiveCell.Row;
// Get rightmost column value
Colmn := MyXLApplication.ActiveCell.Column;
End; //procedure TAccess_Excel.OpenXLFile
.
.
.
.
END.
I've been trying to develop a Delphi 7 app that will read data from a
text or csv file, perform some basic functions, load it into an array,
and append the array contents below the current last row in an existing
Excel (XLS) file.
The pace is slow as documentation is somewhat sketchy so it's strictly
cut and paste, trial and error.
As it stands now, the code as shown will compile but if I try run it I get
the error message,
Project AccessingXL raised exception class EClassNotFound with message,
"class TExcelWorkbook Not Found."
When I remove the comment slashes from 'TExcelWorkbook' and 'TExcelWorkSheet'
under 'type' the compiler rejects with the message,
"Incompatible types: ' TExcelWorkbook' and '_Workbook'" and the same for TExcelWorksheet.
I think my problem is that I'm getting examples from different versions of Delphi, possibly 3 through 5.
I'm using 7 Professional and there is, of course, nothing in "help" or in my copy of Excel 2000, that I can determine. It seems like parts of some examples conflict with parts of others.
I've gotten most of my examples here, from the Dorothy Pate site, and numerous other sites as well. The LCID reference in 'var' is from a previous try and other than 1033 for the US I have no idea what it's here for.
In the interest of brevity I've included what I take to be the pertinent code. I think I get the Range stuff all right though I may need a hint on finding the last row.
I've included code from the unit declaration down for clarity. Thank you very much for sticking with me this far. Any help would be greatly appreciated.
Thank you, Bill Kilgore
UNIT TryAccessingXL;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Excel2000, OleServer, StdCtrls, ComObj,
AccessExcelSpecific; //Unit for basic Functions and Procedures unique to this application.
type
TAccess_Excel = class(TForm)
MyXLApplication: TExcelApplication;
// MyXLWorkbook: TExcelWorkbook;
// MyXLWorksheet: TExcelWorksheet;
btnOpenXL: TButton;
btnCloseXL: TButton;
procedure OpenXLFile(Sender: TObject);
procedure btnOpenTickersClick(Sender: TObject);
procedure btnReadCloseClick(Sender: TObject);
procedure CloseProgram(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
LCID,Rowe,Colmn : integer;
ticker_symbol, close_data, close_price, close_date, close_volume : string;
Access_Excel: TAccess_Excel;
ATryoutFile : TextFile;
MyXLWorkbook,MyXLWorksheet,RawData : OleVariant;
ArrayOfClose,SortedArrayOfClose : variant;
implementation
{$R *.dfm}
procedure TAccess_Excel.OpenXLFile(Sender: TObject);
Begin
MyXLApplication.Connect;
MyXLWorkbook.ConnectTo(MyXLApplication.ActiveWorkbook);
MyXLWorksheet.ConnectTo(MyXLApplication.ActiveSheet as _Worksheet);
MyXLWorksheet.ConnectTo(MyXLApplication.Worksheets.Item['RawData'] as _Worksheet);
MyXLWorkbook := MyXLApplication.Workbooks.Open('C:\AccessingXL\8.5 TEST TryOut.xls',
EmptyParam,EmptyParam,EmptyParam,
EmptyParam, EmptyParam,EmptyParam,
EmptyParam,EmptyParam,EmptyParam,
EmptyParam,EmptyParam,EmptyParam,0);
MyXLWorksheet := MyXLWorkbook.Worksheets.Item['RawData'];
MyXLWorksheet.Activate;
MyXLWorksheet.Cells.SpecialCells(xlCellTypeLastCell,EmptyParam).Activate;
// Get last row value
Rowe := MyXLApplication.ActiveCell.Row;
// Get rightmost column value
Colmn := MyXLApplication.ActiveCell.Column;
End; //procedure TAccess_Excel.OpenXLFile
.
.
.
.
END.