Macros/Calc/py001

From The Document Foundation Wiki
< Macros‎ | Calc
Jump to: navigation, search
Other languages:
dansk • ‎English • ‎español

Description

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

Python code

 1 import uno
 2 from com.sun.star.table.CellContentType import TEXT, VALUE
 3 
 4 
 5 def copy_cell():
 6     doc_source_name = 'source.ods'
 7     sheet_source_name = 'source'
 8     cell_source_name = 'A1'
 9 
10     desktop = XSCRIPTCONTEXT.getDesktop()
11     for doc_source in desktop.Components:
12         if doc_source.Title == doc_source_name:
13             break
14 
15     cell_source = doc_source.Sheets[sheet_source_name][cell_source_name]
16 
17     doc = XSCRIPTCONTEXT.getDocument()
18     cell = doc.CurrentController.ActiveSheet[cell_source_name]
19 
20     if cell_source.Type == TEXT:
21         cell.String = cell_source.String
22     elif cell_source.Type == VALUE:
23         cell.Value = cell_source.Value
24     else:
25         cell.Formula = cell_source.Formula
26     return