Insert a comment with custom presets

From The Document Foundation Wiki
< Macros‎ | Calc
Jump to: navigation, search
This page contains changes which are not marked for translation.

Other languages:
English • ‎español


Description

Copy content cell from Spreadsheet to other. The spreadsheet source should be open.

Basic code

 1 Sub main()
 2 DOC_NAME_SOURCE = "source.ods"
 3 SHEET_NAME_SOURCE = "source"
 4 CELL_NAME_SOURCE = "A1"
 5 
 6     doc_source = get_doc(DOC_NAME_SOURCE)
 7     sheet_source = doc_source.Sheets.getByName(SHEET_NAME_SOURCE)
 8     cell_source = sheet_source.getCellRangeByName(CELL_NAME_SOURCE)
 9 
10     doc = ThisComponent
11     sheet = doc.CurrentController.ActiveSheet
12     cell = sheet.getCellRangeByName(CELL_NAME_SOURCE)
13  
14     If cell_source.Type = 1 Then
15         cell.Value = cell_source.Value
16     ElseIf cell_source.Type = 2 Then
17         cell.String = cell_source.String
18     Else
19         cell.Formula = cell_source.Formula
20     End If
21 End Sub
22 
23 Function get_doc(title)
24     docs = StarDesktop.getComponents()
25     enumeration = docs.createEnumeration()
26     Do While enumeration.hasMoreElements()
27         doc = enumeration.nextElement()
28         If doc.Title = title Then
29             Exit Do
30         End If
31     Loop
32     get_doc = doc
33 End Function