easydev documentation - read the docs · 13.4 grid ... ("org.universolibre.easydev")...

85
EasyDev Documentation Release 2.0.0 Mauricio Baeza Mar 19, 2017

Upload: tranduong

Post on 18-Oct-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

EasyDev DocumentationRelease 2.0.0

Mauricio Baeza

Mar 19, 2017

Contents

1 Introduction 31.1 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.2 Test installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

2 Tools for debug 52.1 Show info en shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52.2 Save info in file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72.3 Special msgbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72.4 Call MRI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

3 Tools 93.1 Show info PC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93.2 Make question . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103.3 Render string . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103.4 Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113.5 Files and folders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113.6 Execute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133.7 Config . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133.8 Clipboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133.9 Unix time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153.10 Call macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153.11 Timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163.12 Export CSV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173.13 Import CSV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183.14 Zip files and folders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183.15 Unzip . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

4 Send mail 214.1 Send mail and wait result . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214.2 Send mail and not wait . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224.3 Send mail with CC and BCC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224.4 Send mail with attachment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234.5 Send mail and save . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

5 Arrays 275.1 Append . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275.2 Delete . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

i

5.3 Extend . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275.4 Multiplicate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275.5 Unique values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285.6 Reverse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285.7 Insert . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285.8 Remove . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285.9 Len . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285.10 Count . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295.11 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295.12 Max, Min and Average . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295.13 Sum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295.14 Exists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295.15 Equal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295.16 Slice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305.17 Sorted . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305.18 Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

6 Requests 336.1 Get . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

7 Documents 357.1 New . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357.2 Get doc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357.3 Get type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367.4 Get documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367.5 Open . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367.6 Active . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377.7 Status bar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377.8 Set visible . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377.9 Export PDF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387.10 Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

8 Calc 418.1 Get sheet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 418.2 Set active sheet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428.3 Insert sheets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428.4 Insert sheet from document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 438.5 Remove sheet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 438.6 Move sheet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 448.7 Sort sheets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 458.8 Copy sheet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 458.9 Copy sheet to document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 468.10 Rename sheet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 478.11 Show or hidden sheet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 478.12 Sheet password . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 488.13 Cells . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 498.14 Ranges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 508.15 Select range . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 528.16 Current region . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 538.17 Get empty cells . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 538.18 Get visible cells . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 538.19 Last row . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 548.20 Next value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 548.21 Cell value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

ii

8.22 Set data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 558.23 Get data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

9 Writer 579.1 Paragraphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57

10 Data Base 5910.1 Connection DB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5910.2 ODBC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6010.3 Query . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6010.4 Update . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60

11 Charts 6311.1 Chart XY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63

12 Images and shapes 6712.1 Insert image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6712.2 Insert shape . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69

13 Dialogs 7313.1 Create dialog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7313.2 Label hyperlink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7413.3 Roadmap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7413.4 Grid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7513.5 TextBox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7713.6 CommandButton . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78

14 Indices and tables 79

iii

iv

EasyDev Documentation, Release 2.0.0

Contents:

Contents 1

EasyDev Documentation, Release 2.0.0

2 Contents

CHAPTER 1

Introduction

EasyDev can you help to develop macros in LibreOffice.

Installation

• Download lates version from GitHub.

• Open LibreOffice

• Tools -> Extension manager...

• Add...

3

EasyDev Documentation, Release 2.0.0

Test installation

Sub Test()'Create serviceutil = createUnoService("org.universolibre.EasyDev")

MsgBox util.VERSIONEnd Sub

4 Chapter 1. Introduction

CHAPTER 2

Tools for debug

Show info en shell

Only Linux

Sub Debug()'Create serviceutil = createUnoService("org.universolibre.EasyDev")

util.debug("Test debug")End Sub

5

EasyDev Documentation, Release 2.0.0

In Windows, you can open a new document Writer, save with name debug.odt and show info debug in this document.

6 Chapter 2. Tools for debug

EasyDev Documentation, Release 2.0.0

Save info in file

Sub LogFile()

util = createUnoService("org.universolibre.EasyDev")

util.log("/home/USER/log.txt", util)

End Sub

Automatic add date and time.

2015-10-28 20:56:35 - EasyDev - <uno_component.EasyDev object at 0x7f96caf34438>2015-10-28 20:56:41 - EasyDev - <uno_component.EasyDev object at 0x7f96caf34438>

Special msgbox

Show any data in msgbox like objects and arrays.

Sub MessageBox()util = createUnoService("org.universolibre.EasyDev")

'Show info in message boxutil.msgbox("Debug data")

'Show any datadata = "This is string"util.msgbox(data)

data = 12345util.msgbox(data)

data = Array("Uno", 2)util.msgbox(data)

util.msgbox(util)End Sub

Call MRI

MRI is the best extension for introspeccion of objects for Apache OpenOffice and LibreOffice. Download and install.

Call from EasyDev.

Sub CallMRI()util = createUnoService("org.universolibre.EasyDev")

'MRI is a great extensionutil.mri(util)

End Sub

2.2. Save info in file 7

EasyDev Documentation, Release 2.0.0

8 Chapter 2. Tools for debug

CHAPTER 3

Tools

Show info PC

Sub ShowInfoPC()util = createUnoService("org.universolibre.EasyDev")

'Operator Systemutil.msgbox(util.OS)

'App Nameutil.msgbox(util.APP_NAME)

'App Versionutil.msgbox(util.APP_VERSION)

'App Languageutil.msgbox(util.LANGUAGE)

'Size screenutil.msgbox(util.getSizeScreen())

' https://docs.python.org/3.3/library/platform.html' Get info PC:' name user,' name pc' system/OS name,' machine type,' Returns the (real) processor name' string identifying platform with as much useful information as possible,util.msgbox(util.getInfoPC())

End Sub

9

EasyDev Documentation, Release 2.0.0

Make question

Sub Question()util = createUnoService("org.universolibre.EasyDev")

title = "My App"message = "Is easy Python?"res = util.question(title, message)

'If Yes return True, else return Falseutil.msgbox(res)

End Sub

Render string

Render text and replace arguments.

Sub RenderString()util = createUnoService("org.universolibre.EasyDev")

'Used NamedValuemessage = "Hello $data with $language, from Basic 1!!"Dim data1(1) As New com.sun.star.beans.NamedValue

data1(0).Name = "data"data1(0).Value = "World"data1(1).Name = "language"data1(1).Value = "Python"message = util.render(message, data1)util.msgbox(message)

'Used PropertyValuemessage = "Hello $data with $language, from Basic 2!!"Dim data2(1) As New com.sun.star.beans.PropertyValue

data2(0).Name = "data"data2(0).Value = "World"data2(1).Name = "language"data2(1).Value = "Python"message = util.render(message, data2)util.msgbox(message)

'Used Arraysmessage = "Hello $data with $language, from Basic 3!!"data = Array( _

Array("data", "World"), _Array("language", "Python") _

)message = util.render(message, data2)util.msgbox(message)

End Sub

10 Chapter 3. Tools

EasyDev Documentation, Release 2.0.0

Format

Look more info and examples here.

Sub FormatData()util = createUnoService("org.universolibre.EasyDev")

MsgBox util.format("Hello {}", "World")

MsgBox util.format("Hello {} from {}", Array("World", "PyUNO"))

MsgBox util.format("Hello {1} from {0}", Array("World", "PyUNO"))

MsgBox util.format("{:<20}|{:^20}|{:>20}", Array("Left", "Center", "Rigth"))

MsgBox util.format("{:_<20}|{:-^20}|{:_>20}", Array("Left", "Center", "Rigth"))

MsgBox util.format("{:d} {:f}", Array(100, 3.1416))

MsgBox util.format("{0:,.2f}", 123456789.2468)

MsgBox util.format("Number {n1} y {n2}", Array(Array("n1", "one"), Array("n2",→˓"two")))

MsgBox util.format("Number {n2} y {n1}", Array(Array("n1", "one"), Array("n2",→˓"two")))

my_date = createUnoStruct("com.sun.star.util.Date")my_date.Day = 15my_date.Month = 1my_date.Year = 1974MsgBox util.format("{:%d-%B-%Y}", my_date)

my_date = createUnoStruct("com.sun.star.util.DateTime")my_date.Day = 15my_date.Month = 1my_date.Year = 1974my_date.Hours = 13my_date.Minutes = 30

MsgBox util.format("{:%Y-%b-%d %H:%M}", my_date)

End Sub

Files and folders

Return de path name in config. Look XPathSettings.

