Copia la cella del contenuto da un foglio di calcolo ad altro

From The Document Foundation Wiki
< Macros‎ | Calc
Jump to navigation Jump to search
This page is a translated version of the page Macros/Calc/ba001 and the translation is 100% complete.
Other languages:
English • ‎dansk • ‎español • ‎italiano


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

Codice in Basic

Sub main()
DOC_NAME_SOURCE = "source.ods"

    doc_source = get_doc(DOC_NAME_SOURCE)
    sheet_source = doc_source.Sheets.getByName(SHEET_NAME_SOURCE)
    cell_source = sheet_source.getCellRangeByName(CELL_NAME_SOURCE)

    doc = ThisComponent
    sheet = doc.CurrentController.ActiveSheet
    cell = sheet.getCellRangeByName(CELL_NAME_SOURCE)
    If cell_source.Type = 1 Then
        cell.Value = cell_source.Value
    ElseIf cell_source.Type = 2 Then
        cell.String = cell_source.String
        cell.Formula = cell_source.Formula
    End If
End Sub

Function get_doc(title)
    docs = StarDesktop.getComponents()
    enumeration = docs.createEnumeration()
    Do While enumeration.hasMoreElements()
        doc = enumeration.nextElement()
        If doc.Title = title Then
            Exit Do
        End If
    get_doc = doc
End Function