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.
-- try to get a script context, will be .nil, if script was not invoked by OOo
x_ScriptContext = uno.getScriptContext()
if (x_ScriptContext <> .nil) then
do
-- invoked by OOo as a macro
-- get context
x_ComponentContext = x_ScriptContext~getComponentContext
-- get desktop (an XDesktop)
x_Desktop = x_ScriptContext~getDesktop
-- get current document
x_Document = x_ScriptContext~getDocument
end
else
do
-- called from outside of OOo, create a connection
-- connect to Open Office and get component context
x_ComponentContext = UNO.connect()
-- create a desktop service and its interface
service = "{%see com.sun.star.frame.Desktop}"
s_Desktop = x_ComponentContext~getServiceManager~{%see com.sun.star.lang.XMultiServiceFactory%XMultiServiceFactory}~createInstance(service)
x_Desktop = s_Desktop~{%see com.sun.star.frame.XDesktop%XDesktop}
-- get the last active document
x_Document = x_Desktop~getCurrentComponent()
end
-- first get currently selected sheet
x_Model = x_Document~{%see com.sun.star.frame.XModel%XModel}
s_CurrentController = x_Model~getCurrentController()
x_View = s_CurrentController~{%see com.sun.star.sheet.XSpreadsheetView%XSpreadsheetView}
x_Spreadsheet = x_View~getActiveSheet()
-- then get the drawpage (used for paintings) of the sheet
x_DrawPageSupplier = x_Spreadsheet~{%see com.sun.star.drawing.XDrawPageSupplier%XDrawPageSupplier}
x_DrawPage = x_DrawPageSupplier~getDrawPage()
-- create a new Shape and configure it
x_MultiServiceFactory = x_Document~{%see com.sun.star.lang.XMultiServiceFactory%XMultiServiceFactory}
s_Shape = x_MultiServiceFactory~createInstance("{%see com.sun.star.drawing.LineShape}")
shapecolor = .bsf~new("java.lang.Integer", X2D("FF0000"))
shapeProperties = s_Shape~{%see com.sun.star.beans.XPropertySet%XPropertySet}
shapeProperties~setPropertyValue("LineColor", shapecolor)
linelength = .bsf~new("java.lang.Integer", 500)
shapeProperties~setPropertyValue("LineWidth", linelength)
size = .bsf~new("{%see com.sun.star.awt.Size}")
size~bsf.setFieldValue("width", 25000)
size~bsf.setFieldValue("height", 14000)
pos = .bsf~new("{%see com.sun.star.awt.Point}")
pos~bsf.setFieldValue("X", 400)
pos~bsf.setFieldValue("Y", 400)
x_Shape = s_Shape~{%see com.sun.star.drawing.XShape%XShape}
x_Shape~setSize(size)
x_Shape~setPosition(pos)
-- finally add the shape to the sheet
x_DrawPage~add(x_Shape)
::requires UNO.CLS