path = util.getPath("Temp")util.msgbox(path)path = util.getPath("Work")util.msgbox(path)

Get info from path: path base, file name, file name without extension, extension

3.4. Format 11

EasyDev Documentation, Release 2.0.0

data = util.getPathInfo("/home/USER/log.txt")util.msgbox(data)

Join paths

path = util.pathJoin(Array("/home", "USER", "Documents"))util.msgbox(path)path = util.pathJoin(Array("/home/USER/Documents", "..", "Picture"))util.msgbox(path)

Select folder, default path documents user

folder = util.getFolder("")util.msgbox(folder)

'With other init folderfolder = util.getFolder("/home/USER")util.msgbox(folder)

Select one file without filters

file = util.getSelectedFiles("", False, Array())util.msgbox(file)

Select multiple files

files = util.getSelectedFiles("", True, Array())util.msgbox(files)

Select multiple files with filter

filters = Array( _Array("TXT", "*.txt"), _Array("LOG", "*.log"), _Array("CER | KEY", "*.cer;*.key") _

)files = util.getSelectedFiles("", True, filters)util.msgbox(files)

Get all files recursive

files = util.getFiles("/home/USER/Pictures", "")util.msgbox(files)

Get all files with filter extension

files = util.getFiles("/home/USER/Pictures", "jpg")util.msgbox(files)files = util.getFiles("/home/USER/Pictures", "png")util.msgbox(files)

Open file, read all content

data = util.fileOpen("/home/USER/log.txt", "r", False)util.msgbox(data)

Open file, get lines in array

12 Chapter 3. Tools

EasyDev Documentation, Release 2.0.0

data = util.fileOpen("/home/USER/log.txt", "r", True)util.msgbox(data)

Save data in new file

data = "Hello World Python"util.fileSave("/home/USER/test.txt", "w", data)'Verifydata = util.fileOpen("/home/mau/test.txt", "r")util.msgbox(data)

Save data in append file

data = "Hello World Python" & CHR(10)util.fileSave("/home/USER/test2.txt", "a", data)'Verifydata = util.fileOpen("/home/USER/test2.txt", "r")util.msgbox(data)

Execute

Execute command and wait response

res = util.execute(Array("ls","-la"), True)util.msgbox(res)

Execute command and not wait

util.execute(Array("gnome-calculator"), False)

Config

Save value in config, save is persistente

util.setConfig("DefaultMail", "[email protected]")'Get value from configvalue = util.getConfig("DefaultMail")util.msgbox(value)

Is posible save arrays

util.setConfig("Matriz", Array(1,2,3))value = util.getConfig("Matriz")util.msgbox(value)

Clipboard

Get text from clipboard

3.6. Execute 13

EasyDev Documentation, Release 2.0.0

value = util.getClipboard()util.msgbox(value)

Send text to clipboard

util.setClipboard("Hello World PyUNO!!")'Verifyvalue = util.getClipboard()util.msgbox(value)

Copy and paste. Currently, only Calc. Copy current selection.

util = createUnoService("org.universolibre.EasyDev")

doc = ThisComponentutil.copy(doc)util.paste(doc)

Copy and paste range cells, is very important, select ranges correctly. See Ranges.

util = createUnoService("org.universolibre.EasyDev")source = createUnoStruct("org.universolibre.EasyDev.CellRangeAddress")target = createUnoStruct("org.universolibre.EasyDev.CellRangeAddress")

doc = ThisComponentsource.Doc = docsource.Sheet = "Sheet1"source.Name = "A1:B2"range = util.getRange(source)util.selectRange(doc, range)util.copy(doc)

target.Doc = doctarget.Sheet = "Sheet1"target.Name = "A8"range = util.getRange(target)util.selectRange(doc, range)util.paste(doc)

14 Chapter 3. Tools

EasyDev Documentation, Release 2.0.0

Unix time

Look https://en.wikipedia.org/wiki/Unix_time

epoch = util.getEpoch()util.msgbox(epoch)

Call macros

Look: Scripting Framework

Save next macro in:

/home/USER/.config/libreoffice/4/user/Scripts/python/mymacros.py

import unoimport time

def show_time(cell):cell.setString(time.strftime('%c'))time.sleep(3)return

Call macro in Python (is default), wait end

macro = createUnoStruct("org.universolibre.EasyDev.Macro")macro.Library = "mymacros"macro.Name = "show_time"cell = ThisComponent.CurrentSelectionutil.callMacro(macro, Array(cell))

Call macro in Python, and NOT wait end

3.9. Unix time 15

EasyDev Documentation, Release 2.0.0

macro = createUnoStruct("org.universolibre.EasyDev.Macro")macro.Library = "mymacros"macro.Name = "show_time"macro.Thread = Truecell = ThisComponent.CurrentSelectionutil.callMacro(macro, Array(cell))

Call macro in Basic

macro = createUnoStruct("org.universolibre.EasyDev.Macro")macro.Library = "EasyDevLib"macro.Module = "Examples"macro.Name = "HelloWorld"macro.Language = "Basic"macro.Thread = Falseutil.callMacro(macro, Array())

Timer

Save next macro in:

/home/USER/.config/libreoffice/4/user/Scripts/python/mymacros.py

import unoimport time

def show_time(cell):cell.setString(time.strftime('%c'))return

timer(NAME_TIMER, SECONDS_WAIT, MACRO, ARGUMENTS)

NAME_TIMER is import for stop timer. Timer always execute in other thread.

util = createUnoService("org.universolibre.EasyDev")

'Make data macromacro = createUnoStruct("org.universolibre.EasyDev.Macro")macro.Library = "mymacros"macro.Name = "show_time"'Argumentscell = ThisComponent.CurrentSelection'Timer name "time" and wait one secondutil.timer("time", 1, macro, Array(cell))

Stop timer for name

16 Chapter 3. Tools

EasyDev Documentation, Release 2.0.0

Sub StopTimer()util = createUnoService("org.universolibre.EasyDev")util.stopTimer("time")

End Sub

Export CSV

Set range with data and select.

and export

util = createUnoService("org.universolibre.EasyDev")

range = ThisComponent.CurrentSelection

path = "/home/USER/test.csv"data = range.getDataArray()options = Array()

util.exportCSV(path, data, options)

Change options for export, look: https://docs.python.org/3.3/library/csv.html#csv.writer

Dim options(0) As New com.sun.star.beans.NamedValue

util = createUnoService("org.universolibre.EasyDev")

range = ThisComponent.CurrentSelection

path = "/home/USER/test.csv"data = range.getDataArray()options(0).Name = "delimiter"options(0).Value = "|"util.exportCSV(path, data, options)

3.12. Export CSV 17

EasyDev Documentation, Release 2.0.0

Import CSV

Selected range must be with number exactly of columns and rows to import, only for this example.

More options see: https://docs.python.org/3.3/library/csv.html#csv.reader

and import

util = createUnoService("org.universolibre.EasyDev")

range = ThisComponent.CurrentSelectionpath = "/home/USER/test.csv"options = Array()data = util.importCSV(path, options)range.setDataArray(data)

It’s possible calculate automatically the size of data range. see Set data.

Zip files and folders

Zip file, write zip in same directory and same name.

util = createUnoService("org.universolibre.EasyDev")

source = "/home/mau/Documents/debug.log"'Target = "/home/mau/Documents/debug.zip"target = ""util.zip(source, target)

Zip file in other directory, same name.

source = "/home/mau/Documents/debug.log"'Target = "/home/mau/debug.zip"target = "/home/mau"util.zip(source, target)

Zip file in other directory, other name.

18 Chapter 3. Tools

EasyDev Documentation, Release 2.0.0

source = "/home/mau/Documents/debug.log"target = "/home/mau/test.zip"util.zip(source, target)

Zip folder

source = "/home/mau/Pictures"'Target = "/home/mau/Pictures.zip"target = ""util.zip(source, target)

'Target = "/home/mau/Documents/Pictures.zip"target = "/home/mau/Documents"util.zip(source, target)

target = "/home/mau/Documents/pic.zip"util.zip(source, target)

Unzip

Unzip file, extract all content.

source = "/home/mau/Documents/Pictures.zip"target = ""file_name = ""util.unzip(source, target, file_name)

Extract in other folder.

target = "/home/mau"file_name = ""util.unzip(source, target, file_name)

Extract only one file.

target = "/home/mau"file_name = "mylove.png"util.unzip(source, target, file_name)

3.15. Unzip 19

EasyDev Documentation, Release 2.0.0

20 Chapter 3. Tools

CHAPTER 4

