...print an Excel file?

Author: Thomas Stutz

Category: Objects/ActiveX

{
  This is a simple example how to print an Excel file using OLE.
}

{
  Dies ist ein einfaches Beispiel, um eine Excel Datei über OLE im Hintergrund
  auszudrucken.
}

uses
  
ComObj;

procedure TForm1.Button1Click(Sender: TObject);
var
  
ExcelApp: OLEVariant;
begin
  
// Create an Excel instance
  // Excel Instanz erzeugen
  
ExcelApp := CreateOleObject('Excel.Application');
  try
    
ExcelApp.Workbooks.Open('C:\test\xyz.xls');
    // you can also modify some settings from PageSetup
    // Man kann auch noch einige Einstellungen von "Seite Einrichten" anpassen
    
ExcelApp.ActiveSheet.PageSetup.Orientation := xlLandscape;
    // Print it out
    // Ausdrucken
    
ExcelApp.Worksheets.PrintOut;
  finally
    
// Close Excel
    // Excel wieder schliessen
    
if not VarIsEmpty(ExcelApp) then
    begin
      
ExcelApp.Quit;
      ExcelApp := Unassigned;
    end;
  end;
end;

 

printed from
www.swissdelphicenter.ch
developers knowledge base