Macros/Math/001
Appearance
TDF LibreOffice Document Liberation Project Community Blogs Weblate Nextcloud Redmine Ask LibreOffice Donate
説明
これから作成するすべての式の属性を変更する場合は、Faq/Math/008 で説明されている手順に従うだけです。"after the fact" に変更する場合は、すべての式を再度開いて変更する必要があります。式の数が多い場合、これはすぐに面倒な作業になります。
このスクリプトは、埋め込まれた数式オブジェクトを選択します。[1]のAPIドキュメントを参照し、目的の数式プロパティを更新します。[2]のAPIドキュメントを参照してください。 このマクロは問題 i#5092 を解決します。
Ask121655 では、(少し)別なアプローチが提供されています。
Code
Python スクリプトまたは LibreOffice Basic マクロの使用:
# coding: utf-8
from __future__ import unicode_literals
import uno
# from com.sun.star.document import OfficeDocument
FRAME_DESKTOP = 'com.sun.star.frame.Desktop'
FORMULA_PROPERTIES = 'com.sun.star.formula.FormulaProperties'
class UIFormulaCollection():
""" 現在のドキュメントの数式コレクション """
def __init__(self):
""" デフォルトでUIの現在のドキュメントを取り込む """
# ctx = uno.getComponentContext() # GetDefaultContext
# smgr = ctx.getServiceManager() # GetProcessServiceManager
# desktop = smgr.createInstanceWithContext(FRAME_DESKTOP, ctx) # StarDesktop
# self.doc = desktop.CurrentComponent # ThisComponent
self.doc = XSCRIPTCONTEXT.getDocument()
self.objects = self.doc.EmbeddedObjects
self.names = self.objects.getElementNames()
def reformat(self, fontHeight=None, font=None):
""" 必要な数のプロパティを追加する """
for name in self.names:
element = self.objects.getByName(name).Model
if element.supportsService(FORMULA_PROPERTIES):
if font:
element.FontNameFunctions = font
element.FontNameText = font
element.FontNameNumbers = font
element.FontNameVariables = font
if fontHeight:
element.BaseFontHeight = fontHeight
self.doc.reformat()
def reformatAllFormulas():
ui = UIFormulaCollection()
ui.reformat(font="Arial", fontHeight=14)
g_exportedScripts = reformatAllFormulas,
Option Explicit
Sub ChangeFormulasSizeAndFont()
'''ドキュメント内のすべての数式のサイズまたはフォントを変更する'''
Dim element As Object ' com.sun.star.text.TextEmbeddedObject.Model
Dim realElem As Object ' com.sun.star.text.TextEmbeddedObject.(get)EmbeddedObject
For each element in ThisComponent.getEmbeddedObjects()
If (not isNull(element.Model)) Then
With element.Model
If .supportsService("com.sun.star.formula.FormulaProperties") Then
' Force the update
realElem = element.EmbeddedObject
realElem.updateMode = com.sun.star.embed.EmbedUpdateModes.ALWAYS_UPDATE
.BaseFontHeight = 14
.FontNameVariables = "Arial"
.FontNameFunctions = "Arial"
.FontNameNumbers = "Arial"
.FontNameText = "Arial"
End If
End With ' element As com.sun.star.formula.FormulaProperties
End If
Next element
ThisComponent.reformat()
End Sub ' ChangeFormulasSizeAndFont
マクロテスト用の ODS ファイル
テスト用に、LibreOffice published Math guide を選択してください。
メモ
- 変更可能なその他のプロパティについては、
FormulaProperties
に関するAPIドキュメントを参照してください。
- ↑ ドキュメント内の com.sun.star.text.TextEmbeddedObjects およびcom.sun.star.text.TextEmbeddedObject services
- ↑ com.sun.star.formula.FormulaProperties service