Send mail

Send mail and wait result

Sub SendMail()util = createUnoService("org.universolibre.EasyDev")

server = createUnoStruct("org.universolibre.EasyDev.SmtpServer")message = createUnoStruct("org.universolibre.EasyDev.EmailMessage")

server.Name = "smtp.gmail.com"server.User = "[email protected]"server.Password = "supersecret"server.Ssl = True

temp = "Dear Madame: $name\n\nBest regards from $country"data = Array( _

Array("name", "Teresa"), _Array("country", "México"), _

)body = util.render(temp, data)

message.To = "[email protected]"message.Subject = "Email test"message.Body = body

'Send mail and wait responseresult = util.sendMail(server, message)If result Then

MsgBox "Send mail"Else

MsgBox "Error send mail"End If

End Sub

21

EasyDev Documentation, Release 2.0.0

Send mail and not wait

Sub SendMailNoWait()util = createUnoService("org.universolibre.EasyDev")

server = createUnoStruct("org.universolibre.EasyDev.SmtpServer")message = createUnoStruct("org.universolibre.EasyDev.EmailMessage")

server.Name = "smtp.gmail.com"server.User = "[email protected]"server.Password = "supersecret"server.Ssl = Trueserver.Thread = True 'Send in other thread

temp = "Dear Madame: $name\n\nBest regards from $country"data = Array( _

Array("name", "Teresa"), _Array("country", "México"), _

)body = util.render(temp, data)

message.To = "[email protected]"message.Subject = "Email test"message.Body = body

'Send mail and NO wait responseutil.sendMail(server, message)MsgBox "Send mail"

End Sub

Send mail with CC and BCC

Sub SendMailNoWaitAndCCBCC()util = createUnoService("org.universolibre.EasyDev")

server = createUnoStruct("org.universolibre.EasyDev.SmtpServer")message = createUnoStruct("org.universolibre.EasyDev.EmailMessage")

server.Name = "smtp.gmail.com"server.User = "[email protected]"server.Password = "supersecret"server.Ssl = Trueserver.Thread = True 'Send in other thread

temp = "Dear Madame: $name\n\nBest regards from $country"data = Array( _

Array("name", "Teresa"), _Array("country", "México"), _

)body = util.render(temp, data)

message.To = "[email protected]"message.Subject = "Email test"message.Body = body

22 Chapter 4. Send mail

EasyDev Documentation, Release 2.0.0

message.Cc = "[email protected],[email protected]"message.Bcc = "[email protected],[email protected]"

'Send mail and NO wait responseutil.sendMail(server, message)MsgBox "Send mail"

End Sub

Send mail with attachment

Sub SendMailWithAttachment()util = createUnoService("org.universolibre.EasyDev")

server = createUnoStruct("org.universolibre.EasyDev.SmtpServer")message = createUnoStruct("org.universolibre.EasyDev.EmailMessage")

server.Name = "smtp.gmail.com"server.User = "[email protected]"server.Password = "supersecret"server.Ssl = Trueserver.Thread = True 'Send in other thread

temp = "Dear Madame: $name\n\nBest regards from $country"data = Array( _

Array("name", "Teresa"), _Array("country", "México"), _

)body = util.render(temp, data)

files = Array("/home/USER/Documents/pruebas.cer", "/home/USER/Documents/pruebas.→˓key")

message.To = "[email protected]"message.Subject = "Email test"message.Body = bodymessage.Files = files

'Send mail and NO wait responseutil.sendMail(server, message)MsgBox "Send mail"

End Sub

Send mail and save

If you use a path in Thunderbird, you can see mail in folder into Thunderbird

Caution: Use separate folder into tree folders in Thunderbird!

4.4. Send mail with attachment 23

EasyDev Documentation, Release 2.0.0

Sub SendMailAndSave()util = createUnoService("org.universolibre.EasyDev")

server = createUnoStruct("org.universolibre.EasyDev.SmtpServer")message = createUnoStruct("org.universolibre.EasyDev.EmailMessage")

server.Name = "smtp.gmail.com"server.User = "[email protected]"server.Password = "supersecret"server.Ssl = Trueserver.Thread = True 'Send in other threadserver.PathSave = "/home/USER/.thunderbird/cwfln0bi.default/Mail/Local Folders/

→˓Sent"

temp = "Dear Madame: $name\n\nBest regards from $country"data = Array( _

Array("name", "Teresa"), _Array("country", "México"), _

)body = util.render(temp, data)

files = Array("/home/USER/Documents/pruebas.cer")

message.To = "[email protected]"message.Subject = "Email test"message.Body = bodymessage.Files = filesmessage.Save = True

'Send mail and NO wait responseutil.sendMail(server, message)MsgBox "Send mail"

End Sub

24 Chapter 4. Send mail

EasyDev Documentation, Release 2.0.0

4.5. Send mail and save 25

EasyDev Documentation, Release 2.0.0

26 Chapter 4. Send mail

CHAPTER 5

Arrays

Append

a = Array("Nikole","Scarlett","Monica","Naomi","Marion")a = util.append(a, "Sofia")util.msgbox( a )

Delete

a = util.delete(a, "Nikole")util.msgbox( a )

Extend

a = Array("Nikole","Scarlett","Monica","Naomi","Marion")a2 = Array("Sofia", "Anita")a = util.extend(a, a2)util.msgbox( a )

Multiplicate

a = Array("Nikole","Scarlett","Monica","Naomi","Marion")a = util.multi(a, 2)util.msgbox( a )

27

EasyDev Documentation, Release 2.0.0

Unique values

a = Array(1,2,"Two",3,3,3,4,4,4,4,5,5,5,5,5,"Uno","Uno")a = util.unique(a)util.msgbox( a )

Reverse

a = Array("Nikole","Scarlett","Monica","Naomi","Marion")a = util.reverse(a)util.msgbox( a )

Insert

Insert element in pos

a = Array("Nikole","Scarlett","Monica","Naomi","Marion")a = util.insert(a, 2, "Mary")util.msgbox( a )

Remove

Remove element in pos and return array and element

a = Array(1,2,"Two",3,3,3,4,4,4,4,5,5,5,5,5,"Uno","Uno")data = util.pop(a, 2)util.msgbox( data(0) ) 'Array without element in posutil.msgbox( data(1) ) 'Element removed

Remove first element found

a = Array(1,2,2,3,3,3,4,4,4,4,5,5,5,5,5,"Uno","Uno")util.msgbox( util.remove(a, 5, False) )

Remove all elements found

util.msgbox( util.remove(a, 5, True) )

Len

a = Array(1,2,2,3,3,3,4,4,4,4,5,5,5,5,5,"Uno","Uno")util.msgbox( util.len(a) )

28 Chapter 5. Arrays

EasyDev Documentation, Release 2.0.0

Count

a = Array(1,2,2,3,3,3,4,4,4,4,5,5,5,5,5,"Uno","Uno")util.msgbox( util.count(a, 3) )util.msgbox( util.count(a, 5) )util.msgbox( util.count(a, "Uno") )

Index

a = Array("Nikole","Scarlett","Monica","Naomi","Marion")util.msgbox( util.index(a, "Naomi") )util.msgbox( util.index(a, "Monica") )

Max, Min and Average

a = Array(1,2,3,4,5,6,7,8,9,10)util.msgbox( util.max(a) )util.msgbox( util.min(a) )util.msgbox( util.average(a) )

Sum

a = Array(1,2,3,4,5,6,7,8,9,10)util.msgbox( util.sum(a) )

Only sum values, the first element is string

a = Array("10", 1,2,3,4,5,6,7,8,9,10, "One", "Two")util.msgbox( util.sum(a) )

Exists

If value exists in array

a = Array(1,2,3,4,5,"One","Seven",9,10)util.msgbox( util.exists(a, "One") )util.msgbox( util.exists(a, "Two") )

Equal

If array 1 is equal to array2

5.10. Count 29

EasyDev Documentation, Release 2.0.0

a1 = Array(1,2,3) : a2 = Array(1,2,3)util.msgbox( util.equal(a1, a2) )

a1 = Array(1,"Dos",3) : a2 = Array(1,2,"Tres")util.msgbox( util.equal(a1, a2) )

Slice

Copy

a = Array("Nikole","Scarlett","Monica","Naomi","Marion","Sofia","Anita")a2 = util.slice(a, "[:]")util.msgbox( a2 )

First two elements

a2 = util.slice(a, "[:2]")util.msgbox( a2 )

Last two elements

a2 = util.slice(a, "[-2:]")util.msgbox( a2 )

