...save a Excel file as Text file?

Author: Thomas Stutz

Category: Objects/ActiveX

uses
  
ComObj;

function ExcelSaveAsText(ExcelFile, TextFile: TFileName): Boolean;
const
  
xlText = -4158;
var
  
ExcelApp: OleVariant;
  vTemp1, vTemp2, vTemp3: OLEVariant;
begin
  
Result := False;
  try
    
ExcelApp := CreateOleObject('Excel.Application');
  except
    
// Fehler beim öffnen von Excel...
    // Error occured...
    
Exit;
  end;
  try
    
ExcelApp.Workbooks.Open(ExcelFile);
    ExcelApp.DisplayAlerts := False;
    vTemp3 := False;
    vTemp2 := xlText;
    vTemp1 := TextFile;
    ExcelApp.ActiveWorkbook.SaveAs(vTemp1, vTemp2, vTemp3);
    Result := True;
  finally
    
ExcelApp.Quit;
    ExcelApp := Unassigned;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  
ExcelSaveAsText('C:\YouExcelFile.xls','C:\YourTextFile.txt');
end;

 

printed from
www.swissdelphicenter.ch
developers knowledge base