我需要用excel出报表,怎么操作啊
给你一段代码看看:
unit Unit_ExcelReport;
interface
uses
SysUtils, Windows, Messages, Classes, Graphics, Controls,
Forms, Dialogs, ComObj, Variants, Math, DB, ADODB, DateUtils, StrUtils;
const ErrFileNoExists = 报表模板文件 "%s" 不存在!;
type
TReportProgressEvent = procedure (Sender: TObject; Position, Max: Integer)
of Object;
TMDReportProgressEvent = procedure (Sender: TObject; MPos, MMax,
Pos, Max: Integer) of Object;
TStatuChangeEvent = procedure (Sender: TObject; Statu: String) of Object;
TNo21Total = Record
LMAmount, MinAm, MOutAm, MAmOut: Double;
LMMoney, MInMoney, MOutMoney, MMoney: Double;
end;
TCurreAmt = Record
CURRE: String;
Amount, RMBAmount, TaxAmount: Double;
end;
type
TExcelReport = class (TObject)
private
FBeginRow: Integer;
FCurrentSheet: Variant;
FDPageCount: Integer;
FDPageRecordCount: Integer;
FDPageTotal: Integer;
FDRecordCount: Integer;
FDRecordTotal: Integer;
FDRowCount: Integer;
FDRowCountPerRecord: Integer;
FExcelApp: Variant;
FOnStatusChange: TStatuChangeEvent;
FPageBeginCol: Integer;
FPageCount: Integer;
FPageEndCol: Integer;
FPageRecordCount: Integer;
FPageRowCount: Integer;
FPageTotal: Integer;
FPatternSheet: Variant;
FPosition: Integer;
FRecordCount: Integer;
FRecordTotal: Integer;
FReportSheet: Variant;
FReportWorkBook: Variant;
FRowCount: Integer;
FRowCountPerRecord: Integer;
FTempletFileName: string;
FTempletWorkbook: Variant;
function GetActiveSheet: Variant;
function GetActiveWorkBook: Variant;
function GetCells: Variant;
function GetWorkBooks: Variant;
procedure SetVisible(Value: Boolean);
public
NewPageCount:Integer;
constructor Create(TempletFileName: String); reintroduce;
destructor Destroy; override;
procedure InitReportWorkBook;
procedure NewPage; virtual;
procedure NewReportSheet; virtual;
procedure OpenPatternFile;
procedure PrintOut; virtual;
procedure SaveAs(AFileName: string);
procedure SetBorders(Range: String);
procedure SetCellsValue(ARow, ACol: Integer; Value: Variant);
property ActiveSheet: Variant read GetActiveSheet;
property ActiveWorkBook: Variant read GetActiveWorkBook;
property BeginRow: Integer read FBeginRow write FBeginRow;
property Cells: Variant read GetCells;
property DPageCount: Integer read FDPageCount write FDPageCount;
property DPageRecordCount: Integer read FDPageRecordCount write
FDPageRecordCount;
property DPageTotal: Integer read FDPageTotal write FDPageTotal;
property DRecordCount: Integer read FDRecordCount write FDRecordCount;
property DRecordTotal: Integer read FDRecordTotal write FDRecordTotal;
property DRowCount: Integer read FDRowCount write FDRowCount;
property DRowCountPerRecord: Integer read FDRowCountPerRecord write
FDRowCountPerRecord;
property ExcelApp: Variant read FExcelApp;
property PageBeginCol: Integer read FPageBeginCol write FPageBeginCol;
property PageCount: Integer read FPageCount;
property PageEndCol: Integer read FPageEndCol write FPageEndCol;
property PageRecordCount: Integer read FPageRecordCount write
FPageRecordCount;
property PageRowCount: Integer read FPageRowCount write FPageRowCount;
property PageTotal: Integer read FPageTotal write FPageTotal;
property PatternSheet: Variant read FPatternSheet;
property Position: Integer read FPosition write FPosition;
property RecordCount: Integer read FRecordCount write FRecordCount;
property RecordTotal: Integer read FRecordTotal write FRecordTotal;
property ReportSheet: Variant read FReportSheet;
property ReportWorkBook: Variant read FReportWorkBook;
property RowCount: Integer read FRowCount;
property RowCountPerRecord: Integer read FRowCountPerRecord write
FRowCountPerRecord;
property TempletWorkbook: Variant read FTempletWorkbook;
property Visible: Boolean write SetVisible;
property WorkBooks: Variant read GetWorkBooks;
published
property OnStatusChange: TStatuChangeEvent read FOnStatusChange write
FOnStatusChange;
end;
function PatternPath: string;
function TPXDateToStrDate(TpxDate: String; DateFmt: String=YYYY"-"MM"-"DD):
TDateTime;
function FormatDate(Date: TDate; Fmt:String=YYYY"-"MM"-"DD): string;
function FormatQty(Qty: Real; Fmt: String = #,####.00): string;
function FormatCurr(Curr: Real; Fmt: String=#,###.00): string;
function nString(n: Integer; Str: String=0): string;
function StrToCode39Str(Str: String): string;
function MyDateToInt(DateStr:String):String;
function SetMonth(Month:Integer):String;
function SetDay(Day:Integer):String ;
procedure EnterToTab(TheForm: TForm; var Key: Char);