Range

a2 = util.slice(a, "[2:-2]")util.msgbox( a2 )

a2 = util.slice(a, "[::2]")util.msgbox( a2 )

a2 = util.slice(a, "[1::2]")util.msgbox( a2 )

Reverse

a2 = util.slice(a, "[::-1]")util.msgbox( a2 )

Sorted

Sorted unidimension array

a = Array("Nikole","Scarlett","Monica","Naomi","Marion","Sofia","Anita")a = util.sorted(a, 0)util.msgbox( a )

Sorted multidimension array

a = Array( _Array(1, 1, 3, "a", 56), _Array(1, 2, 3, "z", 43), _

30 Chapter 5. Arrays

EasyDev Documentation, Release 2.0.0

Array(1, 3, 3, "g", 78), _Array(1, 4, 3, "e", 32), _Array(1, 5, 3, "M", 89) _

)a = util.sorted(a, 0)util.msgbox( a )a = util.sorted(a, 1)util.msgbox( a )a = util.sorted(a, 2)util.msgbox( a )a = util.sorted(a, 3)util.msgbox( a )a = util.sorted(a, 4)util.msgbox( a )

Get column

util.msgbox(util.getColumn(a, 1))

Operations

Sub ArraysOperations()util = createUnoService("org.universolibre.EasyDev")

a1 = Array(1,2,3,4,5) : a2 = Array(3,4,5,6,7,8)a = util.union(a1, a2)util.msgbox( a )

a = util.intersection(a1, a2)util.msgbox( a )

a = util.difference(a1, a2)util.msgbox( a )

a = util.symmetricDifference(a1, a2)util.msgbox( a )

End Sub

5.18. Operations 31

EasyDev Documentation, Release 2.0.0

32 Chapter 5. Arrays

CHAPTER 6

Requests

Requests is the best library for HTTP in Python

Get

Sub Getutil = createUnoService("org.universolibre.EasyDev")data = createUnoStruct("org.universolibre.EasyDev.Requests")

data.Method = "get"data.Url = "https://api.vaultoro.com/latest"args = Array( _

Array("verify", False) _)data.Args = args

response = util.requests(data)util.msgbox(response.Text)

End Sub

First, get IP public, and then, get location IP

Sub GetIPLocation()util = createUnoService("org.universolibre.EasyDev")data = createUnoStruct("org.universolibre.EasyDev.Requests")

data.Method = "get"data.Url = "http://api.ipify.org"response = util.requests(data)ip_public = response.Text

data.Url = "http://freegeoip.net/csv/" & ip_public

33

EasyDev Documentation, Release 2.0.0

response = util.requests(data)util.msgbox(response.Text)

End Sub

Use Auth

util = createUnoService("org.universolibre.EasyDev")data = createUnoStruct("org.universolibre.EasyDev.Requests")

data.Method = "get"data.Url = "https://api.github.com/user"data.Args = Array( _

Array("auth", Array("mauriciobaeza", "supersecret")) _)

response = util.requests(data)

util.msgbox(response.StatusCode)util.msgbox(response.Text)

You can test request in: http://httpbin.org/

34 Chapter 6. Requests

CHAPTER 7

Documents

New

Look: http://www.openoffice.org/api/docs/common/ref/com/sun/star/frame/XComponentLoader.html

Sub NewDoc()'Create new docutil = createUnoService("org.universolibre.EasyDev")

'Default Calcdoc = util.newDoc("")

End Sub

Other values: swriter, simpress, sdraw, smath

doc = util.newDoc("sdraw")

For Base document.

path_db = "/home/USER/dbtest.odb"db = util.newDB(path_db)

Get doc

Current

Important: Current doc can be IDE

35

EasyDev Documentation, Release 2.0.0

doc1 = util.getDoc("")MsgBox doc1.Title

Get doc by title, if not found, doc is Empty

doc2 = util.getDoc("Name_doc.odt")util.msgbox(doc2)

Get type

Values return: calc, writer, impress, draw, math, base, ide

doc1 = util.newDoc("sdraw")MsgBox util.getTypeDoc(doc1)

doc2 = util.newDoc("swriter")MsgBox util.getTypeDoc(doc2)

Get documents

Get all open documents

docs = util.getDocs()MsgBox util.format("{} Open documents", util.len(docs))

Open

More info and options:

• Component Loader

• Media Descriptor

Open by path document

Dim options1(0) As New com.sun.star.beans.NamedValueutil = createUnoService("org.universolibre.EasyDev")

path = "/home/USER/Plantilla.ods"options = Array()doc = util.openDoc(path, options)

Open like template

options1(0).Name = "AsTemplate"options1(0).Value = Truepath = "/home/USER/Plantilla.ods"doc = util.openDoc(path, options1)

Open hidden

36 Chapter 7. Documents

EasyDev Documentation, Release 2.0.0

options1(0).Name = "Hidden"options1(0).Value = Truepath = "/home/USER/Plantilla.ods"doc = util.openDoc(path, options1)MsgBox "Close doc"doc.dispose()

Active

Send focus to document

doc1 = util.newDoc("")doc2 = util.newDoc("swriter")wait(1000)util.setFocus(doc1)

Status bar

Set text and show progress bar

'Get current docdoc = util.getDoc("")'Get status barsb = util.getStatusBar(doc)

'Init text and up limitsb.start( "Row ", 10 )For co1 = 1 To 10

'Set valuesb.setValue( co1 )Wait 1000

Next'Is import free status barsb.end()

Set visible

Hidden document.

util = createUnoService("org.universolibre.EasyDev")

doc = util.newDoc("")

util.setVisible(doc, False)

MsgBox "Document is hidden"

util.setVisible(doc, True)

7.6. Active 37

EasyDev Documentation, Release 2.0.0

Export PDF

All options in PDF Export in wiki.

If export is correct, return path save PDF

Export current doc in the same folder and same name

doc = util.getDoc("")path = util.exportPDF(doc, "", Array())MsgBox util.format("PDF export in: {}", path)

For save in other folder and same name

path_save = "/home/USER/OTHER_FOLDER"path_pdf = util.exportPDF(doc, path_save, Array())

For save in other folder and other name

path_save = "/home/USER/OTHER_FOLDER/NAME.pdf"path_pdf = util.exportPDF(doc, path_save, Array())

Export with options

Dim options(0) As New com.sun.star.beans.NamedValue

doc = util.getDoc("")options(0).Name = "PageRange"options(0).Value = "2"path = util.exportPDF(doc, "", options)MsgBox util.format("PDF export in: {}", path)

Search

Important: Pass object correct in Doc argument. See examples.

Search in Writer

util = createUnoService("org.universolibre.EasyDev")opt = createUnoStruct("org.universolibre.EasyDev.SearchReplace")

doc = ThisComponentopt.Doc = docopt.Search = "test"

found = util.search(opt)util.selectText(doc, found)

Search in Calc

util = createUnoService("org.universolibre.EasyDev")opt = createUnoStruct("org.universolibre.EasyDev.SearchReplace")

doc = ThisComponent

38 Chapter 7. Documents

EasyDev Documentation, Release 2.0.0

sheet = doc.getCurrentController().getActiveSheet()opt.Doc = sheetopt.Search = "test"

found = util.search(opt)util.selectRange(doc, found)

Search in Draw or Impress

util = createUnoService("org.universolibre.EasyDev")opt = createUnoStruct("org.universolibre.EasyDev.SearchReplace")

doc = ThisComponentpage = doc.getDrawPages().getByIndex(0)opt.Doc = pageopt.Search = "test"

found = util.search(opt)util.msgbox(found(0).getString())

7.10. Search 39

EasyDev Documentation, Release 2.0.0

40 Chapter 7. Documents

CHAPTER 8

Calc

Get sheet

Get all sheets names.

util = createUnoService("org.universolibre.EasyDev")

'Get current docdoc = util.getDoc("")names = util.getSheetsNames(doc)util.msgbox(names)

Get active sheet.

Important: Current doc can be IDE, and IDE not have sheets

util = createUnoService("org.universolibre.EasyDev")address = createUnoStruct("org.universolibre.EasyDev.CellRangeAddress")

'Get active sheet from active docsheet = util.getSheet(address)msgbox sheet.Name

Is better use explicit doc

doc = ThisComponentaddress.Doc = docsheet = util.getSheet(address)MsgBox sheet.Name

Get active sheet from other doc

41

EasyDev Documentation, Release 2.0.0

address.Doc = util.getDoc("Untitled 3.ods")sheet = util.getSheet(address)MsgBox sheet.Name

