月別アーカイブ: 2013年12月

Libre:012 複数のワークシートを追加する

Excelの場合、Sheets.add count =2

などとして、2つのシートを一度に追加できますが、

Libreではできないようです。

同じシート名で追加しようとするとエラーになりますので、

For文で回すときにシート名を変えています。

 

Sub ksSheetsAdd

 for a = 1 to 2

 ThisComponent.Sheets.insertNewByName(“test”& a , 2)

 next a

End Sub

Libre:009 ブックを拡大表示する

ブックの拡大は、画面右下のスライダーで変更可能です。

これをコードで変更したい場合は、以下のコードで可能

です。

 

sub ksZoom

Dim controller As Object
Dim doc as object

doc = ThisComponent
controller = doc.getCurrentController()
controller.ZoomType = 3
controller.ZoomValue = 175

end sub

Excelの場合、Variant型で柔軟性があります。

少し複雑ですが、初心者には使いやすいでしょうかね。

Libreの場合、ZoomTypeとZoomValue ともにShort型です。単純です。

 

 

ZoomTypeは以下のとおりです。

 

OPTIMAL = 0  

The page content width (excluding margins) at the current selection is fit into the view.

 

PAGE_WIDTH = 1

The page width at the current selection is fit into the view.  

 

ENTIRE_PAGEA = 2

complete page of the document is fit into the view.

 

BY_VALUE = 3

The zoom is relative and is to be set via the property ViewSettings::ZoomValue.

 

PAGE_WIDTH_EXACT = 4

The page width at the current selection is fit into the view,

with zhe view ends exactly at the end of the page.  

SetPosSizeの一番後ろの数字に関して

画面サイズを設定する時、以下のコードを使用しましたが、

一番後ろの数字について説明しなかったので、補足します。

vWindow.setPosSize(intXPos, intYPos, intWidth, intHeight, 15)

 

 

Description

These constants are used to flag the parameters of a rectangle.

 

X = 1 flags the x-coordinate.

Y = 2 flags the y-coordinate.

WIDTH = 4 flags the width.

HEIGHT = 8 flags the height.

POS = 3 flags the x- and y-coordinate.

SIZE = 12  flags the width and height.

POSSIZE = 15 flags the x- and y-coordinate, width and height.

 

 つまり、Flagを1にセットすると、X軸だけ変更を受けつることになります。

Libre:008 ブックを非表示にする−2

もう一つ、非表示にする方法は、

画面の外に追い出しておくということも考えられます。

005で示したコードで座標を画面の外側に設定すれば

かくれるはずです。

Sub hideWindow


 dim vFrame as Object
 dim vWindow as Object
 dim vRect as Object
 dim intHeight as Integer
 dim intWidth as Integer
 dim intXPos as Integer
 dim intYPos as Integer

  vFrame = StarDesktop.getCurrentFrame()
  vWindow = vFrame.getContainerWindow()
  vRect = vWindow.getPosSize() 

’ここを変更

  intXPos= -2000 ‘vRect.X 

  intYPos= 0 ‘vRect.Y


  intHeight= 712
  intWidth= 1024
  vWindow.setPosSize(intXPos, intYPos, intWidth, intHeight, 15)

End Sub

しかし、Excelではうまくいくこの方法はLibreではうまく行きませんでした。

40pixほどは表示されてしまいます。

そこで、HeightとWidthを変更します。

intHeight= vRect.Height
intWidth= vRect.Width

if intHeight = 0 OR intWidth = 0 then
 intHeight = 200
 intWidth = 200

else
 intHeight= 0
 intWidth= 0

end if

これで、画面からウィンドウを消すことができます。

消したウインドウは、もう一度このマクロを走らせれば、

表示されるようになります。

Libre:007 ブックを非表示にする−1

ここにもExcelとの違いがあります。

Excelの場合、

activeWindow.visible = False

とすると非表示になりますが、

メニューから再表示を選択することで

windowは復元されます。

 

しかし、liber では復元されないようです。

どちらかと言えば、「ウィンドウを閉じる」

だと言えます。

 

sub windowVisible

dim vFrame as Object
dim vWindow as Object

vFrame = StarDesktop.getCurrentFrame()
vWindow = vFrame.getContainerWindow() 

vWindow.SetVisible(False)

end sub

画面を更新しない

画面の更新をしない:

ThisComponent.addActionLock()

 

画面の更新を再開する:

ThisComponent.removeActionLock() 

 

ここにシートへの高速アクセスで書かれていますが、

VBAでは画面の更新を止めるとより高速に

動作します。

Libreでも、効果的です。

しかし、基本的にLibre basicは実行速度が遅いので

十分ではありません。

Libre:006 表示サイズの最大値を取得する

Libre officeでは、ウインドウとシートの区別が

ありませんので、表示サイズの最大値は画面サイズに

なります。

 

表示サイズの最大値を得るためには、003で示した

フルサイズ表示させたあと、その画面サイズを

取得することになります。

 

sub ksDisplayWindowSize

dim vFrame as Object
dim vWindow as Object
dim vRect as Object
dim intHeight as Integer
dim intWidth as Integer

vFrame = StarDesktop.getCurrentFrame()
vWindow = vFrame.getContainerWindow()
vRect = vWindow.getPosSize()
intHeight= vRect.Height
intWidth= vRect.Width

msgbox(“height” & intHeight & “: width”& intWidth)


end sub


Sub ksFullScreen

document = ThisComponent.CurrentController.Frame

dispatcher = createUnoService(“com.sun.star.frame.DispatchHelper”)

dim args1(0) as new com.sun.star.beans.PropertyValue

args1(0).Name = “FullScreen”

args1(0).Value = true

dispatcher.executeDispatch(document, “.uno:FullScreen”, “”, 0, args1())

ksDisplayWindowSize

End Sub

Libre:005 ブックの位置表示を指定する

004と同様にLibreOfficeでは指定できないと思われます。

002と同様の方法でWindowの位置は設定できます。

 

Sub ksWindowPosition 
  dim vFrame as Object 
  dim vWindow as Object 
  dim vRect as Object 
  dim intHeight as Integer 
  dim intWidth as Integer 
  dim intXPos as Integer 
  dim intYPos as Integer 

  vFrame = StarDesktop.getCurrentFrame() 
  vWindow = vFrame.getContainerWindow() 
  vRect = vWindow.getPosSize() 

  intXPos= 100  <———xポジション
  intYPos= 100  <———yポジション

  intHeight= vRect.Height
  intWidth= vRect.Width 

  vWindow.setPosSize(intXPos, intYPos, intWidth, intHeight, 15)

End Sub