Macros/Calc/py001

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.
Other languages:
English • ‎dansk • ‎español • ‎italiano

Descrizione

Copia la cella del contenuto da un foglio di calcolo ad altro. Il foglio di calcolo originale dovrebbe essere aperto.

Codice Python

 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