Cell操作
[ Basic ]
[ Insert・Delete.Copy ]
[ Property(Cellの書式設定) ]
{{ Format }}
{{ Font }}
{{ Font Effet }}[ Refer to "Font / 文字関連の Property 一覧" ]
{{ Position / Size }}
{{ Color }}
[ Clear ]
[ Selection ]
[ Address(セル番地) ]
Cell操作
[ Basic ]
#!
#coding: utf-8
# python Marco
import uno, sys, traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',oMsgType='messbox'):
"""shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MESSAGEBOX, 1, oTitle, oMessage)
return msgbox.execute()
def oTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet =oDoc.getSheets().getByIndex(0)
oCell = oSheet.getCellByPosition(0,0)
oCell.String = 'MacroTest'
oDisp = 'A1セルに文字を入力'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp,1,'LO7.0.4.2')
【 解説 】
A1セルに文字を代入するマクロのコードです。
Pythonマクロは関数( def )を呼出して実行 します。
上記のコードでは oTest を Mainコードとして呼出して実行。
R1C1形式のセルアドレスで入力するマクロのコードです。
行列の指定は (列,行) である事に注意。
Indexは 0 から始まります。
メッセージボックス( def omsgbox())のコードの詳細は General No.1 参照
#!
#coding: utf-8
# python Marco
import uno, sys, traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',oMsgType='messbox'):
"""shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MESSAGEBOX, 1, oTitle, oMessage)
return msgbox.execute()
def oTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet =oDoc.getSheets().getByIndex(0)
oSheet.getCellByPosition(0,0).Value = 1
oSheet.getCellByPosition(0,1).Value = 2
oSheet.getCellByPosition(0,2).Formula = "=sum(A1:A2)"
#A3セルの数式を確認する為、A3セルを選択
oCtrl = oDoc.getCurrentController()
oSelRange = oSheet.getCellByPosition(0,2)
oCtrl.select(oSelRange)
#
oDisp = '値と式を入力'
except ExceptA1ion as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp,1,'LO7.0.4.2')
【 解説 】
セルに値と式を入力するマクロのコードです。
文字列で .String プロパティを使いましたが
値:.Value
式:.Formula
プロパティを利用します。
.String / .Value / .Formula についてはLibreOffice Basic編の Calc No.1 参照
#!
#coding: utf-8
# python Marco
import uno, sys, traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',oMsgType='messbox'):
"""shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MESSAGEBOX, 1, oTitle, oMessage)
return msgbox.execute()
def oTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet =oDoc.getSheets().getByName('Sheet1')
oSheet.getCellRangeByName('A1').Value = 1
oSheet.getCellRangeByName('A2').Value = 2
oSheet.getCellRangeByName('A3').Formula = "=sum(A1:A2)"
oSheet.getCellRangeByName('A4').String = 'LibreOffice'
#A3セルの数式を確認する為、A3セルを選択
oCtrl = oDoc.getCurrentController()
oSelRange = oSheet.getCellRangeByName('A3')
oCtrl.select(oSelRange)
#
oDisp = 'A1形式でCell Addressを指定'
except ExceptA1ion as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp,1,'LO7.0.4.2')
【 解説 】
A1形式のセルアドレスで入力するマクロのコードです。
シート名でシート指定:.getByName()
A1形式でCellアドレス:.getCellRangeByName()
#!
#coding: utf-8
# python Marco
import uno, sys, traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',oMsgType='messbox'):
"""shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MESSAGEBOX, 1, oTitle, oMessage)
return msgbox.execute()
def oTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet =oDoc.getSheets().getByIndex(0)
oDisp = '[ Cell 値取得 ]'
for i in range(0, 5):
oCell =oSheet.getCellByPosition(0, i )
oCellType = oCell.getType()
if oCellType == uno.Enum('com.sun.star.table.CellContentType', 'EMPTY'):
oVal = '空白です。'
elif oCellType == uno.Enum('com.sun.star.table.CellContentType', 'VALUE'):
oVal = oCell.Value
elif oCellType == uno.Enum('com.sun.star.table.CellContentType', 'TEXT'):
oVal = oCell.String
elif oCellType == uno.Enum('com.sun.star.table.CellContentType', 'FORMULA'):
oVal = oCell.Formula
else:
oVal = '不正な型のDataです。'
#
oDisp = oDisp + '\n A' + str(i+1) + ' Cell の値 : ' + str(oVal)
except ExceptA1ion as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp,1,'LO7.0.4.2')
【 解説 】
入力値の形式によって入力値を取得しています.
入力値の形式に関わらず .Valueで取得した場合、
文字列と空白は取得値は 0 となる。
[ Insert・Delete.Copy ]
#!
#coding: utf-8
# python Marco
import uno
import sys
import traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',MsgType=MESSAGEBOX):
# """shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MsgType, oBtnType, oTitle, oMessage)
return msgbox.execute()
def oMacroTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet =oDoc.getSheets().getByName('sheet1')
#
oCellRangeAddr = uno.createUnoStruct('com.sun.star.table.CellRangeAddress')
oCellRangeAddr.Sheet = 0
oCellRangeAddr.StartColumn = 2
oCellRangeAddr.StartRow = 2
oCellRangeAddr.EndColumn = 4
oCellRangeAddr.EndRow = 4
oSheet.insertCells(oCellRangeAddr, 1) # com.sun.star.sheet.CellInsertMode.DOWN
oDisp = 'Success'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp)
#!
#coding: utf-8
# python Marco
import uno
import sys
import traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',MsgType=MESSAGEBOX):
# """shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MsgType, oBtnType, oTitle, oMessage)
return msgbox.execute()
def oMacroTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet =oDoc.getSheets().getByName('sheet1')
#
oCellRangeAddr = uno.createUnoStruct('com.sun.star.table.CellRangeAddress')
oCellRangeAddr.Sheet = 0
oCellRangeAddr.StartColumn = 2
oCellRangeAddr.StartRow = 2
oCellRangeAddr.EndColumn = 4
oCellRangeAddr.EndRow = 4
oSheet.insertCells(oCellRangeAddr, 2) # com.sun.star.sheet.CellInsertMode.RIGHT
oDisp = 'Success'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp)
#!
#coding: utf-8
# python Marco
import uno
import sys
import traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',MsgType=MESSAGEBOX):
# """shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MsgType, oBtnType, oTitle, oMessage)
return msgbox.execute()
def oMacroTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet =oDoc.getSheets().getByName('sheet1')
#
oCellRangeAddr = uno.createUnoStruct('com.sun.star.table.CellRangeAddress')
oCellRangeAddr.Sheet = 0
oCellRangeAddr.StartColumn = 2
oCellRangeAddr.StartRow = 2
oCellRangeAddr.EndColumn = 4
oCellRangeAddr.EndRow = 4
oSheet.insertCells(oCellRangeAddr, 3) # com.sun.star.sheet.CellInsertMode.ROW
oDisp = 'Success'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp)
#!
#coding: utf-8
# python Marco
import uno
import sys
import traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',MsgType=MESSAGEBOX):
# """shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MsgType, oBtnType, oTitle, oMessage)
return msgbox.execute()
def oMacroTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet =oDoc.getSheets().getByName('sheet1')
#
oCellRangeAddr = uno.createUnoStruct('com.sun.star.table.CellRangeAddress')
oCellRangeAddr.Sheet = 0
oCellRangeAddr.StartColumn = 2
oCellRangeAddr.StartRow = 2
oCellRangeAddr.EndColumn = 4
oCellRangeAddr.EndRow = 4
oSheet.insertCells(oCellRangeAddr, 4) # com.sun.star.sheet.CellInsertMode.COLUMNS
oDisp = 'Success'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp)
#!
#coding: utf-8
# python Marco
from com.sun.star.beans import PropertyValue
import uno
import sys
import traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',MsgType=MESSAGEBOX):
# """shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MsgType, oBtnType, oTitle, oMessage)
return msgbox.execute()
def oMacroTest():
try:
ctx = XSCRIPTCONTEXT.getComponentContext()
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
dispatchHelper = ctx.ServiceManager.createInstanceWithContext( 'com.sun.star.frame.DispatchHelper', ctx )
# B2へ移動
oProp = PropertyValue()
oProp.Name = 'ToPoint'
oProp.Value = 'C3:E5'
properties = (oProp,)
dispatchHelper.executeDispatch( frame, '.uno:GoToCell', '', 0, properties )
#
oProp.Name = 'Flags'
oProp.Value = 'V'
properties = (oProp,)
dispatchHelper.executeDispatch( frame, '.uno:InsertCell', '', 0, properties )
oDisp = 'Success'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp)
#
# [ Note ]
# V : Cellを下に移動
# > : Cellを右に移動
# R : 行全体を下に移動
# C : 列全体を右に移動
#!
#coding: utf-8
# python Marco
import uno
import sys
import traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',MsgType=MESSAGEBOX):
# """shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MsgType, oBtnType, oTitle, oMessage)
return msgbox.execute()
def oMacroTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet =oDoc.getSheets().getByName('sheet1')
#
oCellRangeAddr = uno.createUnoStruct('com.sun.star.table.CellRangeAddress')
oCellRangeAddr.Sheet = 0
oCellRangeAddr.StartColumn = 2
oCellRangeAddr.StartRow = 2
oCellRangeAddr.EndColumn = 4
oCellRangeAddr.EndRow = 4
oSheet.removeRange(oCellRangeAddr, 1) # com.sun.star.sheet.CellDeleteMode.UP
oDisp = 'Success'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp)
#!
#coding: utf-8
# python Marco
import uno
import sys
import traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',MsgType=MESSAGEBOX):
# """shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MsgType, oBtnType, oTitle, oMessage)
return msgbox.execute()
def oMacroTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet =oDoc.getSheets().getByName('sheet1')
#
oCellRangeAddr = uno.createUnoStruct('com.sun.star.table.CellRangeAddress')
oCellRangeAddr.Sheet = 0
oCellRangeAddr.StartColumn = 2
oCellRangeAddr.StartRow = 2
oCellRangeAddr.EndColumn = 4
oCellRangeAddr.EndRow = 4
oSheet.removeRange(oCellRangeAddr, 2) # com.sun.star.sheet.CellDeleteMode.LEFT
oDisp = 'Success'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp)
#!
#coding: utf-8
# python Marco
import uno
import sys
import traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',MsgType=MESSAGEBOX):
# """shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MsgType, oBtnType, oTitle, oMessage)
return msgbox.execute()
def oMacroTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet =oDoc.getSheets().getByName('sheet1')
#
oCellRangeAddr = uno.createUnoStruct('com.sun.star.table.CellRangeAddress')
oCellRangeAddr.Sheet = 0
oCellRangeAddr.StartColumn = 2
oCellRangeAddr.StartRow = 2
oCellRangeAddr.EndColumn = 4
oCellRangeAddr.EndRow = 4
oSheet.removeRange(oCellRangeAddr, 3) # com.sun.star.sheet.CellDeleteMode.ROWS
oDisp = 'Success'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp)
#!
#coding: utf-8
# python Marco
import uno
import sys
import traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',MsgType=MESSAGEBOX):
# """shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MsgType, oBtnType, oTitle, oMessage)
return msgbox.execute()
def oMacroTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet =oDoc.getSheets().getByName('sheet1')
#
oCellRangeAddr = uno.createUnoStruct('com.sun.star.table.CellRangeAddress')
oCellRangeAddr.Sheet = 0
oCellRangeAddr.StartColumn = 2
oCellRangeAddr.StartRow = 2
oCellRangeAddr.EndColumn = 4
oCellRangeAddr.EndRow = 4
oSheet.removeRange(oCellRangeAddr, 4) # com.sun.star.sheet.CellDeleteMode.COLUMNS
oDisp = 'Success'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp)
#!
#coding: utf-8
# python Marco
from com.sun.star.beans import PropertyValue
import uno
import sys
import traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',MsgType=MESSAGEBOX):
# """shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MsgType, oBtnType, oTitle, oMessage)
return msgbox.execute()
def oMacroTest():
try:
ctx = XSCRIPTCONTEXT.getComponentContext()
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
dispatchHelper = ctx.ServiceManager.createInstanceWithContext( 'com.sun.star.frame.DispatchHelper', ctx )
# B2へ移動
oProp = PropertyValue()
oProp.Name = 'ToPoint'
oProp.Value = 'C3:E5'
properties = (oProp,)
dispatchHelper.executeDispatch( frame, '.uno:GoToCell', '', 0, properties )
#
oProp.Name = 'Flags'
oProp.Value = 'U'
properties = (oProp,)
dispatchHelper.executeDispatch( frame, '.uno:DeleteCell', '', 0, properties )
oDisp = 'Success'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp)
#
# [ Flag Value ]
# U : Cell を 上に移動
# L : Cell を 左に移動
# R : 行全体を削除
# C : 列全体を削除
#!
#coding: utf-8
# python Marco
import uno
import sys
import traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',MsgType=MESSAGEBOX):
# """shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MsgType, oBtnType, oTitle, oMessage)
return msgbox.execute()
def oMacroTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet =oDoc.getSheets().getByIndex(0)
#
oRangeAddress = oSheet.getCellRangeByName('B2:D4').getRangeAddress()
oCellAddress = oSheet.getCellByPosition(0,10).getCellAddress()
oSheet.copyRange(oCellAddress, oRangeAddress)
oDisp = 'Success'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp)
#!
#coding: utf-8
# python Marco
import uno
import sys
import traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',MsgType=MESSAGEBOX):
# """shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MsgType, oBtnType, oTitle, oMessage)
return msgbox.execute()
def oMacroTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet1 = oDoc.getSheets().getByIndex(0)
oSheet2 = oDoc.getSheets().getByIndex(1)
sCol = 0
eCol = 3
sRow = 0
eRow = 10
oCopyRange = oSheet1.getCellRangeByPosition(sCol, sRow, eCol, eRow)
oPasteRange = oSheet2.getCellRangeByPosition(sCol, sRow, eCol, eRow)
oCopyData = oCopyRange.getData()
oPasteRange.setData(oCopyData)
oDisp = 'Success'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp)
#!
#coding: utf-8
# python Marco
import uno
import sys
import traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',MsgType=MESSAGEBOX):
# """shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MsgType, oBtnType, oTitle, oMessage)
return msgbox.execute()
def oMacroTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet1 = oDoc.getSheets().getByIndex(0)
oSheet2 = oDoc.getSheets().getByIndex(1)
sCol = 0
eCol = 3
sRow = 0
eRow = 5
oCopyRange = oSheet1.getCellRangeByPosition(sCol, sRow, eCol, eRow)
oPasteRange = oSheet2.getCellRangeByPosition(sCol+1, sRow+1, eCol+1, eRow+1)
oCopyData = oCopyRange.getDataArray()
oPasteRange.setDataArray(oCopyData)
oDisp = 'Success'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp)
#!
#coding: utf-8
# python Marco
from com.sun.star.beans import PropertyValue
import uno
import sys
import traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',MsgType=MESSAGEBOX):
# """shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MsgType, oBtnType, oTitle, oMessage)
return msgbox.execute()
def oMacroTest():
try:
ctx = XSCRIPTCONTEXT.getComponentContext()
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
dispatchHelper = ctx.ServiceManager.createInstanceWithContext( 'com.sun.star.frame.DispatchHelper', ctx )
# Move A1 cell and Copy
oProp = PropertyValue()
oProp.Name = 'ToPoint'
oProp.Value = 'A1'
properties = (oProp,)
dispatchHelper.executeDispatch( frame, '.uno:GoToCell', '', 0, properties )
properties = ()
dispatchHelper.executeDispatch( frame, '.uno:Copy', '', 0, properties )
#
oProp = PropertyValue()
oProp.Name = 'ToPoint'
oProp.Value = 'B2'
properties = (oProp,)
dispatchHelper.executeDispatch( frame, '.uno:GoToCell', '', 0, properties )
# Initialize
oProp = []
oProp1 = PropertyValue()
oProp1.Name = 'Flags'
oProp1.Value = 'SDFNT'
oProp2 = PropertyValue()
oProp2.Name = 'FormulaCommand'
oProp2.Value = 0
oProp3 = PropertyValue()
oProp3.Name = 'SkipEmptyCells'
oProp3.Value = False # false : NG
oProp4 = PropertyValue()
oProp4.Name = 'Transpose'
oProp4.Value = False
oProp5 = PropertyValue()
oProp5.Name = 'AsLink'
oProp5.Value = False
oProp6 = PropertyValue()
oProp6.Name = 'MoveMode'
oProp6.Value = 4
oProp.append(oProp1)
oProp.append(oProp2)
oProp.append(oProp3)
oProp.append(oProp4)
oProp.append(oProp5)
oProp.append(oProp6)
properties = tuple(oProp)
dispatchHelper.executeDispatch( frame, '.uno:InsertContents', '', 0, properties )
oDisp = 'Success'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp)
#
# [ Flag Value ]
# S : String ( テキスト )
# V : Value ( 値 )
# D : Date ( 日付 )
# F : Formula ( 式 )
# N : Note ( コメント )
# T : Format ( 書式 )
# 空白 : Object ( オブジェクト )
# A : 全て
#!
#coding: utf-8
# python Marco
import os
import uno
import sys
import traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title'):
"""shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MESSAGEBOX, oBtnType, oTitle, oMessage)
return msgbox.execute()
def oWorkBook(filename):
desktop = XSCRIPTCONTEXT.getDesktop()
oComponents = desktop.getComponents()
oEnum = oComponents.createEnumeration()
while oEnum.hasMoreElements():
oComponent = oEnum.nextElement()
if oComponent.hasLocation():
if os.path.basename(oComponent.Location) == filename:
return oComponent
def oTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet = oDoc.getSheets().getByName("Sheet1")
oDoc2 = oWorkBook('GetComponent.ods')
oDisp = ''
if oDoc2 is None:
oDisp = 'Copy先のDocumentは開かれていません'
sys.exit([0])
oSheet2 = oDoc2.getSheets().getByName("Sheet1")
#
oCopyRange = oSheet.getCellRangeByName("A2:A4")
oPasteRange = oSheet2.getCellRangeByName("A2:A4")
#元のDocumentからコピー先に値をコピー
oCopyData = oCopyRange.getDataArray()
oPasteRange.setDataArray(oCopyData) # ※:式は値でコピーされる
#
#式をコピーする場合
oSheet2.getCellRangeByName("A5").Formula = oSheet.getCellRangeByName("A4").Formula
oDisp = 'Success'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp,1,'LO7.0.4.2')
[ Property(Cellの書式設定) ]

#!
#coding: utf-8
# python Marco
from com.sun.star.beans import PropertyValue
import uno
import sys
import traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',MsgType=MESSAGEBOX):
# """shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MsgType, oBtnType, oTitle, oMessage)
return msgbox.execute()
def oTest():
try:
ctx = XSCRIPTCONTEXT.getComponentContext()
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
dispatchHelper = ctx.ServiceManager.createInstanceWithContext( 'com.sun.star.frame.DispatchHelper', ctx )
#
oProp = PropertyValue()
properties = (oProp,)
dispatchHelper.executeDispatch( frame, '.uno:ResetAttributes', '', 0, properties )
oDisp = 'Success\n( Python )'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp,1)
{{ Format }}
#!
#coding: utf-8
# python Marco
from com.sun.star.beans import PropertyValue
import uno
import sys
import traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',MsgType=MESSAGEBOX):
# """shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MsgType, oBtnType, oTitle, oMessage)
return msgbox.execute()
def oMacroTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
#
oLocale = uno.createUnoStruct("com.sun.star.lang.Locale")
oLocale.Language = "ja"
oLocale.Country = "JP"
oNumberFormats = oDoc.NumberFormats
oList1 = ['#,##0','#,##0.#0','0%','0.00%','[$¥-411]#,##0;-[$¥-411]#,##0','[$¥-411]#,##0;[RED]-[$¥-411]#,##0']
oList2 = ['YYYY/MM/DD',u'YYYY年MM月DD日(AAAA)','GE.M.D','HH:MM','HH:MM:SS','0.00E+00','# ??/??']
oDF = oList1 + oList2
oDisp = u'[ 表示Key No ]'
for n in oDF:
oKeyNo = oNumberFormats.queryKey( n, oLocale, False ) # false : NG
oDisp = oDisp + '\n' + n + ' ⇒ ' + str(oKeyNo)
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp)
#!
#coding: utf-8
# python Marco
import uno
import sys
import traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',MsgType=MESSAGEBOX):
# """shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MsgType, oBtnType, oTitle, oMessage)
return msgbox.execute()
def oMacroTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet = oDoc.getSheets().getByName('sheet1')
oCell=oSheet.getCellRangeByName('A1')
#
oLocale = uno.createUnoStruct('com.sun.star.lang.Locale')
oLocale.Language = 'ja'
oLocale.Country = 'JP'
NumberFormats = oDoc.NumberFormats
NumberFormatString = u'#,##0.#0円'
NumberFormatId = NumberFormats.queryKey(NumberFormatString, oLocale, True)
if NumberFormatId == -1:
NumberFormatId = NumberFormats.addNew(NumberFormatString, oLocale) # 書式コードを追加
oCell.NumberFormat = NumberFormatId
oDisp = 'Success'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp)
#!
#coding: utf-8
# python Marco
import uno
import sys
import traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',MsgType=MESSAGEBOX):
# """shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MsgType, oBtnType, oTitle, oMessage)
return msgbox.execute()
def oMacroTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet = oDoc.getSheets().getByName('sheet1')
oCell=oSheet.getCellRangeByName('A1')
oCell.Value = 20000 # value : NG
oCell.NumberFormat = 10103
oDisp = 'Success'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp)
#!
#coding: utf-8
# python Marco
from com.sun.star.beans import PropertyValue
import uno
import sys
import traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',MsgType=MESSAGEBOX):
# """shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MsgType, oBtnType, oTitle, oMessage)
return msgbox.execute()
def oMacroTest():
try:
ctx = XSCRIPTCONTEXT.getComponentContext()
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
dispatchHelper = ctx.ServiceManager.createInstanceWithContext( 'com.sun.star.frame.DispatchHelper', ctx )
# A1へ移動
oProp = PropertyValue()
oProp.Name = 'ToPoint'
oProp.Value = 'A1'
properties = (oProp,)
dispatchHelper.executeDispatch( frame, '.uno:GoToCell', '', 0, properties )
#
oProp.Name = 'NumberFormatValue'
oProp.Value = 25
properties = (oProp,)
dispatchHelper.executeDispatch( frame, '.uno:NumberFormatValue', '', 0, properties )
oDisp = 'Success'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp)
#!
#coding: utf-8
# python Marco
import uno
import sys
import traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',MsgType=MESSAGEBOX):
# """shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MsgType, oBtnType, oTitle, oMessage)
return msgbox.execute()
def oMacroTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet = oDoc.getSheets().getByName('sheet1')
oCell=oSheet.getCellRangeByName('A1')
oCell.String = 'LibreOffice' # string : NG
oType = oCell.getType()
#
if oType == uno.Enum('com.sun.star.table.CellContentType', 'EMPTY'):
oDisp = 'Empty'
elif oType == uno.Enum('com.sun.star.table.CellContentType', 'VALUE'):
oDisp = 'Value'
elif oType == uno.Enum('com.sun.star.table.CellContentType', 'TEXT'):
oDisp = 'Text'
elif oType == uno.Enum('com.sun.star.table.CellContentType', 'FORMULA'):
oDisp = 'Formula'
else:
oDisp = 'UnKnown'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp)
#!
#coding: utf-8
# python Marco
from com.sun.star.beans import PropertyValue
import uno
import sys
import traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',MsgType=MESSAGEBOX):
# """shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MsgType, oBtnType, oTitle, oMessage)
return msgbox.execute()
def oMacroTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet = oDoc.getSheets().getByName('sheet1')
oCell=oSheet.getCellRangeByName('A1')
#
oUserAttr = uno.createUnoStruct('com.sun.star.xml.AttributeData')
# xray oUserAtrr
oUserAttr.Type ="CDATA"
oUserAttr.Value = "NewOOo3 macro"
oUserData = oCell.UserDefinedAttributes
#
if not oUserData.hasByName('home'):
oUserData.insertByName("home",oUserAttr)
oCell.UserDefinedAttributes = oUserData
# xray oUserData
oUser = oUserData.ElementNames
#
oDisp = '[ User Define Attributes ]'
for n in oUser:
oDisp = oDisp + '\n' + n
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp)
#!
#coding: utf-8
# python Marco
import uno
import sys
import traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',MsgType=MESSAGEBOX):
# """shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MsgType, oBtnType, oTitle, oMessage)
return msgbox.execute()
#
def ColumnNumberToString(nColumn):
oRtn = ''
while nColumn >= 0:
oAsc = 65 + (nColumn%26)
oReturn2= chr(oAsc)
oRtn = str(oReturn2) + oRtn
nColumn= int(nColumn / 26 - 1)
else:
return str(oRtn)
#
def oMacroTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet = oDoc.getSheets().getByName('sheet1')
oGetFormat = oSheet.getCellFormatRanges()
oDisp = '[ getCellFormatRanges() ]'
for i in range(oGetFormat.getCount()):
oSheetCellRange = oGetFormat.getByIndex(i)
oAddress = oSheetCellRange.getRangeAddress()
oDisp = oDisp + '\n\t\t' + str(i) + ' = Sheet' + str(oAddress.Sheet +1) + '.'
oDisp = oDisp + ColumnNumberToString(oAddress.StartColumn) + str(oAddress.StartRow + 1) + ':'
oDisp = oDisp + ColumnNumberToString(oAddress.EndColumn) + str(oAddress.EndRow + 1) + '\n'
#
oGetFormat = oSheet.getUniqueCellFormatRanges()
oDisp = oDisp + '\n[ getUniqueCellFormatRanges() ]'
for i in range(oGetFormat.getCount()):
oSheetUniqueRange = oGetFormat.getByIndex(i)
oDisp = oDisp + '\n\t\t' + str(i) + ' = ' + str(oSheetUniqueRange.getRangeAddressesAsString())
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp)
{{ Font }}
#!
#coding: utf-8
# python Marco
import uno
import sys
import traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',MsgType=MESSAGEBOX):
# """shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MsgType, oBtnType, oTitle, oMessage)
return msgbox.execute()
def oTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet =oDoc.getSheets().getByIndex(0)
oCell = oSheet.getCellByPosition(0,0)
oCell.String = u'Python マクロ for LibreOffice / ApacheOpenOffice'
oCell.IsTextWrapped = True
oDisp = 'Success\n( Python )'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp,1)

