Das freut mich, das die Excelfunctionslib immer noch beliebt ist.
Da hier schon mal eine Frage war, wie man in Excel ein Bild aus dem Speicher
einfügen kann, habe ich noch was probiert. GetClipboardImage() eignet sich dafür ganz gut.
Aber auch für den xinclude etc. könnte man dann CatchImage() benutzen, um dann das Bild für
Excel in die Zwischenablage zu kopieren.
Folgende Funktion habe ich hinzugefügt:
Code: Alles auswählen
Procedure XLSFunc_PasteFromClipboard(ExcelObject.COMateObject,ImgNr,Width,Height,Prop=#msoFalse); This function put any Images from Clipboard.
If GetClipboardImage(ImgNr)
ExcelObject\Invoke("ActiveSheet\Paste")
ExcelObject\SetProperty("Selection\ShapeRange\LockAspectRatio = "+Str(Prop));msoTrue = Proportional
ExcelObject\SetProperty("Selection\ShapeRange\Height="+Str(Height))
ExcelObject\SetProperty("Selection\ShapeRange\Width="+Str(Width))
Else
MessageRequester("Achtung","Es liegt keine Bildkopie im Zwischenspeicher vor!")
EndIf
EndProcedure
Kleiner Beispielssource hier, wobei man beachten muss, erst ein Bild in die Zwischenablage zu kopieren.
Erst dann wird das Bild in Excel mit einstellbarer Größe auch eingefügt bzw. angezeigt.
Code: Alles auswählen
XIncludeFile "ExcelFunktion.pbi"
;-Defines
Define NewExcelObject
Define CSIDL_DESKTOP
Define UserDesktop.s
Define Result.l
Define FFormat.l
Define Ext_xl.l
Define Extend.s
Define MyComment.s
Procedure.s GetSpecialFolder(CSIDL); Codeschnipsel from german Forum
Protected *itemid.ITEMIDLIST
Protected location.s = Space(#MAX_PATH)
If SHGetSpecialFolderLocation_ (0, CSIDL, @*itemid) = #NOERROR
If SHGetPathFromIDList_(*itemid, @location)
CoTaskMemFree_(*itemid)
If Right(location, 1) <> "\" : location + "\" : EndIf
ProcedureReturn location
EndIf
EndIf
; Liste zu den Konstanten: http://msdn.microsoft.com/en-us/library/bb762494.aspx
EndProcedure
Result=MessageRequester("Bitte korrekt beantworten","Ist Dein Excel älter als Excel2007?", #PB_MessageRequester_YesNo )
If Result = #PB_MessageRequester_Yes
Extend="xls"
Ext_xl.l= #xlNormal
ElseIf Result = #PB_MessageRequester_No
Extend="xlsx"
Ext_xl.l= #xlOpenXMLWorkbook
EndIf
UserDesktop=GetSpecialFolder(CSIDL_DESKTOP)
CreateDirectory(UserDesktop+"ExcelProgramm")
NewExcelObject=XLSFunc_CreateExcelFile(UserDesktop+"ExcelProgramm"); Create a new Excelfile to this Path.
Debug COMate_GetLastErrorDescription()+" XLSFunc_CreateExcelFile"
XLSFunc_ExcelVisible(NewExcelObject,#True); Nothing to see Excel
Debug COMate_GetLastErrorDescription()+" XLSFunc_ExcelVisible"
XLSFunc_WriteCellS(NewExcelObject, 1,2, "Test1 Paste Bild")
Debug COMate_GetLastErrorDescription()+" XLSFunc_WriteCellS"
XLSFunc_SelectCells(NewExcelObject, "C3")
Debug COMate_GetLastErrorDescription()+" XLSFunc_SelectCells"
XLSFunc_PasteFromClipboard(NewExcelObject,0,100,100)
Debug COMate_GetLastErrorDescription()+" XLSFunc_PasteMemImage"
XLSFunc_CloseWorkbook(NewExcelObject)
ClearClipboard()
Debug COMate_GetLastErrorDescription()+" XLSFunc_CloseWorkbook"
XLSFunc_CloseExcelAll(NewExcelObject); End of Excel
Debug COMate_GetLastErrorDescription()+" XLSFunc_CloseExcelAll"