ich probiere im Moment etwas mit ActiveX rum. Geärgert hat mich immer, dass ein Übertrag einer relativ kleinen DBF-Datei in ein bestehendes Excel-Sheet so lange dauert. Ich wollte aber auch nicht aus der Excel-Anwendung auf die DBF zugreifen.
Mit dem kleinen Trick über die Zwischenablage geht das richtig fix. Naja, vielleicht nix Neues für die meisten Profis hier. Ich war jedenfalls froh, das ich es herausgefunden habe.
Wer's also brauchen kann oder wissen will...
Code: Alles auswählen
*****************************************************************************
*
* Ausgabe der Ergebnis.dbf in eine Excel-Tabelle
*
*****************************************************************************
#include "Appevent.ch"
#include "Gra.ch"
#include "Xbp.ch"
#include "std.ch"
#include "common.ch"
#include "topdown.ch"
#include "Xbpdev.ch"
#include "dmlb.ch"
#include "activex.ch"
#include "excel.ch"
//////////////////////////////////////////////////////////////////////
// Main entry point of the application
//////////////////////////////////////////////////////////////////////
Function ProFi
LOCAL oExcel, oBook, oSheet
LOCAL cUebergabe:="", oClipboard
oDlg2 := tdModal(7,34,,,20,,,.T.)
oDlg2:title := "ProFi-Bericht erstellen..."
oDlg2:create()
oDlg2:setModalState(XBP_DISP_APPMODAL)
oDa2 := oDlg2:drawingarea
tdSay(1.5,2,'Ergebnisdaten nach ProFiErg.xls exportieren ...',oDa2,35,'c',,'10.Arial')
oProgBar1:=tdProgBar(2.5,2,oDa2,32,,tdRED)
use ergebnis new exclusive
// Create the "Excel.Application" object
oExcel := CreateObject("Excel.Application")
IF Empty( oExcel )
tdMsg("Excel ist nicht installiert!" )
RETURN NIL
ENDIF
// Avoid message boxes such as "File already exists". Also,
// ensure the Excel application is visible.
oExcel:DisplayAlerts := .F.
* oExcel:visible := .T. // soll im Hintergrund erfolgen
// Add a workbook to the Excel application. Query for
// the active sheet (sheet-1) and set up page/paper
// orientation.
oBook := oExcel:workbooks:Open(cDataPath+"\ProFiErg.xls")
oSheet := oBook:Worksheets(3)
oSheet:Activate
// Feed in the data from the table to the Cells
// of the sheet.
do while nr<1000 .and. !eof()
cUebergabe+=' '+ergebnis->bezei+chr(9)
cUebergabe+=tdFixUp(ergebnis->gesamt,15,"",",",2)+chr(9)
cUebergabe+=tdFixUp(ergebnis->summe,15,"",",",2)+chr(9)
cUebergabe+=tdFixUp(ergebnis->t1 ,15,"",",",2)+chr(9)
cUebergabe+=tdFixUp(ergebnis->t2 ,15,"",",",2)+chr(9)
cUebergabe+=tdFixUp(ergebnis->t3 ,15,"",",",2)+chr(9)
cUebergabe+=tdFixUp(ergebnis->t4 ,15,"",",",2)+chr(9)
cUebergabe+=tdFixUp(ergebnis->t5 ,15,"",",",2)+chr(9)
cUebergabe+=tdFixUp(ergebnis->t6 ,15,"",",",2)+chr(9)
cUebergabe+=tdFixUp(ergebnis->t7 ,15,"",",",2)+chr(9)
cUebergabe+=tdFixUp(ergebnis->t8 ,15,"",",",2)+chr(9)
cUebergabe+=tdFixUp(ergebnis->t9 ,15,"",",",2)+chr(9)
cUebergabe+=tdFixUp(ergebnis->t10,15,"",",",2)+chr(9)
cUebergabe+=tdFixUp(ergebnis->t11,15,"",",",2)+chr(9)
cUebergabe+=chr(13)+chr(10)
DbSkip(1)
ENDDO
close Ergebnis
oClipboard:=xbpClipboard():new():create()
oClipboard:Open()
oClipboard:Clear()
oClipboard:SetBuffer(cUebergabe)
oClipboard:Close()
oClipboard:destroy()
oSheet:Cells(2,1):select()
oSheet:Paste()
Sleep(10)
oSheet := oBook:Worksheets(1)
oSheet:Activate
// Save workbook as ordinary excel file.
oBook:Save()
// Quit Excel
oExcel:Quit()
oExcel:Destroy()
RETURN NIL
Ach ja, mit der Steuerung einer Powerpoint-Show kämpfe ich noch. Aufrufen etc. funktioniert. Probleme machen noch die Verknüpfungen. Die sollen automatisch - ohne das der Anwender das merkt - aktualisiert werden. Aber das kriege ich auch noch raus.
Gruß
Christof