#!
#coding: utf-8
# python Marco
from com.sun.star.beans import PropertyValue
import uno
import sys
import traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title' ,MsgType=MESSAGEBOX):
# """shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MsgType, oBtnType, oTitle, oMessage)
return msgbox.execute()
def oTest():
try:
ctx = XSCRIPTCONTEXT.getComponentContext()
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
dispatchHelper = ctx.ServiceManager.createInstanceWithContext( 'com.sun.star.frame.DispatchHelper', ctx )
# A1へ移動
oProp = PropertyValue()
oProp.Name = 'ToPoint'
oProp.Value = 'A1'
properties = (oProp,)
dispatchHelper.executeDispatch( frame, '.uno:GoToCell', '', 0, properties )
oProp.Name = 'WrapText'
oProp.Value = True
properties = (oProp,)
dispatchHelper.executeDispatch( frame, '.uno:WrapText', '', 0, properties )
oDisp = ' Success\n [ dispatchHelper ]\n ( Python )'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp,1)
#!
#coding: utf-8
# python Marco
import uno
import sys
import traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
class cFontSlant():
from com.sun.star.awt.FontSlant import (NONE, ITALIC, REVERSE_ITALIC,OBLIQUE,)
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',MsgType=MESSAGEBOX):
# """shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MsgType, oBtnType, oTitle, oMessage)
return msgbox.execute()
def oMacroTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet = oDoc.getSheets().getByIndex(0)
oCell = oSheet.getCellByPosition(0,1)
oCell.String = '水 素はH2'
oCell.CharFontName = "Arial"
oCell.CharFontNameAsian = "Arial"
oCell.CharPosture = cFontSlant.ITALIC
oCell.CharPostureAsian = cFontSlant.OBLIQUE
oCell.CharHeight=40 # 英数字サイズは40(Cell単位での設定)
oCell.CharHeightAsian=20 # 日本語は20(Cell単位での設定)
oTextCursor = oCell.createTextCursor()
oTextCursor.gotoStart(False) # false : NG
oTextCursor.goRight(3, True)
oTextCursor.setPropertyValue('CharContoured', True ) #中抜き効果
oTextCursor.setPropertyValue('CharCrossedOut', True ) #取り消し線
oTextCursor.setPropertyValue('CharEmphasis',3) #強調文字 3は「・」の上付き、4は「、」の上付
oTextCursor.setPropertyValue('CharUnderlineColor', 2918503 ) #下線色 / 白抜きにしているので無意味
oTextCursor.setPropertyValue('CharUnderline',1) #UnderLine
oTextCursor.setPropertyValue('CharRelief',1) #浮き出し 0はNormal 1は浮き出し効果
oTextCursor.setPropertyValue('CharShadowed',True) #Shadow効果
oTextCursor.gotoEnd(False)
oDisp = 'Success'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp,1,u'Python/Font')
#!
#coding: utf-8
# python Marco
import uno
import sys
import traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',MsgType=MESSAGEBOX):
# """shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MsgType, oBtnType, oTitle, oMessage)
return msgbox.execute()
def oTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet = oDoc.getSheets().getByIndex(0)
oCell = oSheet.getCellByPosition(0,1)
oCell.String = '水素はH2'
oTextCursor = oCell.createTextCursor()
oTextCursor.gotoEnd( False ) # false : NG
oTextCursor.goLeft(1 , True )
oTextCursor.setPropertyValue('CharEscapement', -101 ) # ←下付は「-101」
oTextCursor.setPropertyValue('CharEscapementHeight', 80 ) # ←下付文字のサイズは80%としている。
oDisp = '\t Success\n\t ( Python )'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp,1)
# -*- coding: utf-8 -*-
import uno
import unohelper
import os.path
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',MsgType=MESSAGEBOX):
# """shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MsgType, oBtnType, oTitle, oMessage)
return msgbox.execute()
from com.sun.star.table import ShadowFormat
def oMacroTest():
try:
ofile= os.path.abspath('c:/temp/MacroCalc.ods')
if os.path.isfile(ofile): # If is Bad.
oURL = unohelper.systemPathToFileUrl(ofile)
desktop = XSCRIPTCONTEXT.getDesktop()
oDoc = desktop.loadComponentFromURL( oURL,"_blank", 0, () )
oSheet = oDoc.getSheets().getByIndex(0)
oCell = oSheet.getCellByPosition(0,0)
oCell.CellBackColor = 0xff0000 # 背景色⇒ RGBの16進数6桁で表示 0x + RGB(255,0,0)⇒ 0xff0000
else:
oDisp = str( ofile + ' => does not Exist!!')
omsgbox(oDisp)
except:
pass
#!
#coding: utf-8
# python Marco
from com.sun.star.beans import PropertyValue
import uno
import sys
import traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',MsgType=MESSAGEBOX):
# """shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MsgType, oBtnType, oTitle, oMessage)
return msgbox.execute()
def oTest():
try:
ctx = XSCRIPTCONTEXT.getComponentContext()
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
dispatchHelper = ctx.ServiceManager.createInstanceWithContext( 'com.sun.star.frame.DispatchHelper', ctx )
# A1へ移動
oProp = PropertyValue()
oProp.Name = 'ToPoint'
oProp.Value = 'A1'
properties = (oProp,)
dispatchHelper.executeDispatch( frame, '.uno:GoToCell', '', 0, properties )
oProp.Name = 'BackgroundPattern.BackColor'
oProp.Value = 0x00ff00 # RGB(0,255,0) ⇒ 0x00ff00
properties = (oProp,)
dispatchHelper.executeDispatch( frame, '.uno:BackgroundPattern', '', 0, properties )
oDisp = ' Success\n [ dispatchHelper ]\n ( Python )'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp,1)
#!
#coding: utf-8
# python Marco
import uno
import sys
import traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',MsgType=MESSAGEBOX):
# """shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MsgType, oBtnType, oTitle, oMessage)
return msgbox.execute()
def oTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet = oDoc.getSheets().getByName('sheet1')
oCell = []
for i in range(6):
oCell.append(oSheet.getCellByPosition(0,i))
oCell[i].String = 'Python'
oCell[0].RotateAngle = 2000 #20degree
oCell[1].RotateAngle = 4000
oCell[2].RotateAngle = 6000
oCell[3].RotateAngle = 9000
oCell[4].RotateAngle = -4500
oCell[5].RotateAngle = -9000
oDisp = '\t Success\n\t ( Python )'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp,1)
# -*- coding: utf-8 -*-
import uno
import unohelper
import os.path
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',MsgType=MESSAGEBOX):
# """shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MsgType, oBtnType, oTitle, oMessage)
return msgbox.execute()
from com.sun.star.table import ShadowFormat
def oMacroTest():
try:
ofile= os.path.abspath('c:/temp/MacroCalc.ods')
if os.path.isfile(ofile): # If is Bad.
oURL = unohelper.systemPathToFileUrl(ofile)
#
desktop = XSCRIPTCONTEXT.getDesktop()
oDoc = desktop.loadComponentFromURL( oURL,"_blank", 0, () )
#
oSheet = oDoc.getSheets().getByIndex(0)
#
oCell = oSheet.getCellByPosition(0,0)
#
oCell.String = 'MacroTest'
oCell.CharColor = 0xff0000 # 文字色=> RGBの16進数6桁で表示 0x + RGB(255,0,0)=> 0xff0000
oCell.CharHeight = 15 # 文字Size
oCell.CharWeight = 100 # 文字太さ
else:
oDisp = str( ofile + ' => does not Exist!!')
omsgbox(oDisp)
except:
pass
#!
#coding: utf-8
# python Marco
import uno
import sys, traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
from com.sun.star.beans import PropertyValue
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',oMsgType='messbox'):
"""shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MESSAGEBOX, 1, 'Title', oMessage)
return msgbox.execute()
def oTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet = oDoc.getSheets().getByIndex(0)
oCell = oSheet.getCellRangeByName("A1")
oCell.String = 'こんにちは。\n LO Ver4.2\n 3月27日\n ( 27は全角 )'
ctx = XSCRIPTCONTEXT.getComponentContext()
desktop = XSCRIPTCONTEXT.getDesktop()
oFrame = desktop.getCurrentFrame()
dispatchHelper = ctx.ServiceManager.createInstanceWithContext( 'com.sun.star.frame.DispatchHelper', ctx )
# A1へ移動
oProp = PropertyValue()
oProp.Name = 'ToPoint'
oProp.Value = 'A1'
properties = (oProp,)
oArray = ()
dispatchHelper.executeDispatch(oFrame, '.uno:GoToCell', '', 0, properties )
dispatchHelper.executeDispatch(oFrame, '.uno:TextdirectionTopToBottom', '', 0, oArray)
oDisp = ' Success\n [ dispatchHelper ]\n ( Python )'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp,1)
{{ Font Effet }}
#!
#coding: utf-8
# python Marco
import uno
import sys, traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
class cUnderLine():
from com.sun.star.awt.FontUnderline import (NONE, SINGLE, DOUBLE, DOTTED, DONTKNOW, DASH, LONGDASH, DASHDOT, DASHDOTDOT, SMALLWAVE, WAVE, DOUBLEWAVE, BOLD, BOLDDOTTED, BOLDDASH, BOLDLONGDASH, BOLDDASHDOT, BOLDDASHDOTDOT, BOLDWAVE,)
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',oMsgType='messbox'):
"""shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MESSAGEBOX, 1, 'Title', oMessage)
return msgbox.execute()
def oTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet = oDoc.getSheets().getByIndex(0)
oCell = []
for i in range(10):
oCell.append(oSheet.getCellByPosition(0, i))
oCell[i].String = str(i) + ') LO( Python )'
for i in range(10,19):
oCell.append(oSheet.getCellByPosition(1, i-10))
oCell[i].String = str(i) + ') AOO( Python )'
oCell[0].CharUnderline = cUnderLine.NONE
oCell[1].CharUnderline = cUnderLine.SINGLE
oCell[2].CharUnderline = cUnderLine.DOUBLE
oCell[3].CharUnderline = cUnderLine.DOTTED
oCell[4].CharUnderline = cUnderLine.DONTKNOW
oCell[5].CharUnderline = cUnderLine.DASH
oCell[6].CharUnderline = cUnderLine.LONGDASH
oCell[7].CharUnderline = cUnderLine.DASHDOT
oCell[8].CharUnderline = cUnderLine.DASHDOTDOT
oCell[9].CharUnderline = cUnderLine.SMALLWAVE
oCell[10].CharUnderline = cUnderLine.WAVE
oCell[11].CharUnderline = cUnderLine.DOUBLEWAVE
oCell[12].CharUnderline = cUnderLine.BOLD
oCell[13].CharUnderline = cUnderLine.BOLDDOTTED
oCell[14].CharUnderline = cUnderLine.BOLDDASH
oCell[15].CharUnderline = cUnderLine.BOLDLONGDASH
oCell[16].CharUnderline = cUnderLine.BOLDDASHDOT
oCell[17].CharUnderline = cUnderLine.BOLDDASHDOTDOT
oCell[18].CharUnderline = cUnderLine.BOLDWAVE
oDisp = ' Success\n ( Python )'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp,1)
#!
#coding: utf-8
# python Marco
import uno
import sys, traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
class cUnderLine():
from com.sun.star.awt.FontUnderline import (NONE, SINGLE, DOUBLE, DOTTED, DONTKNOW, DASH, LONGDASH, DASHDOT, DASHDOTDOT, SMALLWAVE, WAVE, DOUBLEWAVE, BOLD, BOLDDOTTED, BOLDDASH, BOLDLONGDASH, BOLDDASHDOT, BOLDDASHDOTDOT, BOLDWAVE,)
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',oMsgType='messbox'):
"""shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MESSAGEBOX, 1, 'Title', oMessage)
return msgbox.execute()
def oTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet = oDoc.getSheets().getByIndex(0)
oCell = oSheet.getCellByPosition(0,0)
oCell.String = u'Pythonマクロ'
# Font Effect
oCell.CharHeight = 20
oCell.CharHeightAsian = 20
oCell.CharUnderline = cUnderLine.DOUBLE
oCell.CharUnderlineColor = 0x00ff00 # RGBの16進数6桁で表示 0x + RGB(0,255,0) ⇒ 0x00ff00
oCell.CharUnderlineHasColor = True
oDisp = ' Success\n ( Python )'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp,1)
#!
#coding: utf-8
# python Marco
import uno
import sys, traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
class cFontWeight():
from com.sun.star.awt.FontWeight import (DONTKNOW, THIN, ULTRALIGHT, LIGHT, SEMILIGHT, NORMAL, SEMIBOLD, BOLD, ULTRABOLD, BLACK,)
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',oMsgType='messbox'):
"""shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MESSAGEBOX, 1, 'Title', oMessage)
return msgbox.execute()
def oTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet = oDoc.getSheets().getByIndex(0)
oCell = oSheet.getCellByPosition(0,0)
oCell.String = u'Pythonマクロ'
# Font Effect
oCell.CharFontName = 'Arial'
oCell.CharFontNameAsian = 'Arial'
oCell.CharHeight = 20
oCell.CharHeightAsian = 20
oCell.CharWeight = cFontWeight.ULTRABOLD
oCell.CharWeightAsian = cFontWeight.ULTRABOLD
oCell.CharShadowed = True
oDisp = ' Success\n ( Python )'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp,1)
#!
#coding: utf-8
# python Marco
import uno
import sys, traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
from com.sun.star.beans import PropertyValue
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',oMsgType='messbox'):
"""shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MESSAGEBOX, 1, 'Title', oMessage)
return msgbox.execute()
def oTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet = oDoc.getSheets().getByIndex(0)
oCell = oSheet.getCellRangeByName('A1')
oCell.String = u'Pythonです'
ctx = XSCRIPTCONTEXT.getComponentContext()
desktop = XSCRIPTCONTEXT.getDesktop()
oFrame = desktop.getCurrentFrame()
dispatchHelper = ctx.ServiceManager.createInstanceWithContext( 'com.sun.star.frame.DispatchHelper', ctx )
# A1へ移動
oProp = PropertyValue()
oProp.Name = 'ToPoint'
oProp.Value = 'A1'
properties = (oProp,)
dispatchHelper.executeDispatch(oFrame, '.uno:GoToCell', '', 0, properties )
# Shadow
oProp.Name = 'Shadowed'
oProp.Value = True
properties = (oProp,)
dispatchHelper.executeDispatch(oFrame, '.uno:Shadowed', '', 0, properties )
oDisp = ' Success\n ( Python )'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp,1)
#!
#coding: utf-8
# python Marco
import uno
import sys, traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
class cFontStrikeout():
from com.sun.star.awt.FontStrikeout import (NONE, SINGLE, DOUBLE, DONTKNOW, BOLD, SLASH, X,)
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',oMsgType='messbox'):
"""shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MESSAGEBOX, 1, 'Title', oMessage)
return msgbox.execute()
def oTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet = oDoc.getSheets().getByIndex(0)
for i in range(7):
oCell = oSheet.getCellByPosition(0,i)
oText = u'Pythonマクロ'
oCell.String = oText
oCell.CharHeight = 20
oCell.CharHeightAsian = 20
if i == 0:
oCell.CharStrikeout = cFontStrikeout.NONE
elif i == 1:
oCell.CharStrikeout = cFontStrikeout.SINGLE
elif i == 2:
oCell.CharStrikeout = cFontStrikeout.DOUBLE
elif i == 3:
oCell.CharStrikeout = cFontStrikeout.BOLD
elif i == 4:
oCell.CharStrikeout = cFontStrikeout.SLASH
elif i == 5:
oCell.CharStrikeout = cFontStrikeout.X
else:
oCell.CharStrikeout = cFontStrikeout.DONTKNOW
oDisp = ' Success\n ( Python )'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp,1)
#!
#coding: utf-8
# python Marco
import uno
import sys, traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
from com.sun.star.beans import PropertyValue
class cFontStrikeout():
from com.sun.star.awt.FontStrikeout import (NONE, SINGLE, DOUBLE, DONTKNOW, BOLD, SLASH, X,)
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',oMsgType='messbox'):
"""shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MESSAGEBOX, 1, 'Title', oMessage)
return msgbox.execute()
def oTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet = oDoc.getSheets().getByIndex(0)
oCell = oSheet.getCellRangeByName('A1')
oCell.String = u'Pythonです'
ctx = XSCRIPTCONTEXT.getComponentContext()
desktop = XSCRIPTCONTEXT.getDesktop()
oFrame = desktop.getCurrentFrame()
dispatchHelper = ctx.ServiceManager.createInstanceWithContext( 'com.sun.star.frame.DispatchHelper', ctx )
# A1へ移動
oProp = PropertyValue()
oProp.Name = 'ToPoint'
oProp.Value = 'A1'
properties = (oProp,)
dispatchHelper.executeDispatch(oFrame, '.uno:GoToCell', '', 0, properties )
# Shadow
oProp.Name = 'Strikeout.Kind'
oProp.Value = cFontStrikeout.SLASH
properties = (oProp,)
dispatchHelper.executeDispatch(oFrame, '.uno:Strikeout', '', 0, properties )
oDisp = ' Success\n ( Python )'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp,1)
#!
#coding: utf-8
# python Marco
import uno
import sys, traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',oMsgType='messbox'):
"""shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MESSAGEBOX, 1, 'Title', oMessage)
return msgbox.execute()
def oTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet = oDoc.getSheets().getByIndex(0)
for i in range(5):
oCell = oSheet.getCellByPosition(0,i)
oText = u'Pythonマクロ'
oCell.String = oText
oTextCursor = oCell.createTextCursor()
oTextCursor.gotoStart( False )
oTextCursor.goRight(len(oText), True )
oTextCursor.setPropertyValue('CharEmphasis', i )
oTextCursor.gotoEnd( False )
oDisp = ' Success\n ( Python )'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp,1)
#!
#coding: utf-8
# python Marco
import uno
import sys, traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',oMsgType='messbox'):
"""shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MESSAGEBOX, 1, 'Title', oMessage)
return msgbox.execute()
def oTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet = oDoc.getSheets().getByIndex(0)
for i in range(3):
oCell = oSheet.getCellByPosition(0,i)
oText = u'Pythonマクロ'
oCell.String = oText
oCell.CharHeight = 20
oCell.CharHeightAsian = 20
oTextCursor = oCell.createTextCursor()
oTextCursor.gotoStart( False )
oTextCursor.goRight(len(oText), True )
oTextCursor.setPropertyValue('CharRelief', i )
oTextCursor.gotoEnd( False )
oDisp = ' Success\n ( Python )'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp,1)
#!
#coding: utf-8
# python Marco
import uno
import sys, traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
from com.sun.star.beans import PropertyValue
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',oMsgType='messbox'):
"""shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MESSAGEBOX, 1, 'Title', oMessage)
return msgbox.execute()
def oTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet = oDoc.getSheets().getByIndex(0)
for i in range(3):
oCell = oSheet.getCellByPosition(0, i)
oCell.String = u'Pythonです'
ctx = XSCRIPTCONTEXT.getComponentContext()
desktop = XSCRIPTCONTEXT.getDesktop()
oFrame = desktop.getCurrentFrame()
dispatchHelper = ctx.ServiceManager.createInstanceWithContext( 'com.sun.star.frame.DispatchHelper', ctx )
# A2へ移動
oProp = PropertyValue()
oProp.Name = 'ToPoint'
oProp.Value = 'A2'
properties = (oProp,)
dispatchHelper.executeDispatch(oFrame, '.uno:GoToCell', '', 0, properties )
# 浮出し
oProp.Name = 'CharacterRelief'
oProp.Value = 1
properties = (oProp,)
dispatchHelper.executeDispatch(oFrame, '.uno:CharacterRelief', '', 0, properties )
# A3へ移動
oProp = PropertyValue()
oProp.Name = 'ToPoint'
oProp.Value = 'A3'
properties = (oProp,)
dispatchHelper.executeDispatch(oFrame, '.uno:GoToCell', '', 0, properties )
# 浮彫り
oProp.Name = 'CharacterRelief'
oProp.Value = 2
properties = (oProp,)
dispatchHelper.executeDispatch(oFrame, '.uno:CharacterRelief', '', 0, properties )
oDisp = ' Success\n ( Python )\n [ DispatchHelper ]'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp,1)
#!
#coding: utf-8
# python Marco
import uno
import sys, traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',oMsgType='messbox'):
"""shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MESSAGEBOX, 1, 'Title', oMessage)
return msgbox.execute()
def oTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet = oDoc.getSheets().getByIndex(0)
oCell = oSheet.getCellByPosition(0,0)
oText = u'Pythonマクロ'
oCell.String = oText
oCell.CharHeight = 20
oCell.CharHeightAsian = 20
oCell.CharContoured = True
oDisp = ' Success\n ( Python )'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp,1)
#!
#coding: utf-8
# python Marco
import uno
import sys, traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
from com.sun.star.beans import PropertyValue
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',oMsgType='messbox'):
"""shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MESSAGEBOX, 1, 'Title', oMessage)
return msgbox.execute()
def oTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet = oDoc.getSheets().getByIndex(0)
oCell = oSheet.getCellByPosition(0,0)
oCell.String = u'Pythonです'
ctx = XSCRIPTCONTEXT.getComponentContext()
desktop = XSCRIPTCONTEXT.getDesktop()
oFrame = desktop.getCurrentFrame()
dispatchHelper = ctx.ServiceManager.createInstanceWithContext( 'com.sun.star.frame.DispatchHelper', ctx )
# A1へ移動
oProp = PropertyValue()
oProp.Name = 'ToPoint'
oProp.Value = 'A1'
properties = (oProp,)
dispatchHelper.executeDispatch(oFrame, '.uno:GoToCell', '', 0, properties )
# 中抜き
oProp.Name = 'OutlineFont'
oProp.Value = True
properties = (oProp,)
dispatchHelper.executeDispatch(oFrame, '.uno:OutlineFont', '', 0, properties )
oDisp = ' Success\n ( Python )\n [ DispatchHelper ]'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp,1)
{{ Position / Size }}
#!
#coding: utf-8
# python Marco
import uno
import sys, traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
from com.sun.star.beans import PropertyValue
class cCellVertJust():
from com.sun.star.table.CellVertJustify import (STANDARD, TOP, CENTER, BOTTOM)
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',oMsgType='messbox'):
"""shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MESSAGEBOX, 1, 'Title', oMessage)
return msgbox.execute()
def oTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet = oDoc.getSheets().getByIndex(0)
oCell = []
for i in range(4):
oCell.append(oSheet.getCellByPosition(0, i))
oCell[i].Value = i*20
oCell[0].VertJustify = cCellVertJust.STANDARD
oCell[1].VertJustify = cCellVertJust.TOP
oCell[2].VertJustify = cCellVertJust.CENTER
oCell[3].VertJustify = cCellVertJust.BOTTOM
oDisp = ' Success\n ( Python )'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp,1)
#!
#coding: utf-8
# python Marco
import uno
import sys, traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
from com.sun.star.beans import PropertyValue
class cCellHoriJust():
from com.sun.star.table.CellHoriJustify import (STANDARD, LEFT, CENTER, RIGHT, BLOCK, REPEAT)
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',oMsgType='messbox'):
"""shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MESSAGEBOX, 1, 'Title', oMessage)
return msgbox.execute()
def oTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet = oDoc.getSheets().getByIndex(0)
oCell = []
for i in range(6):
oCell.append(oSheet.getCellByPosition(0, i))
oCell[i].Value = i*20
oCell[0].HoriJustify = cCellHoriJust.STANDARD
oCell[1].HoriJustify = cCellHoriJust.LEFT
oCell[2].HoriJustify = cCellHoriJust.CENTER
oCell[3].HoriJustify = cCellHoriJust.RIGHT
oCell[4].HoriJustify = cCellHoriJust.BLOCK
oCell[5].HoriJustify = cCellHoriJust.REPEAT
oDisp = ' Success\n ( Python )'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp,1)
#!
#coding: utf-8
# python Marco
import uno
import sys, traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
from com.sun.star.beans import PropertyValue
#class cCellVertJust():
# from com.sun.star.table.CellVertJustify import (STANDARD, TOP, CENTER, BOTTOM,)
class cCellHoriJust():
from com.sun.star.table.CellHoriJustify import (STANDARD, LEFT, CENTER, RIGHT, BLOCK, REPEAT,)
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',oMsgType='messbox'):
"""shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MESSAGEBOX, 1, 'Title', oMessage)
return msgbox.execute()
def oTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet = oDoc.getSheets().getByIndex(0)
oCell = []
for i in range(8):
oCell.append(oSheet.getCellByPosition(0, i))
oCell[i].Value = i*20
if i == 7:
oCell[i].String = str(oCell[i].Value) + 'Test'
ctx = XSCRIPTCONTEXT.getComponentContext()
desktop = XSCRIPTCONTEXT.getDesktop()
oFrame = desktop.getCurrentFrame()
dispatchHelper = ctx.ServiceManager.createInstanceWithContext( 'com.sun.star.frame.DispatchHelper', ctx )
oProp = PropertyValue()
# Move the Cell
oProp.Name = 'ToPoint'
oProp.Value = 'A1'
properties = (oProp,)
dispatchHelper.executeDispatch(oFrame, '.uno:GoToCell', '', 0, properties )
# Position
oProp.Name = 'VerticalJustification'
oProp.Value = 1 # cCellVertJust.TOP : NG?
properties = (oProp,)
dispatchHelper.executeDispatch(oFrame, '.uno:VerticalJustification', '', 0, properties )
# Move the Cell
oProp.Name = 'ToPoint'
oProp.Value = 'A2'
properties = (oProp,)
dispatchHelper.executeDispatch(oFrame, '.uno:GoToCell', '', 0, properties )
# Position
oProp.Name = 'VerticalJustification'
oProp.Value = 2
properties = (oProp,)
dispatchHelper.executeDispatch(oFrame, '.uno:VerticalJustification', '', 0, properties )
# Move the Cell
oProp.Name = 'ToPoint'
oProp.Value = 'A3'
properties = (oProp,)
dispatchHelper.executeDispatch(oFrame, '.uno:GoToCell', '', 0, properties )
# Position
oProp.Name = 'VerticalJustification'
oProp.Value = 3
properties = (oProp,)
dispatchHelper.executeDispatch(oFrame, '.uno:VerticalJustification', '', 0, properties )
# Move the Cell
oProp.Name = 'ToPoint'
oProp.Value = 'A4'
properties = (oProp,)
dispatchHelper.executeDispatch(oFrame, '.uno:GoToCell', '', 0, properties )
# Position
oProp.Name = 'HorizontalJustification'
oProp.Value = cCellHoriJust.LEFT
properties = (oProp,)
dispatchHelper.executeDispatch(oFrame, '.uno:HorizontalJustification', '', 0, properties )
# Move the Cell
oProp.Name = 'ToPoint'
oProp.Value = 'A5'
properties = (oProp,)
dispatchHelper.executeDispatch(oFrame, '.uno:GoToCell', '', 0, properties )
# Position
oProp.Name = 'HorizontalJustification'
oProp.Value = cCellHoriJust.CENTER
properties = (oProp,)
dispatchHelper.executeDispatch(oFrame, '.uno:HorizontalJustification', '', 0, properties )
# Move the Cell
oProp.Name = 'ToPoint'
oProp.Value = 'A6'
properties = (oProp,)
dispatchHelper.executeDispatch(oFrame, '.uno:GoToCell', '', 0, properties )
# Position
oProp.Name = 'HorizontalJustification'
oProp.Value = cCellHoriJust.RIGHT
properties = (oProp,)
dispatchHelper.executeDispatch(oFrame, '.uno:HorizontalJustification', '', 0, properties )
# Move the Cell
oProp.Name = 'ToPoint'
oProp.Value = 'A7'
properties = (oProp,)
dispatchHelper.executeDispatch(oFrame, '.uno:GoToCell', '', 0, properties )
# Position
oProp.Name = 'HorizontalJustification'
oProp.Value = cCellHoriJust.BLOCK
properties = (oProp,)
dispatchHelper.executeDispatch(oFrame, '.uno:HorizontalJustification', '', 0, properties )
# Move the Cell
oProp.Name = 'ToPoint'
oProp.Value = 'A8'
properties = (oProp,)
dispatchHelper.executeDispatch(oFrame, '.uno:GoToCell', '', 0, properties )
# Position
oProp.Name = 'HorizontalJustification'
oProp.Value = cCellHoriJust.REPEAT
properties = (oProp,)
dispatchHelper.executeDispatch(oFrame, '.uno:HorizontalJustification', '', 0, properties )
oDisp = ' Success\n ( Python )\n [ DispatchHelper ]'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp,1)
{{ Color }}
#!
#coding: utf-8
# python Marco
import uno
import sys, traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title'):
"""shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MESSAGEBOX, oBtnType, oTitle, oMessage)
return msgbox.execute()
def oTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet = oDoc.getSheets().getByName('sheet1')
oCell=[]
for i in range(2):
oCell.append(oSheet.getCellByPosition(0, i))
if i == 0:
oCell[0].String ='LibreOffice'
oCell[0].CharColor = 0x0000ff # 0x + RGB値 / red ならば 0xff0000
oCell[0].IsTextWrapped = False
elif i == 1:
oCell[1].String ='Python Macro'
oCell[1].CharColor = 0x00ff00
oCell[1].IsTextWrapped = True
oDisp = 'Success'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp,1,'LO7.0.1.2')
#!
#coding: utf-8
# python Marco
import uno
import sys, traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title'):
"""shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MESSAGEBOX, oBtnType, oTitle, oMessage)
return msgbox.execute()
def oTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet = oDoc.getSheets().getByName('sheet1')
oCell=oSheet.getCellByPosition(0,0)
oTxt = u'1,000円(2020/9/25)'
oCell.String = oTxt
oCNum= oTxt.find('円') #「円」までの文字数を調べる。
oTextCursor = oCell.createTextCursor()
oTextCursor.gotoStart( False )
oTextCursor.goRight( oCNum, True )
oTextCursor.setPropertyValue( 'CharColor', 0xff0000 )
oTextCursor.gotoEnd( False )
oDisp = 'Success'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp,1,'LO7.0.1.2')
[ Clear ]

#!
#coding: utf-8
# python Marco
import uno
import sys, traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
class cCellFlag():
from com.sun.star.sheet.CellFlags import (VALUE, DATETIME, STRING, ANNOTATION, FORMULA, HARDATTR, STYLES, OBJECTS, EDITATTR, FORMATTED,)
def omsgbox(oMessage='',oBtnType=1,oTitle='Title'):
"""shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MESSAGEBOX, oBtnType, oTitle, oMessage)
return msgbox.execute()
def oTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet = oDoc.getSheets().getByIndex(0)
oCellRange=oSheet.getCellRangeByName('A2:D3')
oFlag = cCellFlag.VALUE + cCellFlag.STRING + cCellFlag.FORMULA
oCellRange.clearContents(oFlag)
oDisp = 'Success'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp)
[ Selection ]
#!
#coding: utf-8
# python Marco
import uno
import sys
import traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title'):
# """shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MESSAGEBOX, oBtnType, oTitle, oMessage)
return msgbox.execute()
def oMacroTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oCtrl = oDoc.getCurrentController()
oSelRange = oCtrl.getActiveSheet().getCellRangeByName( "A2" )
oCtrl.select(oSelRange)
#
oDisp = 'Success'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp,1,'LO6.4.3.2(x64)')
#!
#coding: utf-8
# python Marco
import uno
import sys
import traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
#
def omsgbox(oMessage='',oBtnType=1,oTitle='Title'):
# """shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MESSAGEBOX, oBtnType, oTitle, oMessage)
return msgbox.execute()
#
def oTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oCtrl = oDoc.getCurrentController()
oSheet = oDoc.getSheets().getByIndex(0)
oSelRange = oSheet.getColumns().getByIndex(1)
oCtrl.select( oSelRange )
#
oDisp = 'Success'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp,1,'LO6.4.3.2(x64)')
[ Address ]
#!
#coding: utf-8
# python Marco
import uno
import sys
import traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',MsgType=MESSAGEBOX):
# """shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MsgType, oBtnType, oTitle, oMessage)
return msgbox.execute()
def oTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSel = oDoc.getCurrentSelection()
if oSel.supportsService('com.sun.star.sheet.SheetCellRange'):
oActCol = oSel.getRangeAddress().StartColumn
oActRow = oSel.getRangeAddress().StartRow
oShtNo = oSel.getRangeAddress().Sheet
oDisp = '[ Address of Current Cell ]\n\t Sheet No. = ' + str(oShtNo) + '\n\t Address = ( ' + str(oActCol) + ' , ' + str(oActRow) + ' )'
else:
oDisp = u'Address取得失敗'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp,1)
#!
#coding: utf-8
# python Marco
from com.sun.star.sheet.CellFlags import (VALUE, DATETIME, STRING,ANNOTATION, FORMULA, HARDATTR, OBJECTS, EDITATTR, FORMATTED)
import uno
import sys
import traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',MsgType=MESSAGEBOX):
# """shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MsgType, oBtnType, oTitle, oMessage)
return msgbox.execute()
def oTest():
"""shows last used row index of specified column"""
try:
column_index = 0
sheet_index = 0
flags = VALUE + DATETIME + STRING + ANNOTATION + FORMULA + HARDATTR + OBJECTS + EDITATTR + FORMATTED
doc = XSCRIPTCONTEXT.getDocument()
sheet = doc.getSheets().getByIndex(sheet_index)
column = sheet.getColumns().getByIndex(column_index)
ranges = column.queryContentCells(flags).getRangeAddresses()
n = 0
for r in ranges:
if n < r.EndRow:
n = r.EndRow;
oDisp = u'[ 最終Row Address ]\n\t End Row = ' + str(n)
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp,1)
#!
#coding: utf-8
# python Marco
from com.sun.star.beans import PropertyValue
import uno
import sys
import traceback
from com.sun.star.awt.MessageBoxType import MESSAGEBOX
def omsgbox(oMessage='',oBtnType=1,oTitle='Title',MsgType=MESSAGEBOX):
# """shows message."""
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
window = frame.getContainerWindow()
toolkit = window.getToolkit()
msgbox = toolkit.createMessageBox(window, MsgType, oBtnType, oTitle, oMessage)
return msgbox.execute()
def oTest():
try:
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet = oDoc.getSheets().getByIndex(0)
oCursor = oSheet.createCursor()
oShtEndRow = oCursor.getRangeAddress().EndRow
#
ctx = XSCRIPTCONTEXT.getComponentContext()
desktop = XSCRIPTCONTEXT.getDesktop()
frame = desktop.getCurrentFrame()
dispatchHelper = ctx.ServiceManager.createInstanceWithContext( 'com.sun.star.frame.DispatchHelper', ctx )
oProp = PropertyValue()
oProp.Name = 'ToPoint'
oProp.Value = 'A' + str(oShtEndRow)
properties = (oProp,)
dispatchHelper.executeDispatch( frame, '.uno:GoToCell', '', 0, properties )
oProp = []
oProp1 = PropertyValue()
oProp1.Name = 'By'
oProp1.Value = 1
oProp2 = PropertyValue()
oProp2.Name = 'Sel'
oProp2.Value = False # false : NG
oProp.append(oProp1)
oProp.append(oProp2)
properties = tuple(oProp)
dispatchHelper.executeDispatch( frame, '.uno:GoUpToStartOfData', '', 0, properties )
oSel = oDoc.getCurrentSelection()
oEndRow = oSel.getRangeAddress().StartRow
oDisp = u'[ 最終Row Address ]\n\t End Row = ' + str(oEndRow) + '\n\t ( dispatchHelper )'
except Exception as er:
oDisp = ''
oDisp = str(traceback.format_exc()) + '\n' + str(er)
finally:
omsgbox(oDisp,1)