找传奇、传世资源到传世资源站!

delphi excel 转 txt

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

【例子介绍】

excel 转 txt

【相关图片】

【源码结构】

unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids;
 
type
  TForm1 = class(TForm)
    Button1: TButton;
    OpenDialog1: TOpenDialog;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
uses Comobj, Clipbrd;
 
procedure TForm1.Button1Click(Sender: TObject);
var
  FExcel: Variant;
  FWorkbook: Variant;
  FWorksheet: Variant;
  slText: TStringList;
begin
  if not OpenDialog1.Execute then
    exit;
 
  Screen.Cursor := crHourGlass;

  try
    FExcel := CreateOleObject('excel.application');
  except
    Screen.cursor := crDefault;
    MessageDlg('Could not start Microsoft Excel!', mtError, [mbCancel], 0);
    Exit;
  end;
 
  try
    FWorkBook := FExcel.WorkBooks.Open(OpenDialog1.Filename);
    //FWorkSheet := FWorkBook.WorkSheets.Add;
    FWorkSheet := FWorkBook.WorkSheets[1];
    FWorkSheet.UsedRange.Copy;
 
 
    slText := TStringList.Create;
    try
      slText.Text := Clipboard.AsText;
      slText.SaveToFile(ChangeFileExt(OpenDialog1.Filename, '.txt'));
    finally
      slText.Free;
    end;
  finally
    Screen.Cursor := crDefault;
    FExcel.DisplayAlerts := False;
    FWorkBook.Close;
    FExcel.Quit;
  end;
end;
 
end.

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复