Macros/Calc/py001/da

From The Document Foundation Wiki
< Macros‎ | Calc
Jump to navigation Jump to search
This page is a translated version of the page Macros/Calc/py001 and the translation is 100% complete.

Template:Menu.Macros/da

Other languages:
English • ‎dansk • ‎español

Beskrivelse

Kopiér indholdsceller fra et regneark til et andet. Kilderegnearket skal være åbent.

Python-kode

 1import uno
 2from com.sun.star.table.CellContentType import TEXT, VALUE
 3
 4
 5def 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