Get sheet by name.

address.Doc = ThisComponentaddress.Sheet = "Sheet2"sheet = util.getSheet(address)MsgBox sheet.Name

Get sheet by index. Index start in 0.

address.Doc = ThisComponentaddress.Sheet = 1sheet = util.getSheet(address)MsgBox sheet.Name

Get last sheet by index.

address.Doc = ThisComponentaddress.Sheet = -1sheet = util.getSheet(address)MsgBox sheet.Name

Set active sheet

Active sheet by name.

util = createUnoService("org.universolibre.EasyDev")address = createUnoStruct("org.universolibre.EasyDev.CellRangeAddress")

doc = ThisComponentaddress.Doc = docaddress.Sheet = "Sheet2"

util.sheetActivate(address)

Active sheet by index. Last sheet index == -1

doc = ThisComponentaddress.Doc = docaddress.Sheet = -1

util.sheetActivate(address)

Insert sheets

Insert sheet in pos. Get error if sheet exists

util = createUnoService("org.universolibre.EasyDev")address = createUnoStruct("org.universolibre.EasyDev.CellRangeAddress")

42 Chapter 8. Calc

EasyDev Documentation, Release 2.0.0

address.Doc = ThisComponentaddress.Sheet = "New Sheet"util.sheetInsert(address, 0, False)

Rename sheet if exists. Get name “New Sheet_1”, “New Sheet_2”, etc...

address.Doc = ThisComponentaddress.Sheet = "New Sheet"util.sheetInsert(address, 0, True)

Insert in last pos.

address.Doc = ThisComponentaddress.Sheet = "New Sheet"util.sheetInsert(address, -1, True)

Insert more one sheet.

address.Doc = ThisComponentaddress.Sheet = Array("One", "Two", "Other")util.sheetInsert(address, 0, True)

Insert sheet from document

Only LibreOffice, for OpenOffice use: Copy sheet to document. Insert all sheets from source document to targetdocument.

util = createUnoService("org.universolibre.EasyDev")source = createUnoStruct("org.universolibre.EasyDev.CellRangeAddress")target = createUnoStruct("org.universolibre.EasyDev.CellRangeAddress")

doc = ThisComponentsource.Doc = doc

new_doc = util.newDoc("")target.Doc = new_doc

util.sheetInsertFromDoc(source, target, -1, False)

Remove sheet

Important: The index of sheets change if remove some sheet.

Remove sheet by name

util = createUnoService("org.universolibre.EasyDev")address = createUnoStruct("org.universolibre.EasyDev.CellRangeAddress")

address.Doc = ThisComponentaddress.Sheet = "Sheet2"util.sheetRemove(address, False)

8.4. Insert sheet from document 43

EasyDev Documentation, Release 2.0.0

Remove sheet by index

address.Doc = ThisComponentaddress.Sheet = 1util.sheetRemove(address, False)

Remove sheet by index, last sheet

address.Doc = ThisComponentaddress.Sheet = -1util.sheetRemove(address, False)

First get sheet and remove by object

address.Doc = ThisComponentaddress.Sheet = "Sheet6"sheet = util.getSheet(address)address.Sheet = sheetutil.sheetRemove(address, False)

Remove more one sheet, by index, name or object

address.Doc = ThisComponentaddress.Sheet = Array(0, "Sheet4", "Sheet2", sheet, -1)util.sheetRemove(address, False)

Remove all sheet, except name

address.Doc = ThisComponentaddress.Sheet = "Sheet3"util.sheetRemove(address, True)

Remove all sheet, except more one

address.Doc = ThisComponentaddress.Sheet = Array("Sheet2", "Sheet6")util.sheetRemove(address, True)

Move sheet

Move sheet by name to pos.

util = createUnoService("org.universolibre.EasyDev")address = createUnoStruct("org.universolibre.EasyDev.CellRangeAddress")

address.Doc = ThisComponentaddress.Sheet = "Sheet2"util.sheetMove(address, 0)

Move first sheet to last pos

address.Doc = ThisComponentaddress.Sheet = 0util.sheetMove(address, -1)

Move sheet by object

44 Chapter 8. Calc

EasyDev Documentation, Release 2.0.0

address.Doc = ThisComponentaddress.Sheet = 1sheet = util.getSheet(address)address.Sheet = sheetutil.sheetMove(address, -1)

Move more one sheet

address.Doc = ThisComponentaddress.Sheet = Array ("Sheet2", "Sheet4")util.sheetMove(address, -1)

Sort sheets

Sort sheets by name.

util.sheetSort(ThisComponent, True)

Sort in reverse.

util.sheetSort(ThisComponent, False)

Copy sheet

Important: if you not use rename argument, you first valid if new name sheet not exists with method: hasByName

Copy sheet by name to last pos.

util = createUnoService("org.universolibre.EasyDev")address = createUnoStruct("org.universolibre.EasyDev.CellRangeAddress")

address.Doc = ThisComponentaddress.Sheet = "Sheet2"util.sheetCopy(address, "NewName", -1, False)

Copy sheet by index to pos.

address.Doc = ThisComponentaddress.Sheet = 0util.sheetCopy(address, "OtherName", -1, False)

Copy sheet by index to pos and rename if exists

address.Doc = ThisComponentaddress.Sheet = 0util.sheetCopy(address, "NameX", -1, True)

Copy more one sheet, rename is ommited, always is true

8.7. Sort sheets 45

EasyDev Documentation, Release 2.0.0

address.Doc = ThisComponentaddress.Sheet = Array("Sheet1", "Sheet2")util.sheetCopy(address, "NameY", -1, True)

Copy all sheets, rename is ommited, always is true

address.Doc = ThisComponentaddress.Sheet = ""util.sheetCopy(address, "NameNext", -1, False)

Copy sheet to document

Important: The origin document must be saved before copy sheet

sheetCopyToDoc(SOURCE, TARGET, POSITION, RENAME, BY_VALUE)

Source and targe are struct org.universolibre.EasyDev.CellRangeAddress

• SOURCE: Document and sheet origin

• TARGET: Target document

• POSITION: Target position for example first position (0) or last position (-1)

• RENAME: If exists sheet name in target, rename sheet origin

• BY_VALUE: False, copy by formula, True, copy by values.

Copy all sheets from source to target document.

util = createUnoService("org.universolibre.EasyDev")source = createUnoStruct("org.universolibre.EasyDev.CellRangeAddress")target = createUnoStruct("org.universolibre.EasyDev.CellRangeAddress")

doc = ThisComponentsource.Doc = doc

new_doc = util.newDoc("")target.Doc = new_doc

util.sheetCopyToDoc(source, target, -1, True, False)

Copy sheet by name.

doc = ThisComponentsource.Doc = docsource.Sheet = "Source"new_doc = util.newDoc("")target.Doc = new_doc

util.sheetCopyToDoc(source, target, -1, True, False)

Copy sheet by index

46 Chapter 8. Calc

EasyDev Documentation, Release 2.0.0

doc = ThisComponentsource.Doc = docsource.Sheet = 1new_doc = util.newDoc("")target.Doc = new_doc

util.sheetCopyToDoc(source, target, -1, True, False)

Copy more one sheet

doc = ThisComponentsource.Doc = docsource.Sheet = Array(0, "Source")new_doc = util.newDoc("")target.Doc = new_doc

util.sheetCopyToDoc(source, target, -1, True, False)

Copy sheet by value

doc = ThisComponentsource.Doc = docsource.Sheet = "Source"new_doc = util.newDoc("")target.Doc = new_doc

util.sheetCopyToDoc(source, target, -1, True, True)

Rename sheet

Rename sheet by name.

util = createUnoService("org.universolibre.EasyDev")address = createUnoStruct("org.universolibre.EasyDev.CellRangeAddress")

address.Doc = ThisComponentaddress.Sheet = "Sheet2"util.sheetName(address, "Two")

Rename sheet by index.

address.Doc = ThisComponentaddress.Sheet = 0util.sheetName(address, "First")

Rename more one sheet.

address.Doc = ThisComponentaddress.Sheet = Array(0, "Sheet3")util.sheetName(address, "NewName")

Show or hidden sheet

8.10. Rename sheet 47

EasyDev Documentation, Release 2.0.0

Important: If you try hide all sheets, not get error, but always at least one sheet will be visible

Hidden sheet by name.

util = createUnoService("org.universolibre.EasyDev")address = createUnoStruct("org.universolibre.EasyDev.CellRangeAddress")

