|
Examples 
Writer 
0
1
2
3
4
5
6
7
8
9
10
11
| | require 'uno'
import com.sun.star.frame.XComponentLoader
def writer_hello_world()
doc = $XSCRIPTCONTEXT.get_document() if Uno.query(com.sun.star.lang.XServiceInfo, doc).supports_service("com.sun.star.text.TextDocument")
text_doc = Uno.query(com.sun.star.text.XTextDocument, doc)
text = text_doc.get_text()
text.set_string("Hello World!")
end
end
|
Calc 
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| | require 'uno'
def calc_hello_world()
doc = $XSCRIPTCONTEXT.get_document() if Uno.query(com.sun.star.lang.XServiceInfo, doc).supports_service("com.sun.star.sheet.SpreadsheetDocument")
calc_doc = Uno.query(com.sun.star.sheet.XSpreadsheetDocument, doc)
xsheets = calc_doc.get_sheets()
xindex = Uno.query(com.sun.star.container.XIndexAccess, xsheets)
sheet = xindex.get_by_index(0)
xcell_range = Uno.query(com.sun.star.table.XCellRange, sheet)
xcell = xcell_range.get_cell_by_position(0,0)
xtext_range = Uno.query(com.sun.star.text.XTextRange, xcell)
xtext_range.setString("Hello World!")
end
end
|
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| | def calc_test()
desktop = $XSCRIPTCONTEXT.get_desktop()
xloader = Uno.query(com.sun.star.frame.XComponentLoader, desktop)
doc = xloader.load_component_from_url(
"private:factory/scalc", "_blank", 0, com.sun.star.beans.PropertyValue[0].new)
if doc
xmodel = Uno.query(com.sun.star.frame.XModel, doc)
xcontroller = xmodel.getCurrentController()
xselection_supp = Uno.query(com.sun.star.view.XSelectionSupplier, xcontroller)
selection = xselection_supp.getSelection()
if Uno.query(com.sun.star.lang.XServiceInfo, selection).supports_service("com.sun.star.sheet.SheetCell")
text_range = Uno.query(com.sun.star.text.XTextRange, selection)
text_range.setString("Right Alined")
cell_prop = Uno.query(com.sun.star.beans.XPropertySet, text_range)
cell_prop.setPropertyValue(
"HoriJustify",
com.sun.star.table.CellHoriJustify.const_get("RIGHT")) cell_prop.setPropertyValue(
"CharWeight",
com.sun.star.awt.FontWeight.const_get("BOLD")) end
end
end
|
Draw 
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
| | require 'uno'
def draw_hello_world()
doc = $XSCRIPTCONTEXT.getDocument()
if Uno.query(com.sun.star.lang.XServiceInfo, doc).supports_service("com.sun.star.drawing.DrawingDocument")
xdraw_pages_supp = Uno.query(com.sun.star.drawing.XDrawPagesSupplier, doc)
xdraw_pages = xdraw_pages_supp.get_draw_pages()
xindex = Uno.query(com.sun.star.container.XIndexAccess, xdraw_pages)
page = xindex.get_by_index(0)
xmsf = Uno.query(com.sun.star.lang.XMultiServiceFactory, doc)
shape = xmsf.create_instance("com.sun.star.drawing.TextShape")
xshape = Uno.query(com.sun.star.drawing.XShape, shape)
point = com.sun.star.awt.Point.new()
size = com.sun.star.awt.Size.new()
point.X = 1000
point.Y = 1000
size.Width = 5000
size.Height = 1500
xshape.set_position(point)
xshape.set_size(size)
xshapes = Uno.query(com.sun.star.drawing.XShapes, page)
xshapes.add(xshape)
xtext_range = Uno.query(com.sun.star.text.XTextRange, shape)
xtext_range.set_string("Hello World!")
end
end
|
Dialog 
General 
0
1
2
3
4
5
6
7
8
9
10
11
12
13
| | require 'uno'
def create_new_document()
p "create new document"
ctx = $XSCRIPTCONTEXT.get_component_context()
smgr = ctx.get_service_manager()
desktop = smgr.create_instance_with_context("com.sun.star.frame.Desktop", ctx)
loader = Uno.query(XComponentLoader, desktop)
p loader
if loader
loader.load_component_from_url("private:factory/swriter", "_blank",
0, com.sun.star.beans.PropertyValue[0].new)
end
end
|
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| | require 'uno'
def url_parse()
base_url = "file:///home/user/Desktop"
url = com.sun.star.util.URL[1].new
url[0] = com.sun.star.util.URL.new
url[0].Complete = base_url
ctx = $XSCRIPTCONTEXT.getComponentContext()
transformer = Uno.query(
com.sun.star.util.XURLTransformer,
ctx.getServiceManager().createInstanceWithContext(
"com.sun.star.util.URLTransformer", ctx))
transformer.parseStrict(url)
desktop = $XSCRIPTCONTEXT.getDesktop()
xdesktop = Uno.query(com.sun.star.frame.XDesktop, desktop)
message(xdesktop, base_url + "\nprotocol: " + url[0].Protocol)
end
|
|