⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rm_e_csv.pas

📁 report machine 2.3 功能强大
💻 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 <> '' then
      Delimiter := E3.Text[1];
    Free;
  end;
end;

procedure TRMCSVExport.OnEndPage;
var
  i, j, n, tc1, tc2: Integer;
  p: PRMTextRec;
  s: String;
begin
  n := Lines.Count - 1;
  while n >= 0 do
  begin
    if Lines[n] <> nil then break;
    Dec(n);
  end;

  for i := 0 to n do
  begin
    s := '';
    tc1 := 0;
    p := PRMTextRec(Lines[i]);
    while p <> nil do
    begin
      tc2 := Round(p^.X / (64 / ScaleX));
      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;
      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;
end;

{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}

procedure TRMCSVExportForm.Localize;
begin
	Font.Name := RMLoadStr(SRMDefaultFontName);
  Font.Size := StrToInt(RMLoadStr(SRMDefaultFontSize));
  Font.Charset := StrToInt(RMLoadStr(SCharset));

  Caption := RMLoadStr(rmRes + 1810);
  CB1.Caption := RMLoadStr(rmRes + 1801);
  CB2.Caption := RMLoadStr(rmRes + 1802);
  Label1.Caption := RMLoadStr(rmRes + 1806);
  Label4.Caption := RMLoadStr(rmRes + 1811);
  btnCancel.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 + -