address.Doc = ThisComponentaddress.Sheet = "Sheet2"util.sheetVisible(address, False)

Hidden first sheet.

address.Doc = ThisComponentaddress.Sheet = 0util.sheetVisible(address, False)

Hidden last sheet.

address.Doc = ThisComponentaddress.Sheet = -1util.sheetVisible(address, False)

Hidden all sheets, except one

sheets = util.getSheetsNames(ThisComponent)'First show sheetaddress.Doc = ThisComponentaddress.Sheet = sheets(0)util.sheetVisible(address, True)'Remove sheet from arraysheets = util.delete(sheets, 0)'And hide the rest of sheetsaddress.Sheet = sheetsutil.sheetVisible(address, False)

Show al sheets

sheets = util.getSheetsNames(ThisComponent)address.Doc = ThisComponentaddress.Sheet = sheetsutil.sheetVisible(address, True)

Sheet password

Set password by name.

util = createUnoService("org.universolibre.EasyDev")address = createUnoStruct("org.universolibre.EasyDev.CellRangeAddress")

address.Doc = ThisComponentaddress.Sheet = "Sheet2"util.sheetPassword(address, "letmein", False)

48 Chapter 8. Calc

EasyDev Documentation, Release 2.0.0

Set password by index.

address.Doc = ThisComponentaddress.Sheet = -1util.sheetPassword(address, "letmein", False)

Set password all sheet.

address.Doc = ThisComponentaddress.Sheet = ""util.sheetPassword(address, "letmein", False)

Remove password all sheet.

address.Doc = ThisComponentaddress.Sheet = ""util.sheetPassword(address, "letmein", True)

Cells

Get active cell, always back only one cell

Sub getCellDoc()util = createUnoService("org.universolibre.EasyDev")address = createUnoStruct("org.universolibre.EasyDev.CellRangeAddress")

address.Current = Truecell = util.getCell(address)msg = util.format("{} {}", Array(cell.ImplementationName, cell.AbsoluteName))util.msgbox(msg)

End Sub

Get active cell from document by title name, document must be open

address.Doc = "test.ods" 'Title docaddress.Current = Truecell = util.getCell(address)msg = util.format("{} {}", Array(cell.ImplementationName, cell.AbsoluteName))util.msgbox(msg)

Get active cell from object doc

doc = util.getDoc("")address.Doc = docaddress.Current = Truecell = util.getCell(address)msg = util.format("{} {}", Array(cell.ImplementationName, cell.AbsoluteName))util.msgbox(msg)

Get cell from object doc, sheet by name, cell by name

doc = util.getDoc("")address.Doc = docaddress.Sheet = "Sheet2"address.Name = "B5"cell = util.getCell(address)

8.13. Cells 49

EasyDev Documentation, Release 2.0.0

msg = util.format("{} {}", Array(cell.ImplementationName, cell.AbsoluteName))util.msgbox(msg)

Get cell from object doc, sheet by name, cell by col, row

doc = util.getDoc("")address.Doc = docaddress.Sheet = "Sheet2"address.Name = ""address.Col = 1address.Row = 4cell = util.getCell(address)msg = util.format("{} {}", Array(cell.ImplementationName, cell.AbsoluteName))util.msgbox(msg)

Get cell from object sheet, object doc is ommited

sheet = doc.getCurrentController().getActiveSheet()address.Sheet = sheetaddress.Name = "D5"cell = util.getCell(address)msg = util.format("{} {}", Array(cell.ImplementationName, cell.AbsoluteName))util.msgbox(msg)

Ranges

Get active range

Sub getRangeDoc()util = createUnoService("org.universolibre.EasyDev")address = createUnoStruct("org.universolibre.EasyDev.CellRangeAddress")

address.Current = Truerange = util.getRange(address)msg = util.format("{} {}", Array(range.ImplementationName, range.AbsoluteName))util.msgbox(msg)

End Sub

Get active range from document by title name, document must be open

address.Doc = "test.ods" 'Title docaddress.Current = Truerange = util.getRange(address)msg = util.format("{} {}", Array(range.ImplementationName, range.AbsoluteName))util.msgbox(msg)

Get active range from object doc

doc = util.getDoc("")address.Doc = docaddress.Current = Truerange = util.getRange(address)msg = util.format("{} {}", Array(range.ImplementationName, range.AbsoluteName))util.msgbox(msg)

50 Chapter 8. Calc

EasyDev Documentation, Release 2.0.0

Get range from object doc, sheet by name, range by name

doc = util.getDoc("")address.Doc = docaddress.Sheet = "Sheet2"address.Name = "B5:C10"range = util.getRange(address)msg = util.format("{} {}", Array(range.ImplementationName, range.AbsoluteName))util.msgbox(msg)

Get range from object doc, sheet by name, range by position

address.Sheet = "Sheet2"address.Name = ""address.Col = 1address.Row = 4address.EndCol = 3address.EndRow = 9range = util.getRange(address)msg = util.format("{} {}", Array(range.ImplementationName, range.AbsoluteName))util.msgbox(msg)

Get range from object sheet, object doc is ommited.

sheet = doc.getCurrentController().getActiveSheet()address.Sheet = sheetaddress.Name = "D5:E10"range = util.getRange(address)msg = util.format("{} {}", Array(range.ImplementationName, range.AbsoluteName))util.msgbox(msg)

Add ranges into container.

util = createUnoService("org.universolibre.EasyDev")address = createUnoStruct("org.universolibre.EasyDev.CellRangeAddress")

address.Doc = ThisComponentaddress.Sheet = "Sheet1"address.Name = "A1:B2"range = util.getRange(address)'Create container, first argument is a documentcontainer = util.addRanges(ThisComponent, range)MsgBox container.getRangeAddressesAsString()

'Add range to containeraddress.Name = "A4:B5"range = util.getRange(address)'First argument is a container, previously createdcontainer = util.addRanges(container, range)MsgBox container.getRangeAddressesAsString()

Initial container from more one cell range

address.Doc = ThisComponentaddress.Sheet = "Sheet1"address.Name = "B1:C2"r1 = util.getRange(address)address.Name = "B4:C4"r2 = util.getRange(address)

8.14. Ranges 51

EasyDev Documentation, Release 2.0.0

address.Name = "D6:E6"r3 = util.getRange(address)ranges = Array(r1, r2, r3)

'Create container, first argument is a documentcontainer = util.addRanges(ThisComponent, ranges)MsgBox container.getRangeAddressesAsString()

Remove ranges from container.

r = util.removeRanges(container, r2)MsgBox container.getRangeAddressesAsString()

Get all columns from cell range, get a container.

doc = ThisComponent

address.Doc = docaddress.Sheet = "Sheet1"address.Name = "B1:E1"range = util.getRange(address)

columns = util.getColumns(ThisComponent, range)

util.selectRange(doc, columns)

Get all rows from cell range, get a container.

doc = ThisComponent

address.Doc = docaddress.Sheet = "Sheet1"address.Name = "A5:A10"range = util.getRange(address)

rows = util.getRows(ThisComponent, range)

util.selectRange(doc, rows)

Select range

Sub SelectRange()util = createUnoService("org.universolibre.EasyDev")address = createUnoStruct("org.universolibre.EasyDev.CellRangeAddress")

doc = util.getDoc("")address.Doc = docaddress.Sheet = "Sheet2"address.Name = "B5:C10"range = util.getRange(address)

'Selectutil.selectRange(doc, range)

End Sub

52 Chapter 8. Calc

EasyDev Documentation, Release 2.0.0

Current region

Sub getCurrentRegion()

util = createUnoService("org.universolibre.EasyDev")address = createUnoStruct("org.universolibre.EasyDev.CellRangeAddress")

address.Current = Truecell = util.getCell(address)msg = util.format("{} {}", Array(cell.ImplementationName, cell.AbsoluteName))util.msgbox(msg)

End Sub

Only one cell into current region is necesary, get cursor

cursor = util.getCurrentRegion(cell, True)msg = util.format("{} {}", Array(cursor.ImplementationName, cursor.AbsoluteName))util.msgbox(msg)

Only one cell into current region is necesary, get range

range = util.getCurrentRegion(cell, False)msg = util.format("{} {}", Array(range.ImplementationName, range.AbsoluteName))util.msgbox(msg)

Get empty cells

util = createUnoService("org.universolibre.EasyDev")address = createUnoStruct("org.universolibre.EasyDev.CellRangeAddress")

'Get active cell, always get one celladdress.Current = Truecell = util.getCell(address)

ranges = util.getEmpty(cell)util.selectRange(ThisComponent, ranges)

