📄 rm_e_csv.pas
字号:
{*****************************************}
{ }
{ Report Machine v1.0 }
{ CSV export filter }
{ }
{*****************************************}
unit RM_e_csv;
interface
{$I RM.inc}
uses
SysUtils, Windows, Messages, Classes, Graphics, Forms, StdCtrls,
RM_Class, RM_E_TXT, Controls;
type
TRMCSVExport = class(TRMTextExport)
private
FDelimiter: Char;
public
constructor Create(AOwner: TComponent); override;
function ShowModal: Word; override;
procedure OnEndPage; override;
published
property Delimiter: Char read FDelimiter write FDelimiter;
end;
{ TRMCSVExportForm }
TRMCSVExportForm = class(TForm)
GroupBox1: TGroupBox;
CB1: TCheckBox;
CB2: TCheckBox;
Label1: TLabel;
E1: TEdit;
btnOK: TButton;
btnCancel: TButton;
Label2: TLabel;
Label3: TLabel;
E2: TEdit;
Label4: TLabel;
E3: TEdit;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
procedure Localize;
public
{ Public declarations }
end;
implementation
uses RM_CmpReg, RM_Const, RM_Utils;
{$R *.DFM}
{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
{TRMCSVExport}
constructor TRMCSVExport.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
RMRegisterExportFilter(Self, RMLoadStr(SCSVFile) + ' (*.csv)', '*.csv');
ShowDialog := True;
ScaleX := 1;
ScaleY := 1;
KillEmptyLines := True;
ConvertToOEM := False;
Delimiter := ';';
end;
function TRMCSVExport.ShowModal: Word;
begin
if not ShowDialog then
Result := mrOk
else with TRMCSVExportForm.Create(nil) do
begin
CB1.Checked := KillEmptyLines;
CB2.Checked := ConvertToOEM;
E1.Text := FloatToStr(ScaleX);
E2.Text := FloatToStr(ScaleY);
E3.Text := Delimiter;
Result := ShowModal;
try
ScaleX := RMStrToFloat(E1.Text);
except
ScaleX := 1;
end;
try
ScaleY := RMStrToFloat(E2.Text);
except
ScaleY := 1;
end;
FKillEmptyLines := CB1.Checked;
ConvertToOEM := CB2.Checked;
if (E3.Text <> '') and (E3.Text <> '"') then
Delimiter := E3.Text[1];
Free;
end;
end;
procedure TRMCSVExport.OnEndPage;
var
i, j, n, tc1, tc2: Integer;
p: PRMTextRec;
s: String;
cl: TStringList; //waw Added
begin
cl := TStringList.Create; //waw Added
n := Lines.Count - 1;
while n >= 0 do
begin
if Lines[n] <> nil then break;
Dec(n);
end;
//{ //waw Added
s := '';
p := nil;
for i := 0 to n do
begin
p := PRMTextRec(Lines[i]);
if p <> nil then break;
end;
while p <> nil do
begin
cl.Add(IntToStr(p^.DrawRect.left));
// s := s + Delimiter;
// if Pos(Delimiter, p^.Text) <> 0 then s := s + '"' + p^.Text + '"'
// else s := s + p^.Text;
s := s + Delimiter;
s := s + '"' + p^.Text + '"';
p := p^.Next;
end;
if not FKillEmptyLines or (s <> '') then
begin
if ConvertToOEM then CharToOEMBuff(@s[1], @s[1], Length(s));
s := s + #13#10;
Stream.Write(s[1], Length(s));
end;
//} //waw
// for i := 0 to n do //waw
for i := i +1 to n do //waw
begin
s := '';
tc1 := 0;
p := PRMTextRec(Lines[i]);
while p <> nil do
begin
// tc2 := Round(p^.X / (64 / ScaleX)); //waw
//{ //waw Added
j := cl.Indexof(IntToStr(p^.DrawRect.left));
if j = -1 then tc2 := tc1 + 1
else tc2 := j + 1;
//} //waw Added
for j := 0 to tc2 - tc1 -1 do s := s + Delimiter;
// if Pos(Delimiter, p^.Text) <> 0 then s := s + '"' + p^.Text + '"'
// else s := s + p^.Text;
s := s + '"' + p^.Text + '"';
tc1 := tc2;
p := p^.Next;
end;
if not FKillEmptyLines or (s <> '') then
begin
if ConvertToOEM then CharToOEMBuff(@s[1], @s[1], Length(s));
s := s + #13#10;
Stream.Write(s[1], Length(s));
end;
end;
cl.Free; //waw Added
end;
{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
procedure TRMCSVExportForm.Localize;
begin
Font.Name := RMLoadStr(SRMDefaultFontName);
Font.Size := StrToInt(RMLoadStr(SRMDefaultFontSize));
Font.Charset := StrToInt(RMLoadStr(SCharset));
RMSetStrProp(Self, 'Caption', rmRes + 1810);
RMSetStrProp(CB1, 'Caption', rmRes + 1801);
RMSetStrProp(CB2, 'Caption', rmRes + 1802);
RMSetStrProp(Label1, 'Caption', rmRes + 1806);
RMSetStrProp(Label4, 'Caption', rmRes + 1811);
btnOK.Caption := RMLoadStr(SOk);
btnCancel.Caption := RMLoadStr(SCancel);
end;
procedure TRMCSVExportForm.FormCreate(Sender: TObject);
begin
Localize;
end;
initialization
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -