マクロ/Writer/006
Appearance
TDF LibreOffice Document Liberation Project Community Blogs Weblate Nextcloud Redmine Ask LibreOffice Donate
説明
目次(インデックスの一種)などのインデックスは、変更が行われた後に更新されないという問題がよくあります。ドキュメントは誤ったリンクで送信される可能性があります。
このマクロは、インデックス内のリンクを自動的に更新します。マクロを Save document(文書を保存する時) (
▸ ▸ ▸ ) コマンドにリンクすると、ドキュメントの保存時にリンクが更新されるので便利です。目次の例では、さまざまなヘッダー(右クリックや
▸ ,などによって割り当てられる)を含むドキュメントを作成したとします。次に、 ▸ ▸ によって目次を挿入します。さらにヘッダーを追加する場合は、このマクロを実行するだけで目次を更新できます。
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()