Get visible cells

util = createUnoService("org.universolibre.EasyDev")address = createUnoStruct("org.universolibre.EasyDev.CellRangeAddress")

'Get active cell, always get one celladdress.Current = Truecell = util.getCell(address)

ranges = util.getVisible(cell)util.selectRange(ThisComponent, ranges)

8.16. Current region 53

EasyDev Documentation, Release 2.0.0

Last row

Get last row into current region.

Sub getLastRow()util = createUnoService("org.universolibre.EasyDev")address = createUnoStruct("org.universolibre.EasyDev.CellRangeAddress")

address.Current = Truecell = util.getCell(address)row = util.getLastRow(cell)util.msgbox(row)

End Sub

Next value

In range values. Get nex value in relative column (0), or (1), etc.

Sub getNextID()util = createUnoService("org.universolibre.EasyDev")address = createUnoStruct("org.universolibre.EasyDev.CellRangeAddress")

address.Current = Truecell = util.getCell(address)value = util.getNextID(cell, 0)util.msgbox(value)

End Sub

Cell value

Automatically detect type: string, value or formula.

54 Chapter 8. Calc

EasyDev Documentation, Release 2.0.0

Sub CellValue()util = createUnoService("org.universolibre.EasyDev")address = createUnoStruct("org.universolibre.EasyDev.CellRangeAddress")

address.Current = Truecell = util.getCell(address)

value = "String"util.setValue(cell, value)value = util.getValue(cell)util.msgbox(value)

value = 12345util.setValue(cell, value)value = util.getValue(cell)util.msgbox(value)

value = "=SUM(A1:C1)"util.setValue(cell, value)value = util.getValue(cell)util.msgbox(value)

End Sub

Set data

Automatically calculate width and height of data size.

Sub SetData()util = createUnoService("org.universolibre.EasyDev")address = createUnoStruct("org.universolibre.EasyDev.CellRangeAddress")

'Get active cell, always get one celladdress.Current = Truecell = util.getCell(address)

data = Array( _Array(1, "Uno", "Tres"), _Array(2, "Dos", "Cuatro"), _Array(3, "Tres", "Cinco"), _

)'Automatically calculate width and height of data sizeutil.setData(cell, data)

End Sub

Get data

Get data array from cell, automatically get current region. Get hidden cells inclusive.

util = createUnoService("org.universolibre.EasyDev")address = createUnoStruct("org.universolibre.EasyDev.CellRangeAddress")

8.22. Set data 55

EasyDev Documentation, Release 2.0.0

'Get active cell, always get one celladdress.Current = Truecell = util.getCell(address)

data = util.getData(cell, False)util.msgbox(data)

Get data array, only visible cells.

data = util.getData(cell, True)util.msgbox(data)

56 Chapter 8. Calc

CHAPTER 9

Writer

Paragraphs

Get all paragraphs in document.

Sub GetParagraps()util = createUnoService("org.universolibre.EasyDev")

'Get current docdoc = util.getDoc("")

'Get all paragraphsparagraphs = util.getParagraphs(doc, True)util.msgbox(util.len(paragraphs))

End Sub

Get paragraphs with text

paragraphs = util.getParagraphs(doc, False)util.msgbox(util.len(paragraphs))

57

EasyDev Documentation, Release 2.0.0

58 Chapter 9. Writer

CHAPTER 10

Data Base

Connection DB

Connect to register DB in Base.

Sub ConnectDB()db_name = "test"user = ""pass = ""con = util.conDB(db_name, user, pass)

util.msgbox(con.isClosed())End Sub

Verify if exists.

db_name = "test"MsgBox util.existsDB(db_name)

If exists, get path location.

db_name = "test"If util.existsDB(db_name) Then

MsgBox util.getPathDB(db_name)End If

Create DB and register in Base.

path_db = "/home/USER/dbtest.odb"db_name = "TestOne"util.newDB(path_db)util.registerDB(db_name, path_db)

Revoke register DB.

59

EasyDev Documentation, Release 2.0.0

db_name = "test"util.revokeDB(db_name)

ODBC

I test connection with: MySQL, PostgreSQL, SQLite and MSSQL.

Sub ConexionODBC()

util = createUnoService("org.universolibre.EasyDev")

odbc = "ConSQL"user = "sa"passw = "letmein"

con = util.conODBC(odbc, user, passw)

util.msgbox(con)

End Sub

Query

Make query, get data like array

odbc = "ODBCSQLITE"user = ""passw = ""con = util.conODBC(odbc, user, passw)

sql = "SELECT * FROM contactos"data = util.query(con, sql, True)util.msgbox(data)

Make query, get data like resulset

sql = "SELECT * FROM contactos"data = util.query(con, sql, False)util.msgbox(data)

You can set resulset to grid, see Grid.

Update

Insert data.

sql = "INSERT INTO ""directory"" VALUES (6, 'Nikole Kidman', '1970-01-15',→˓'[email protected]')"row = util.update(con, sql)util.msgbox(row)

60 Chapter 10. Data Base

EasyDev Documentation, Release 2.0.0

Update data.

sql = "UPDATE ""directory"" SET ""email""='[email protected]' WHERE ""id""=6"row = util.update(con, sql)util.msgbox(row)

Delete data.

sql = "DELETE FROM ""directory"" WHERE ""id""=5"row = util.update(con, sql)util.msgbox(row)

10.4. Update 61

EasyDev Documentation, Release 2.0.0

62 Chapter 10. Data Base

CHAPTER 11

Charts

Chart XY

Create chart from next data.

Sub addChartXY()Dim pos_size As New com.sun.star.awt.RectangleDim series(1) As New org.universolibre.EasyDev.ChartSerieutil = createUnoService("org.universolibre.EasyDev")

address = createUnoStruct("org.universolibre.EasyDev.CellRangeAddress")data = createUnoStruct("org.universolibre.EasyDev.ChartData")

doc = ThisComponentaddress.Doc = doc

properties = Array( _Array("Color", RGB(255,0,0)), _Array("LineWidth", 100), _

)

63

EasyDev Documentation, Release 2.0.0

series(0).X = "Hoja1.A2:A9"series(0).Y = "Hoja1.B2:B9"series(0).Title = "Hoja1.B1"series(0).Properties = properties

properties = Array( _Array("Color", RGB(255,255,0)), _Array("LineWidth", 50), _

)series(1).X = "Hoja1.C2:C9"series(1).Y = "Hoja1.D2:D9"series(1).Title = "Hoja1.D1"series(1).Properties = properties

pos_size.X = 0pos_size.Y = 5000pos_size.Width = 12000pos_size.Height = 7000

data.Doc = docdata.Sheet = util.getSheet(address)data.Name = "Grafico01"data.Type = "XYDiagram"data.PosSize = pos_sizedata.Series = series

chart = util.chartAdd(data)End Sub

Result.

64 Chapter 11. Charts

EasyDev Documentation, Release 2.0.0

You can use range objects

Dim pos_size As New com.sun.star.awt.RectangleDim series(1) As New org.universolibre.EasyDev.ChartSerieutil = createUnoService("org.universolibre.EasyDev")

address = createUnoStruct("org.universolibre.EasyDev.CellRangeAddress")data = createUnoStruct("org.universolibre.EasyDev.ChartData")

doc = ThisComponentaddress.Doc = docaddress.Sheet = "Hoja1"address.Col = 0address.Row = 1address.EndCol = 0address.EndRow = 8rango_X = util.getRange(address)

address.Col = 1address.EndCol = 1rango_Y = util.getRange(address)

address.Col = 1address.Row = 0title_1 = util.getCell(address)

11.1. Chart XY 65

EasyDev Documentation, Release 2.0.0

properties = Array( _Array("Color", RGB(255,0,0)), _Array("LineWidth", 100), _

)

series(0).X = rango_Xseries(0).Y = rango_Yseries(0).Title = title_1series(0).Properties = properties

properties = Array( _Array("Color", RGB(255,255,0)), _

)series(1).X = "Hoja1.C2:C9"series(1).Y = "Hoja1.D2:D9"series(1).Title = "Hoja1.D1"series(1).Properties = properties

pos_size.X = 0pos_size.Y = 5000pos_size.Width = 12000pos_size.Height = 7000

data.Doc = docdata.Sheet = util.getSheet(address)data.Name = "Grafico01"data.Type = "XYDiagram"data.PosSize = pos_sizedata.Series = series

chart = util.chartAdd(data)

66 Chapter 11. Charts

CHAPTER 12

Images and shapes

Insert image

Insert image from path, image link

