BASICなら簡単に外部実行できる。
成果物
コード
soffice macro:///Standard.Module1.Main
Sub Main MsgBox("マクロのテストです。") End Sub
BASICファイル作成
BASICのコードは以下の手順で作成した。
- LibreOffice Calc を起動する
- メニュー→
マクロ
→マクロの編集
マイマクロ&ダイアログ
→Standard
→Module1
- 画面右のテキストエディタにコードを書く
- 保存する(
Ctrl
+S
キー押下)
BASICファイルパス確認
問題はこの手順で作成したBASICファイルのパスがどこなのか不明なこと。以下のようにパスを確認しようとしたが、出力されない。
Sub Main If ThisComponent.HasLocation() Then Print "The Document URL is " & ThisComponent.getURL() Else Print "The document has not yet been stored" End If MsgBox(StarDesktop.CurrentComponent.getURL & "\n" & ThisComponent.getURL & "\nマクロのテストです。\n") End Sub
自力で探したらあった。以下のパス。
~/.config/libreoffice/4/user/basic/Standard/Module1.xba
ただ、なぜかXML形式の中にBASICコードが入っている。しかもそのせいでサニタイズまでされてる。これじゃ直接編集できないじゃないか……。
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> <script:module xmlns:script="http://openoffice.org/2000/script" script:name="Module1" script:language="StarBasic">Sub Main If ThisComponent.HasLocation() Then Print "The Document URL is " & ThisComponent.getURL() Else Print "The document has not yet been stored" End If MsgBox(StarDesktop.CurrentComponent.getURL & "\n" & ThisComponent.getURL & "\nマクロのテストです。\n") End Sub </script:module>
所感
Pythonもこれで実行できたら楽でよかったのに……。
BASICなんて書きたくない。End Sub
とかクソすぎて発狂しそう。終わってる。でもMsgBox
は圧倒的にスマート。
対象環境
- Raspbierry pi 4 Model B
- Raspbian buster 10.0 2019-09-26 ※
- bash 5.0.3(1)-release 学習まとめ
- LibreOffice 6.1.5.2 ※
$ uname -a Linux raspberrypi 4.19.97-v7l+ #1294 SMP Thu Jan 30 13:21:14 GMT 2020 armv7l GNU/Linux