Jump to content

マクロ/Writer/006

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


説明

目次(インデックスの一種)などのインデックスは、変更が行われた後に更新されないという問題がよくあります。ドキュメントは誤ったリンクで送信される可能性があります。

このマクロは、インデックス内のリンクを自動的に更新します。マクロを Save document(文書を保存する時) (ツール ▸ カスタマイズ ▸ イベント ▸ 文書を保存する時) コマンドにリンクすると、ドキュメントの保存時にリンクが更新されるので便利です。

目次の例では、さまざまなヘッダー(右クリックや段落 ▸ 見出し1,などによって割り当てられる)を含むドキュメントを作成したとします。次に、挿入 ▸ 目次と索引 ▸ 目次、索引または参考文献... によって目次を挿入します。さらにヘッダーを追加する場合は、このマクロを実行するだけで目次を更新できます。


Code

Option Explicit

Sub UpdateIndexes
    '''目次などの索引を更新する'''

    Dim i As Integer

    With ThisComponent ' Writerドキュメントのみを処理
        If .supportsService("com.sun.star.text.GenericTextDocument") Then
            For i = 0 To .getDocumentIndexes().count - 1
                .getDocumentIndexes().getByIndex(i).update()     
            Next i
        End If
    End With ' ThisComponent

End Sub ' UpdateIndexes
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import uno

def インデックスの更新():
    """目次などの索引を更新する"""

    thisComponent = XSCRIPTCONTEXT.getDocument()
    if thisComponent.supportsService("com.sun.star.text.GenericTextDocument"):
        count = thisComponent.getDocumentIndexes().getCount()
        for i in range(0,count):
            thisComponent.getDocumentIndexes().getByIndex(i).update()