util = createUnoService("org.universolibre.EasyDev")data = createUnoStruct("org.universolibre.EasyDev.ImageData")rec = createUnoStruct("com.sun.star.awt.Rectangle")

rec.X = 1000rec.Y = 1000rec.Width = 4000rec.Height = 4000doc = ThisComponentdata.Doc = docdata.Sheet = 0data.Path = "/home/mau/Pictures/mylove.png"data.Name = "With Link"data.Link = Truedata.PosSize = recimage = util.imageAdd(data)

Result.

67

EasyDev Documentation, Release 2.0.0

Insert image from path, image embebbed

util = createUnoService("org.universolibre.EasyDev")data = createUnoStruct("org.universolibre.EasyDev.ImageData")rec = createUnoStruct("com.sun.star.awt.Rectangle")

rec.X = 1000rec.Y = 1000rec.Width = 4000rec.Height = 4000doc = ThisComponentdata.Doc = docdata.Sheet = 0data.Path = "/home/mau/Pictures/mylove.png"data.Name = "unLink"

'Embebbed imagedata.Link = Falsedata.PosSize = recimage = util.imageAdd(data)

Insert image and add text.

68 Chapter 12. Images and shapes

EasyDev Documentation, Release 2.0.0

util = createUnoService("org.universolibre.EasyDev")data = createUnoStruct("org.universolibre.EasyDev.ImageData")rec = createUnoStruct("com.sun.star.awt.Rectangle")

properties = Array( _Array("String", "My Love"), _Array("CharColor", RGB(255,0,0)), _Array("CharHeight", 20), _Array("CharWeight", 150), _

)

rec.X = 1000rec.Y = 1000rec.Width = 4000rec.Height = 4000doc = ThisComponentdata.Doc = docdata.Sheet = 0data.Path = "/home/mau/Pictures/mylove.png"data.Name = "MyLove"data.Link = Falsedata.PosSize = recdata.Properties = propertiesimage = util.imageAdd(data)

Insert shape

Insert a rectangle

rec.X = 1000rec.Y = 1000rec.Width = 4000rec.Height = 4000doc = ThisComponentdata.Doc = docdata.Sheet = 0data.Name = "MyRec"

12.2. Insert shape 69

EasyDev Documentation, Release 2.0.0

data.Type = "Rectangle"data.PosSize = recshape = util.imageAdd(data)

Insert ellipse

properties = Array( _Array("String", "Python!!"), _Array("CharColor", RGB(255,255,0)), _Array("CharHeight", 20), _Array("CharWeight", 150), _

)rec.X = 1000rec.Y = 1000rec.Width = 4000rec.Height = 4000doc = ThisComponentdata.Doc = docdata.Sheet = 0data.Name = "MyEllipse"data.Type = "Ellipse"data.PosSize = recdata.Properties = propertiesshape = util.imageAdd(data)

Insert line

properties = Array( _Array("LineColor", RGB(255,100,0)), _Array("LineWidth", 200), _

)rec.X = 1000rec.Y = 1000rec.Width = 4000rec.Height = 4000doc = ThisComponentdata.Doc = docdata.Sheet = 0data.Name = "MyLine"data.Type = "Line"data.PosSize = recdata.Properties = propertiesshape = util.imageAdd(data)

Insert text.

properties = Array( _Array("String", "Power Python!"), _Array("CharHeight", 20), _Array("CharWeight", 150, _

)rec.X = 1000rec.Y = 1000rec.Width = 5000rec.Height = 1000doc = ThisComponentdata.Doc = docdata.Sheet = 0

70 Chapter 12. Images and shapes

EasyDev Documentation, Release 2.0.0

data.Name = "MyText"data.Type = "Text"data.PosSize = recdata.Properties = propertiesshape = util.imageAdd(data)

12.2. Insert shape 71

EasyDev Documentation, Release 2.0.0

72 Chapter 12. Images and shapes

CHAPTER 13

Dialogs

Create dialog

Create dialog from path.

Sub CreateDialogutil = createUnoService("org.universolibre.EasyDev")

path = "/home/USER/dlg_test.xdl"dlg = util.createDialog(path)dlg.execute()dlg.dispose()

End Sub

Create dialog from Library, default library is Standard

macro = createUnoStruct("org.universolibre.EasyDev.Macro")macro.Dialog = "Dialog1"

73

EasyDev Documentation, Release 2.0.0

dlg = util.createDialog(macro)

'Use other librarymacro.Library = "MyLibrary"macro.Dialog = "MyDialog"

dlg = util.createDialog(macro)

Note: If dialog is into document, use standard method createUnoDialog

Label hyperlink

Automatic add event mouse over

path = "/home/USER/dlg_test.xdl"dlg = util.createDialog(path)

properties = Array( _Array("Name", "link_home"), _Array("PositionX", 100), _Array("PositionY", 10), _Array("URL", "http://universolibre.org"), _Array("Label", "http://universolibre.org"), _

)util.createControl(dlg, "FixedHyperlink", properties)dlg.execute()dlg.dispose()

Roadmap

Add menu options, automatic add event item change for update property Step in dialog.

74 Chapter 13. Dialogs

EasyDev Documentation, Release 2.0.0

path = "/home/USER/dlg_test.xdl"dlg = util.createDialog(path)

options = Array("Init", "Values", "Config", "Other")properties = Array( _

Array("Name", "roadmap"), _Array("Width", 50), _Array("Height", 150), _Array("Options", options), _

)util.createControl(dlg, "Roadmap", properties)dlg.execute()dlg.dispose()

Grid

Create grid and set data from array. Detect column values and format.

13.4. Grid 75

EasyDev Documentation, Release 2.0.0

c1 = Array( _Array("Title", "State"), _Array("HorizontalAlign", 0), _

)c2 = Array( _

Array("Title", "People"), _Array("HorizontalAlign", 2), _Array("Identifier", True), _

)columns = Array(c1, c2)properties = Array( _

Array("Name", "grid"), _Array("PositionX", 100), _Array("PositionY", 50), _Array("Step", 4), _Array("Columns", columns), _

)grid = util.createControl(dlg, "Grid", properties)

data = Array( _Array("Uno", 2222), _Array("Tres", 44444), _Array("Cinco", 666666), _Array("Siete", 666666), _

)col_format = Array()util.setGridData(grid, data, col_format)

dlg.execute()dlg.dispose()

Add data from range cells.

data = ThisComponent.getCurrentSelection().getDataarray()col_format = Array()util.setGridData(grid, data, col_format)

Set data from query, see Query.

76 Chapter 13. Dialogs

EasyDev Documentation, Release 2.0.0

odbc = "TESTODBCSQLITE"user = ""passw = ""

con = util.conODBC(odbc, user, passw)

sql = "SELECT id, name FROM contactos"data = util.query(con, sql, False)properties = Array( _

Array("Name", "grid"), _Array("PositionX", 10), _Array("PositionY", 10), _Array("Columns", Array()) _

)grid = util.createControl(dlg, "Grid", properties)util.setQuery(grid, data, True)

Change default format for columns with values.

data = ThisComponent.getCurrentSelection().getDataarray()

'Default formatutil.numfmt = "$ {0:,.2f}"

col_format = Array()util.setGridData(grid, data, col_format)

Or change format for each column.

data = ThisComponent.getCurrentSelection().getDataarray()col_format = Array("{}", "$ {0:,.2f}")util.setGridData(grid, data, col_format)

And get data grid in array.

data = util.getGridData(grid, Array())util.msgbox(data)

TextBox

Create text box, automatic change background color in focus events.

13.5. TextBox 77

EasyDev Documentation, Release 2.0.0

properties = Array( _Array("Name", "txt_name"), _Array("PositionX", 10), _Array("PositionY", 10), _

)util.createControl(dlg, "Edit", properties)dlg.execute()dlg.dispose()

You can change default background color. Change color before create control.

util.colorOnFocus = RGB(229, 255, 204)

CommandButton

Create command button and assigned macro to execute. Default library is Standard. For default, the macro nameexecute is: CONTROL_NAME + _action, in this example:

Sub cmd_test_action(event):MsgBox event.Source.Model.Name

End Sub

Argument event is important.

macro.Language = "Basic"macro.Module = "LODialog"properties = Array( _

Array("Name", "cmd_test"), _Array("PositionX", 10), _Array("PositionY", 60), _Array("Macro", macro), _

)util.createControl(dlg, "Button", properties)

78 Chapter 13. Dialogs

CHAPTER 14

Indices and tables

• genindex

• modindex

• search

79