Jump to content

Zellinhalt von einem Tabellenblatt in ein anderes kopieren

From The Document Foundation Wiki
This page is a translated version of the page Macros/Calc/ba001 and the translation is 100% complete.



Beschreibung

Zellinhalt von einem Tabellenblatt in ein anderes kopieren

Basic Code

Sub main()
DOC_NAME_SOURCE = "source.ods"
SHEET_NAME_SOURCE = "source"
CELL_NAME_SOURCE = "A1"

    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
    Else
        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
    Loop
    get_doc = doc
End Function