type TAtributCell = (acHidden,acLocked,acShaded,acBottomBorder,acTopBorder, acRightBorder,acLeftBorder,acLeft,acCenter,acRight,acFill); TSetOfAtribut = set of TAtributCell;
procedure TjbExport.SaveToStream; begin if Assigned(Table) then with FTable do begin DoBeginWriting; try TotalCount := 0; // write header DoWriteHeader;
Table.First; while not Table.EOF do begin // processing record DoWriteRecord; Inc(TotalCount); Table.Next; end;
procedure TjbExportText.DoWriteHeader; var aFieldDefs : TFieldDefs; i : Integer; s : String; begin inherited; aFieldDefs := FTable.FieldDefs; s := ''; for i := 0 to aFieldDefs.Count -1 do s := s + aFieldDefs.Items[i].Name + Separator; Delete(s, Length(s) - (Length(Separator) -1), Length(Separator)); Writeln(S); Writeln(''); end;
procedure TjbExportText.DoWriteRecord; var s, s1 : String; i : Integer; begin inherited; s := ''; for i := 0 to FTable.FieldDefs.Count -1 do begin S1 := BeginString + FTable.Fields[i].AsString + EndString + FSeparator; S := S + S1; end;
aFieldDefs := FTable.FieldDefs; for i := 0 to aFieldDefs.Count -1 do StringList.Add(' <TD NOWRAP class="Header">' + aFieldDefs.Items[i].Name +'</TD>'); StringList.Add('<TR>'); StringList.Add('');
WriteLn(StringList.Text);
StringList.Free; end;
procedure TjbExportHTML.DoWriteRecord; var s, s1 : String; i : Integer; begin inherited; s := '';
WriteLn(' <TR>'); for i := 0 to FTable.FieldDefs.Count -1 do begin S1 := FTable.Fields[i].AsString; s := ' <TD NOWRAP>'+S1+'</TD>'; WriteLn(s); end; WriteLn(' </TR>'); end;
procedure TjbExportHTML.SetBodyBGColor(const Value: TColor); begin FBodyBGColor := Value; end;
procedure TjbExportHTML.SetBodyFont(const Value: Tfont); begin FBodyFont := Value; end;
procedure TjbExportHTML.SetHeaderBGColor(const Value: TColor); begin FHeaderBGColor := Value; end;
procedure TjbExportHTML.SetHeaderFont(const Value: TFont); begin FHeaderFont := Value; end;
procedure TjbExportHTML.SetShowGrid(const Value: Boolean); begin FShowGrid := Value; end;
procedure TjbExportHTML.WriteLn(S: string); begin S := S + #13#10; Stream.WriteBuffer(Pointer(S)^, Length(S)); end;
{ TjbExportExcel }
function TjbExportExcel.AddCell(vCol, vRow: Word; vAtribut: TSetOfAtribut; CellRef: TCellClass): TCell; var aCell : TCell; begin aCell := CellRef.Create; with aCell do begin Col := vCol-1; Row := vRow-1; Atribut:=vAtribut; end; AddData(aCell); Result := aCell; end;
procedure TjbExportExcel.AddData(aData: TData); begin Dispatcher.RegisterObj(aData); end;
procedure TjbExportExcel.AddDoubleCell(vCol, vRow: Word; vAtribut: TSetOfAtribut; aValue: Double); begin with TDoubleCell(AddCell(vCol, vRow, vAtribut, TDoubleCell)) do Value := aValue; end;
procedure TjbExportExcel.AddStrCell(vCol, vRow: Word; vAtribut: TSetOfAtribut; aValue: String); begin with TStrCell(AddCell(vCol, vRow, vAtribut, TStrCell)) do value := aValue; end;
procedure TjbExportExcel.AddWordCell(vCol, vRow: Word; vAtribut: TSetOfAtribut; aValue: Word); begin with TWordCell(AddCell(vCol, vRow, vAtribut, TWordCell)) do Value := aValue; end;
for i := 0 to aFieldDefs.Count -1 do AddStrCell(i+1, CurrentCol ,SetAtribut, aFieldDefs.Items[i].Name);
inc(CurrentCol); end;
procedure TjbExportExcel.DoWriteRecord; var i : Integer; SetAtribut : TSetOfAtribut; begin inc(CurrentCol); if FShowGrid then SetAtribut :=[acBottomBorder, acTopBorder, acLeftBorder, acRightBorder, acLeft] else SetAtribut :=[];
for i := 0 to FTable.FieldDefs.Count -1 do AddStrCell(i+1, CurrentCol ,SetAtribut, FTable.Fields[i].AsString);
end;
procedure TjbExportExcel.SetShowGrid(const Value: Boolean); begin FShowGrid := Value; end;
{ TjbWriter }
procedure TjbWriter.WriteByte(B: Byte); begin Stream.Write(B , 1); end;
procedure TjbWriter.WriteDouble(D: Double); begin Stream.Write(D, 8); end;
procedure TjbWriter.WriteInt(I: Integer); begin Stream.Write(I, 4); end;
procedure TjbWriter.WriteSingleStr(S: String); begin Stream.Write(S[1], Length(S)); end;
procedure TjbWriter.WriteStr(S: String); {req: s shouldn't exceed 64KB} var Len : Integer; begin Len := Length(S); WriteWord(Len); Stream.Write(s[1],Len); end;
procedure TjbWriter.WriteWord(W: Word); begin Stream.Write(w,2); end;
{ TDispatcher }
procedure TDispatcher.Clear; var I : Integer; begin for i:=0 to StrList.Count-1 do TjbPersistent(StrList.Objects[i]).Free; StrList.Clear; SLError.Clear; end;
procedure TDispatcher.Write; var i : Integer; Pos , Len : Integer; begin for i := 0 to StrList.Count-1 do begin Writer.WriteWord(TjbPersistent(StrList.objects[i]).Opcode); Writer.WriteWord(0); pos := Stream.Position; TjbPersistent(StrList.Objects[i]).Write(Writer);
Len := Stream.Position-Pos; Stream.Seek(-(Len+2),soFromCurrent); Writer.WriteWord(Len); Stream.Seek(Len, soFromCurrent); end;
procedure TDimension.Write(aWriter: TjbWriter); begin with aWriter do begin WriteWord(MinSaveRecs); WriteWord(MaxSaveRecs); WriteWord(MinSaveCols); WriteWord(MaxSaveCols); end; end;
{ TCell }
procedure TCell.SetAtribut(Value: TSetOfAtribut); var i : Integer; begin //reset for i:=0 to High(FAtribut) do FAtribut[i]:=0;
{ Byte Offset Bit Description Contents 0 7 Cell is not hidden 0b Cell is hidden 1b 6 Cell is not locked 0b Cell is locked 1b 5-0 Reserved, must be 0 000000b 1 7-6 Font number (4 possible) 5-0 Cell format code 2 7 Cell is not shaded 0b Cell is shaded 1b 6 Cell has no bottom border 0b Cell has a bottom border 1b 5 Cell has no top border 0b Cell has a top border 1b 4 Cell has no right border 0b Cell has a right border 1b 3 Cell has no left border 0b Cell has a left border 1b 2-0 Cell alignment code general 000b left 001b center 010b right 011b fill 100b Multiplan default align. 111b }
// bit sequence 76543210
if acHidden in Value then //byte 0 bit 7: FAtribut[0] := FAtribut[0] + 128;
if acLocked in Value then //byte 0 bit 6: FAtribut[0] := FAtribut[0] + 64 ;
if acShaded in Value then //byte 2 bit 7: FAtribut[2] := FAtribut[2] + 128;
if acBottomBorder in Value then //byte 2 bit 6 FAtribut[2] := FAtribut[2] + 64 ;
if acTopBorder in Value then //byte 2 bit 5 FAtribut[2] := FAtribut[2] + 32;
if acRightBorder in Value then //byte 2 bit 4 FAtribut[2] := FAtribut[2] + 16;
if acLeftBorder in Value then //byte 2 bit 3 FAtribut[2] := FAtribut[2] + 8;
if acLeft in Value then //byte 2 bit 1 FAtribut[2] := FAtribut[2] + 1 else if acCenter in Value then //byte 2 bit 1 FAtribut[2] := FAtribut[2] + 2 else if acRight in Value then //byte 2, bit 0 dan bit 1 FAtribut[2] := FAtribut[2] + 3; if acFill in Value then //byte 2, bit 0 FAtribut[2] := FAtribut[2] + 4; end;
procedure TCell.Write(aWrite: TjbWriter); var i : Integer; begin with aWrite do begin WriteWord(Row); WriteWord(Col); for i:=0 to 2 do WriteByte(FAtribut[i]); end; end;
{ TBlankCell }
constructor TBlankCell.Create; begin opCode:=1; end;
procedure TBlankCell.Write(aWriter: TjbWriter); begin inherited; end;
{ TDoubleCell }
constructor TDoubleCell.Create; begin opCode:=3; end;
procedure TDoubleCell.Write(aWriter: TjbWriter); begin inherited; aWriter.WriteDouble(Value); end;
{ TWordCell }
constructor TWordCell.Create; begin opCode:=2; end;
procedure TWordCell.Write(aWriter: TjbWriter); begin inherited; aWriter.WriteWord(Value); end;
{ TStrCell }
constructor TStrCell.Create; begin opCode:=4; end;
procedure TStrCell.Write(aWriter: TjbWriter); begin inherited; aWriter.WriteByte(Length(Value)); aWriter.WriteSingleStr(Value); end;
Hmm bruger bare csv filer istedet. Det er lidt mindre indviklet ;) Men tak alligevel.
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.