매크로/파이썬 가이드/나의 첫 매크로

    From The Document Foundation Wiki
    This page is a translated version of the page Macros/Python Guide/My first macro and the translation is 39% complete.


    색인으로 돌아가기


    나의 첫 파이썬 매크로

    All Python examples are stored as PC-based personal macros, as opposed to product Python scripts or document-based scripts. Any example in this guide assumes that you save in this place.

    IMPORTANT Python's syntax is very strict, be sure copy and paste correctly.

    Use your favorite text editor, or better an IDE to edit your code.

    라이터(Writer)용 매크로

    import uno
    
    def my_first_macro_writer():
        doc = XSCRIPTCONTEXT.getDocument()
        text = doc.getText()  # com.sun.star.text.Text
        text.setString('<span lang="en" dir="ltr" class="mw-content-ltr">Hello World in Python in Writer</span>')
        return

    캘크(Calc)용 매크로

    import uno
    
    def my_first_macro_calc():
        doc = XSCRIPTCONTEXT.getDocument()
        cell = doc.Sheets[0]['A1']  # com.sun.star.sheet.XSpreadsheetDocument
        cell.setString('<span lang="en" dir="ltr" class="mw-content-ltr">Hello World in Python in Calc</span>')
        return


    실행 매크로

    For Writer

    • Open Writer, go to Tools ▸ Macros ▸ Run macro... in section Library select mymacros (or your name file), in section Macro Name, select macro my_first_macro_writer and click in command button Run

    Demo Writer

    For Calc

    • Open calc, go to Tools ▸ Macros ▸ Run macro... in section Library select mymacros (or your name file), in section Macro Name, select macro my_first_macro_calc and click in command button Run

    Demo Calc

    색인으로 돌아가기