 | OO-Snippets: Import a graphic fileCommons| Keywords | graphic, import, insert, spreadsheet |
|---|
| Language | ooRexx |
|---|
| Application | Calc |
|---|
| Authors | Josef Frysak (initial)
|
|---|
| Supported Versions | 2.4.1 |
|---|
| Supported OS | All |
|---|
| Question | How to import a graphic file into a spreadsheet?
|
|---|
| Answer | First a "FilePicker" dialog is used to ask the user for the location of the graphic file. Then a new "GrpahicObjectShape" Object is created by a "XMultiServiceFactory" and the url to the graphic file is stored in its "GraphicURL" property. Finally this graphic object is stored to the "DrawPage" of the spreadsheet. For further details see http://wi.wu-wien.ac.at/rgf/diplomarbeiten/BakkStuff/2008/200809_Frysak/200809_Frysak_Automating_OOo_ooRexx_Nutshells.pdf. |
|---|
x_ScriptContext = uno.getScriptContext()
if (x_ScriptContext <> .nil) then
do
x_ComponentContext = x_ScriptContext~getComponentContext
x_Desktop = x_ScriptContext~getDesktop
x_Document = x_ScriptContext~getDocument
end
else
do
x_ComponentContext = UNO.connect()
service = "com.sun.star.frame.Desktop"
s_Desktop = x_ComponentContext~getServiceManager~XMultiServiceFactory~createInstance(service)
x_Desktop = s_Desktop~XDesktop
x_Document = x_Desktop~getCurrentComponent()
end
x_MultiServiceFactory = x_ComponentContext~getServiceManager()~XMultiServiceFactory
s_FileDialog = x_MultiServiceFactory~createInstance("com.sun.star.ui.dialogs.OfficeFilePicker")
x_FileDialog = s_FileDialog~XFilePicker
x_FileDialogFilters = s_FileDialog~XFilterManager
x_FileDialogFilters~appendFilter("All *.*", "*.*")
x_FileDialog~setTitle("Select Graphic File")
x_FileDialog~setMultiSelectionMode(0)
filechoosen = x_FileDialog~execute()
if ( filechoosen ) then
do
files = x_FileDialog~getFiles()
file = files[1]
x_Model = x_Document~XModel
s_CurrentController = x_Model~getCurrentController()
x_View = s_CurrentController~XSpreadsheetView
x_Spreadsheet = x_View~getActiveSheet()
x_DrawPageSupplier = x_Spreadsheet~XDrawPageSupplier
x_DrawPage = x_DrawPageSupplier~getDrawPage()
x_MultiServiceFactory = x_Document~XMultiServiceFactory
s_Shape = x_MultiServiceFactory~createInstance("com.sun.star.drawing.GraphicObjectShape")
shapeProperties = s_Shape~XPropertySet
shapeProperties~setPropertyValue("GraphicURL", file)
size = .bsf~new("com.sun.star.awt.Size")
size~bsf.setFieldValue("width", 5535)
size~bsf.setFieldValue("height", 5535)
pos = .bsf~new("com.sun.star.awt.Point")
pos~bsf.setFieldValue("X", 400)
pos~bsf.setFieldValue("Y", 400)
x_Shape = s_Shape~XShape
x_Shape~setSize(size)
x_Shape~setPosition(pos)
x_DrawPage~add(x_Shape)
end
::requires UNO.CLS
|
Changelog| Date | User | Modification |
|---|
| 2008-10-12 | 1 | Initial version |
|