Announcement

Collapse
No announcement yet.

OLE-Excel

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • OLE-Excel

    Ich möchte über mein Programm (Delphi 3)mit Hilfe der OLE- Automatisierung<br>
    eine bestimmte Exceldatei holen,<br>
    dann einen neuen Standarddrucker festlegen und diese Datei drucken.<br>
    Das kann aber alles im Hintergrund passieren.<br>
    Mit Word hab ich das schon gemacht und zwar so:<p>

    <b>Uses</b> comobj;<br>
    <b>var</b> Word: Variant;<p>

    <b>begin</b> {OLE-Verbindung zu Word herstellen}<br>
    <b>try</b><br>
    Word := GetActiveOleObject('Word.Application');<br>
    <b>except</b><br>
    Word := CreateOleObject('Word.Application');<br>
    <b>end</b>;<br>
    Word.Documents.Open(Dateiname);<br>
    Word.Visible := false;<br>
    Word.ActivePrinter := 'Name des Druckers';<br>
    Word.PrintOut;<br>
    Word.Documents.Close;<br>
    Word.Quit;<br>
    <b>end</b>;<p>

    geht auch wunderbar und ich dachte nun mit Excel ist das nichts anderes,<br>
    scheint aber nicht so. Kann mir da jemand helfen?<br>
    Bea

  • #2
    Hallo Beate,

    der Zugriff auf Excelmappen (Workbooks) und Tabellenblätter (Worksheets) funktioniert in Excel analog wie auf Dokumente (Documents) in Word. Am besten Du schaust Dir die Visual Basic - Hilfe (VBAXL8.HLP) zu Excel an, dort sind die Eigenschaften und Methoden der Objekte beschrieben. Über OLE-Automation kannst Du diese genau so ansprechen wie im Makro VB von Excel (zumindest fast).

    Gruß Fal
    Wenn du denkst du hast alle Bugs gefunden, dann ist das ein Bug in deiner Denksoftware.

    Quellcode ohne ein Mindestmaß an Formatierung sehe ich mir nicht an! Ich leiste keinen Privatsupport per Mail oder PN!

    Comment


    • #3
      Danke, hab es jetzt hingekriegt.<br>Nur die Druckerzuweisung ging nicht so wie bei Word.<br>Das hab ich dann anders gelöst und hoffe,<br> es gibt da keine Komplikationen.<br>Sieht fertig und funktionierend also jetzt so aus:<p>

      Excel.Workbooks.add('C:\Test.xls');<br>
      Printer.PrinterIndex:=Printer.Printers.IndexOf('Na me des Druckers');<br>
      Printer.GetPrinter(Device, Driver, Port, hDeviceMode);<br>
      StrCat(Device, ',');<br>
      StrCat(Device, Driver);<br>
      StrCat(Device, ',');<br>
      StrCat(Device, Port);<br>
      WriteProfileString('windows', 'device', Device);<br>
      StrCopy(Device, 'windows');<br>
      SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, Longint(@Device));<br>
      Excel.Workbooks[1].Printout;<br>
      Excel.ActiveWorkBook.Saved := True;<br>
      Excel.Workbooks[1].Close;<br>
      Excel.Quit;<p>

      beim Programm beenden:<p>
      if not VarIsEmpty(Excel)<br>
      then Excel.Quit;<p>
      Vielleicht hilfts noch mal jemandem.<br>
      Be

      Comment

      Working...
      X