Q
QSmile
Unregistered / Unconfirmed
GUEST, unregistred user!
unit ExcelExport;
// Author: RedFox
// E-mail: singlecat@163.com
interface
uses Classes;
type
TExcelExport = class
public
procedure WriteBegin(f:TStream);
procedure WriteEnd(f:TStream);
procedure WriteStringCell(f:TStream; ACol,ARow:Integer;Value:string);
procedure WriteIntegerCell(f:TStream; ACol,ARow:Integer;Value:Integer);
procedure WriteFloatCell(f:TStream; ACol,ARow:Integer;Value:double);
end;
implementation
var
arXlsBegin : array[0..5] of Word = ($809, 8, 0, $10, 0, 0);
arXlsEnd : array[0..1] of Word = ($0A, 00);
arXlsString : array[0..5] of Word = ($204, 0, 0, 0, 0, 0);
arXlsNumber : array[0..4] of Word = ($203, 14, 0, 0, 0);
arXlsInteger : array[0..4] of Word = ($27E, 10, 0, 0, 0);
arXlsBlank : array[0..4] of Word = ($201, 6, 0, 0, $17);
{ TExcelExport }
procedure TExcelExport.WriteBegin(f: TStream);
begin
f.WriteBuffer(arXlsBegin, SizeOf(arXlsBegin));
end;
procedure TExcelExport.WriteEnd(f: TStream);
begin
f.WriteBuffer(arXlsEnd, SizeOf(arXlsEnd));
end;
procedure TExcelExport.WriteFloatCell(f: TStream; ACol, ARow: Integer;
Value: double);
begin
arXlsNumber[2] := ARow;
arXlsNumber[3] := ACol;
f.WriteBuffer(arXlsNumber, SizeOf(arXlsNumber));
f.WriteBuffer(Value, 8);
end;
procedure TExcelExport.WriteIntegerCell(f: TStream; ACol, ARow,
Value: Integer);
var
V: Integer;
begin
arXlsInteger[2] := ARow;
arXlsInteger[3] := ACol;
f.WriteBuffer(arXlsInteger, SizeOf(arXlsInteger));
V := (Value shl 2) or 2;
f.WriteBuffer(V, 4);
end;
procedure TExcelExport.WriteStringCell(f: TStream; ACol, ARow: Integer;
Value: string);
var
L: Word;
begin
L := Length(Value);
arXlsString[1] := 8 + L;
arXlsString[2] := ARow;
arXlsString[3] := ACol;
arXlsString[5] := L;
f.WriteBuffer(arXlsString, SizeOf(arXlsString));
f.WriteBuffer(Pointer(Value)^, L);
end;
end.
// Author: RedFox
// E-mail: singlecat@163.com
interface
uses Classes;
type
TExcelExport = class
public
procedure WriteBegin(f:TStream);
procedure WriteEnd(f:TStream);
procedure WriteStringCell(f:TStream; ACol,ARow:Integer;Value:string);
procedure WriteIntegerCell(f:TStream; ACol,ARow:Integer;Value:Integer);
procedure WriteFloatCell(f:TStream; ACol,ARow:Integer;Value:double);
end;
implementation
var
arXlsBegin : array[0..5] of Word = ($809, 8, 0, $10, 0, 0);
arXlsEnd : array[0..1] of Word = ($0A, 00);
arXlsString : array[0..5] of Word = ($204, 0, 0, 0, 0, 0);
arXlsNumber : array[0..4] of Word = ($203, 14, 0, 0, 0);
arXlsInteger : array[0..4] of Word = ($27E, 10, 0, 0, 0);
arXlsBlank : array[0..4] of Word = ($201, 6, 0, 0, $17);
{ TExcelExport }
procedure TExcelExport.WriteBegin(f: TStream);
begin
f.WriteBuffer(arXlsBegin, SizeOf(arXlsBegin));
end;
procedure TExcelExport.WriteEnd(f: TStream);
begin
f.WriteBuffer(arXlsEnd, SizeOf(arXlsEnd));
end;
procedure TExcelExport.WriteFloatCell(f: TStream; ACol, ARow: Integer;
Value: double);
begin
arXlsNumber[2] := ARow;
arXlsNumber[3] := ACol;
f.WriteBuffer(arXlsNumber, SizeOf(arXlsNumber));
f.WriteBuffer(Value, 8);
end;
procedure TExcelExport.WriteIntegerCell(f: TStream; ACol, ARow,
Value: Integer);
var
V: Integer;
begin
arXlsInteger[2] := ARow;
arXlsInteger[3] := ACol;
f.WriteBuffer(arXlsInteger, SizeOf(arXlsInteger));
V := (Value shl 2) or 2;
f.WriteBuffer(V, 4);
end;
procedure TExcelExport.WriteStringCell(f: TStream; ACol, ARow: Integer;
Value: string);
var
L: Word;
begin
L := Length(Value);
arXlsString[1] := 8 + L;
arXlsString[2] := ARow;
arXlsString[3] := ACol;
arXlsString[5] := L;
f.WriteBuffer(arXlsString, SizeOf(arXlsString));
f.WriteBuffer(Pointer(Value)^, L);
end;
end.