 | OO-Snippets: Draw a lineCommons| Keywords | draw, line, shape, spreadsheet |
|---|
| Language | ooRexx |
|---|
| Application | Calc |
|---|
| Authors | Josef Frysak (initial)
|
|---|
| Supported Versions | 2.4.1 |
|---|
| Supported OS | All |
|---|
| Question | How to draw a line on a Spreadsheet?
|
|---|
| Answer | Get the spreadsheet by using the "XSpreadsheetView" interface. Then use the documents "XMultiServiceFactory" interface to create a new "LineShape" object. Next use the Size and Point strucures to descripe position and size attributes of this line. Finally add the newly created line 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_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.LineShape")
shapecolor = .bsf~new("java.lang.Integer", X2D("FF0000"))
shapeProperties = s_Shape~XPropertySet
shapeProperties~setPropertyValue("LineColor", shapecolor)
linelength = .bsf~new("java.lang.Integer", 500)
shapeProperties~setPropertyValue("LineWidth", linelength)
size = .bsf~new("com.sun.star.awt.Size")
size~bsf.setFieldValue("width", 25000)
size~bsf.setFieldValue("height", 14000)
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)
::requires UNO.CLS
|
Changelog| Date | User | Modification |
|---|
| 2008-10-12 | 1 | Initial version |
|