Home > OpenOffice.org > OpenOffice.org Calc で選択範囲に合わせた×を直線で追加するマクロ

OpenOffice.org Calc で選択範囲に合わせた×を直線で追加するマクロ

みようみまねで OpenOffice.org Calc で
選択範囲に合わせた×を直線で追加するマクロをかいてみた。

いらない子には×を与えよう。

'選択範囲に合わせた×を直線で追加する
'本家	http://docs.sun.com/app/docs/doc/819-1332/faaim?a=view
sub DrawX
	'範囲の取得
	dim oDoc	as object
	dim oRange	as object

	oDoc = StarDesktop.CurrentComponent	'このコードを実行しているドキュメントを返す
	oRange = oDoc.CurrentSelection
	if not oRange.supportsService("com.sun.star.sheet.SheetCellRange") then exit sub

	'直線の作成
	dim margin	as long
	dim aPoint	as new com.sun.star.awt.Point
	dim aSize	as new com.sun.star.awt.Size
	dim oRD		as object
	dim oRU		as object

	margin = 20

	'左上→右下
	with oRange
		aPoint.X = .Position.X + margin
		aPoint.Y = .Position.Y + margin
		aSize.Width = .Size.Width - 2 * margin
		aSize.Height = .Size.Height - 2 * margin
	end with
	oRD = oDoc.createInstance("com.sun.star.drawing.LineShape")
	oRD.setPosition(aPoint)
	oRD.setSize(aSize)

	'左下→右上
	with oRange
		aPoint.X = .Position.X + margin
		aPoint.Y = .Position.Y + .Size.Height - margin
		aSize.Width = .Size.Width - 2 * margin
		aSize.Height = -(.Size.Height - 2 * margin)
	end with
	oRU = oDoc.createInstance("com.sun.star.drawing.LineShape")
	oRU.setPosition(aPoint)
	oRU.setSize(aSize)

	'ページに追加
	dim oSheet	as object
	dim oPage	as object

	oSheet = oDoc.CurrentController.ActiveSheet
	oPage = oSheet.DrawPage
	oPage.add(oRD)
	oPage.add(oRU)

	'グループ化
	dim oShapes	as object
	dim oGroup	as object
	oShapes = createUnoService("com.sun.star.drawing.ShapeCollection")
	oShapes.add(oRD)
	oShapes.add(oRU)
	oGroup = oPage.group(oShapes)
end sub

かじゅ OpenOffice.org ,

  1. No comments yet.
  1. No trackbacks yet.