1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72:
| unit u_ExportEXCEL;
interface uses classes;
type TXLSExport = class(TObject) private fs : TFilestream; public constructor Create(filename : string); destructor Destroy; override; procedure Write(const Col, Row: Word; const Value: Integer); overload; procedure Write(const Col, Row: Word; const Value: Double); overload; procedure Write(const Col, Row: Word; const Value: string); overload; end;
implementation
const CXlsBof : array[0..5] of Word = ($809, 8, 00, $10, 1, 0); CXlsEof : array[0..1] of Word = ($0A, 00); CXlsLabel : array[0..5] of Word = ($204, 0, 0, 0, 0, 0); CXlsNumber : array[0..4] of Word = ($203, 14, 0, 0, 0); CXlsRk : array[0..4] of Word = ($27E, 10, 0, 0, 0);
constructor TXLSExport.Create(filename : string); begin inherited Create; fs := TFileStream.Create(filename,fmCreate); fs.WriteBuffer(CXlsBof, SizeOf(CXlsBof)); end;
destructor TXLSExport.Destroy; begin fs.WriteBuffer(CXlsEof, SizeOf(CXlsEof)); inherited Destroy; end;
procedure TXLSExport.Write(const Col, Row: Word; const Value: Integer); var V: Integer; begin CXlsRk[2] := Row; CXlsRk[3] := Col; fs.WriteBuffer(CXlsRk, SizeOf(CXlsRk)); V := (Value shl 2) or 2; fs.WriteBuffer(V, 4); end;
procedure TXLSExport.Write(const Col, Row: Word; const Value: Double); begin CXlsNumber[2] := Row; CXlsNumber[3] := Col; fs.WriteBuffer(CXlsNumber, SizeOf(CXlsNumber)); fs.WriteBuffer(Value, 8); end;
procedure TXLSExport.Write(const Col, Row: Word; const Value: string); var L: Word; begin L := Length(Value); CXlsLabel[1] := 8 + L; CXlsLabel[2] := Row; CXlsLabel[3] := Col; CXlsLabel[5] := L; fs.WriteBuffer(CXlsLabel, SizeOf(CXlsLabel)); fs.WriteBuffer(Pointer(Value)^, L); end;
end. |