用一个控件不就解决问题了,请看该控件的使用说明,想要的话mail me:chenyu0745@163.com
===================
TExcel component 3.2
====================
TExcel is a component to produce output tables directly into
MS Excel, including formatting, commands, macro calls, etc.
Demo project is attached to show how easy to drive it.
The demo project creates the component explicitly so it can be
tried without installing the component.
Files:
EXCELS.PAS Component source
EXCELS.INC Include messages
EXCELS.DCR Component resource for Delphi 1.0
EXCELS.D32 Component resource for Delphi 3.0 (rename to DCR)
EXCELDEM.DPR Demo project
EXCELDEM.RES Demo project resource
EXCELTOP.PAS Demo dialog
EXCELTOP.DFM Demo dialog format
EXCEL.XLS Demo Excel macro collection
EXCEL.TXT This file
TExcel is available at the following sites:
(Thanks to Stefan Hoffmeister the sophisticated
version named TAdvExcel is also available there.)
Delphi Super Page
http://sunsite.icm.edu.pl/delphi/
http://www.cdrom.com/pub/delphi_www/
http://ring.aist.go.jp/archives/pc/delphi/
http://ftp.powerup.com.au/webmirror/delphi/
Torry's Delphi Pages
http://carbohyd.siobc.ras.ru/torry/
http://www.deltacom.ru/torry/
http://torry.rimini.com/
http://www.torry.pp.ru/
http://www.snc.ru/~torry/
===================
About Compatibility
===================
Version 3.2 has left some methods and properties which became
unnecessary due to Batch feature (see next section).
Apart from this it is fully compatible to version 3.1 and 3.0.
===================
About Batch Feature
===================
When huge amount of data must be transferred to Excel you can use
the batch methods and properties. These are the following:
procedure BatchStart(FirstRow, FirstCol: Integer);
procedure BatchSend;
procedure BatchCancel;
property Lines : TStrings;
property BatchOn : Boolean;
property BatchMin : Integer;
property BatchMax : Integer;
property FirstRow : Integer;
property LastCol : Integer;
Each BatchStart must be followed by BatchSend or BatchCancel.
After BatchStart the results of PutStr, PutExt, PutInt and
PutDay methods are collected in Lines (TStringList).
When the Lines.Count reaches BatchMax the first BatchMin
lines are transferred to Excel and deleted from Lines,
besides this FirstRow is increased.
It is recommended to process output by rows.
BatchSend transfers all cells collected in Lines and calls
BatchCancel which clears Lines.
WARNING! In Excel the whole bounding rectangle (batch area)
of the referred cells will be replaced.
All not referred cells in the rectangle will be cleared.
FirstRow always shows which Excel row is the first in Lines.
LastCols shows the greatest cell index in the processed lines.
BachOn shows the batch status. When BatchOn is false or you
refer a row less then
FirstRow or column less then
FirstCol
the put methods (PutStr, PutExt, PutInt and PutDay) are
directly executed.
Transfer speed can be increased if Lines are prepared.
The cells must be separated by tab (#9) in each line (see demo).
Further speed increasing can be achieved
if Excel is restored instead of minimized.
RESTRICTIONS! The Excel DDE buffer cannot be larger then
64 KB.
For Delphi 1.0 the length of lines cannot be
longer then
255 character including separators.
(See buffer checking in demo.)
===============================
About Receiving Data from Excel
===============================
Though TExcel is to produce output to Excel sometimes input is
also needed. GetCell retrieves the contents of the specified cell.
When many cells needed it is recommended to use the GetRange method.
GetRange returns the specified area of the current Excel worksheet
in the stringlist given as Lines. Each cell is separated by tab (#9).
RESTRICTIONS are the same as case of batch (see previous section)!
WARNING! When Batch is on, cells in the batch area are NOT AVAILABLE!
==================
Excel DDE commands
==================
To tell the truth I have never seendo
cumentation of Excel DDE
commands but I have found that most of Excel 4.0 macro instructions
work as DDE commands. So all you have todo
make a macro using the
desired instruction in Excel 4.0 format and use it as DDE command.
(With Excel 5.0 and 7.0 you can record macro in 4.0 format.)
The demo project shows some samples in the "Command" combo box.
=================================================================
Instead ofdo
cumentation here are some words about the interface.
=================================================================
procedure Connect;
To connect Excel.
procedure Disconnect;
To disconnect Excel.
procedure Wait;
To wait for Excel to be ready.
Needed when more thousands commands are executed in a loop.
procedure ProcessMessages;
To permit Windows to process (Excel) messages.
function Request(const Item: string): string;
To request for a DDE item.
Use "SysItems" to get the available items.
procedure Exec(const Cmd : string);
To execute Excel commands. See section "Excel DDE Commands".
procedure Run(const Mn: string);
To execute a macro of the open macro file.
procedure Select(Row, Col: Integer);
To select a cell of the active Excel sheet.
procedure PutStr(Row, Col: Integer;
const s: string);
To replace the cell with string.
procedure PutExt(Row, Col: Integer;
e: Extended);
virtual;
To replace the cell with real number.
procedure PutInt(Row, Col: Integer;
i: Longint);
virtual;
To replace the cell with integer.
procedure PutDay(Row, Col: Integer;
d: TDateTime);
virtual;
To replace the cell with date value.
procedure BatchStart;
To start processing. See section "About Batch...".
procedure BatchCancel;
To cancel batch processing. See section "About Batch...".
procedure BatchSend;
To finish batch processing. See section "About Batch...".
procedure GetRange(R: TRect;
Lines: TStrings);
To receive many data from Excel. See section "About Receive...".
function GetCell(Row, Col: Integer): string;
To get the cell contents. See section "About Receive...".
procedure OpenMacroFile(const Fn: TFileName;
Hide: Boolean);
To specify a macro file.
Needed only when macros are going to call.
procedure CloseMacroFile;
To close an opened macro file.
Only one macro file can be opened at the same time.
property DDE: TDdeCLientConv;
To handle DDE directly. (Read only)
Normally not needed.
property Connected: Boolean;
To check connection.
property Ready: Boolean;
To check Excel status. (Read only)
property Selection: string;
To get current selection. (Read only)
property Lines : TStrings;
To handle batch strings directly. See section "About Batch...".
property FirstRow : Integer;
To check batch area. (Read only) See section "About Batch...".
property LastCol : Integer;
To check or set batch area. See section "About Batch...".
property BatchOn : Boolean;
To check batch status. (Read only) See section "About Batch...".
property ExeName: TFileName;
To set Excel path. If it is not set before connection
it will be set due to Windows Registry.
property Decimals: Integer;
To specify number format for real numbers.
property BatchMin : Integer;
To calibrate batch processing. See section "About Batch...".
property BatchMax : Integer;
To calibrate batch processing. See section "About Batch...".
property OnClose: TNotifyEvent;
Event handler called when Excel is connected.
property OnOpen: TNotifyEvent;
Event handler called when Excel is disconnected.
--------------------------------------
--------------------------------------
TExcel is provided free of charge as so long as
it is not in commercial use. When it produces
income for you, please send me some portion of
your income (at least $50). Thank you.