マクロ/Calc/py001

    From The Document Foundation Wiki
    < Macros‎ | Calc
    This page is a translated version of the page Macros/Calc/py001 and the translation is 40% complete.
    Other languages:

    説明

    セルの内容をスプレッドシートから別のスプレッドシートにコピーします。スプレッドシートは開いている必要があります。

    Python code

    import uno
    from com.sun.star.table.CellContentType import TEXT, VALUE
    </div>
    
    
    <div lang="en" dir="ltr" class="mw-content-ltr">
    def copy_cell():
        doc_source_name = 'source.ods'
        sheet_source_name = 'source'
        cell_source_name = 'A1'
    </div>
    
        <div lang="en" dir="ltr" class="mw-content-ltr">
    desktop = XSCRIPTCONTEXT.getDesktop()
        for doc_source in desktop.Components:
            if doc_source.Title == doc_source_name:
                break
    </div>
    
        <div lang="en" dir="ltr" class="mw-content-ltr">
    cell_source = doc_source.Sheets[sheet_source_name][cell_source_name]
    </div>
    
        <div lang="en" dir="ltr" class="mw-content-ltr">
    doc = XSCRIPTCONTEXT.getDocument()
        cell = doc.CurrentController.ActiveSheet[cell_source_name]
    </div>
    
        <div lang="en" dir="ltr" class="mw-content-ltr">
    if cell_source.Type == TEXT:
            cell.String = cell_source.String
        elif cell_source.Type == VALUE:
            cell.Value = cell_source.Value
        else:
            cell.Formula = cell_source.Formula
        return