0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

LibreOfficeのユーザー定義関数(UDF)

Last updated at Posted at 2025-01-16

内容

LibreOffice calc でユーザ定義関数を作成する

=MYFUNC(C1:D1) みたいなやつ

結論

以下の通り
https://forum.openoffice.org/en/forum/viewtopic.php?t=56899

作りかた

basicの場合

Tools -> Macros -> Organize Macros -> Basic...
でポップアップが表示される

ドキュメントにnewでモジュールを追加してこんなのを書くと

function mysum(r)
	on error resume next
	dim f
	dim c
	dim ans
	f = flattenRange(r)
	
	ans = 0
	for each c in f
		ans = ans + clng(c)
	next
	mysum = ans
end function

=MYSUM(D3:E5)
こんな感じで使用出来る

flattenRangeは毎回使用すると思うので
上記リンク先のをMy Macros内に書いておく
配布するならドキュメント内に書く

数値以外も読むようにしたflattenRangeのコード
Function flattenRange(r)

	Dim i as Long
	Dim j as Long
	Dim Size(2) as Integer
	Dim element
	Dim n As Long
	Dim v(0)
	Dim aRow
	Size(1) = UBound(r,1)-LBound(r,1)
	Size(2) = UBound(r,2)-LBound(r,2)
	'v = r(LBound(r),1)
	n = 0
	for i = 0 to Size(1)
		for j = 0 to Size(2)
			ReDim Preserve v(n)
			if isNumeric(r(LBound(r, 1) + i, LBound(r, 2) + j)) then 
				element = r(LBound(r, 1) + i, LBound(r, 2) + j)
			else
				element = r(LBound(r, 1) + i, LBound(r, 2) + j)
			endif
			v(n) = element
			n = n + 1
		Next j
	Next i
			
	flattenRange = v
end function

javascriptの場合

GUIでモジュールは作成出来ない
→createしてもエラーになる

一応odsをunzipしてファイル追加して固めれば行けるみたい

ただしラッパーが必要なのと初回ロード時に必ずエラー(ダイアログ)が表示されるので
あまり実用的ではない

pythonの場合

GUIでモジュールを配置するディレクトリが作成出来ない
→createボタンがそもそも押せない

javascriptと同じような感じでやってみたが
macroのセキュリティエラーが出てだめだった
→Lowでもだめ

その他

wps officeは無料だとマクロが使えない
softmakerも同じく
gnumericはそもそもマクロが無い

なので無料でマクロが利用出来るものとなると
open officeLibre officeしかない
Libre officeはopen officeを元に作られているので
あまり差は無いようだが使ってみた感じ
マクロに関してはLibre officeの方が良さそうだった

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?