Top > OOoPython > WriterOverView

Python と Writer Edit

Python で Writer ドキュメントを操作します。

  0
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
#!
# -*- coding: utf_8 -*-
 
from com.sun.star.beans import PropertyValue
from com.sun.star.table import TableBorder
from com.sun.star.text import TableColumnSeparator
from com.sun.star.text.HoriOrientation import NONE as HO_NONE
 
 
def writer_test():
    doc = XSCRIPTCONTEXT.getDocument()
    if doc.supportsService("com.sun.star.text.TextDocument"):
        text = doc.getText()
        #insert_heading1(text, u'見出しを入力')
        # 見出しを作成
        cursor = text.createTextCursorByRange(text.getStart())
        cursor.setString(u'見出しを入力')
        cursor.setPropertyValue(u'ParaStyleName', u'Heading 1')
        
        insert_para(text, u'枠線のない表')
        
        # 表を作成、挿入
        table = doc.createInstance("com.sun.star.text.TextTable")
        table.setName("NewTable")
        table.initialize(3, 2)
        
        text.insertTextContent(text.getEnd(),table,True)
        
        # 表の枠線をなしに、幅などを変更
        border = TableBorder()
        border.IsTopLineValid = True
        border.IsBottomLineValid = True
        border.IsLeftLineValid = True
        border.IsRightLineValid = True
        border.IsHorizontalLineValid = True
        border.IsVerticalLineValid = True
        table.TableBorder = border
        
        #table.Width = 12000
        table.LeftMargin = 2000
        table.RightMargin = 2000
        table.HoriOrient = HO_NONE
        
        t = TableColumnSeparator()
        t.Position = 3000
        t.IsVisible = True
        table.TableColumnSeparators = t,
        
        # 一度にセルにデータを入力
        d = (
                (u'項目', u'説明'),
                (u'みかん', u'蜜柑'),
                (u'りんご', u'林檎')
            )
        
        table.setDataArray(d)
 
 
def insert_para(text, string):
    p = make_PropertyValue("ParaStyleName", "Standard")
    text.appendParagraph((p,))
    text.insertString(text.getEnd(), string, False)
    text.finishParagraph(())
 
def insert_heading1(text, string):
    p = make_PropertyValue("ParaStyleName", "Heading 1")
    text.appendParagraph( (p,) )
    text.insertString(text.getEnd(), string, False)
 
def make_PropertyValue(name, value):
    p = PropertyValue()
    p.Name = name
    p.Value = value
    return p
 
g_exportedScripts = writer_test,

Reload   New Lower page making Edit Freeze Diff Upload Copy Rename   Front page List of pages Search Recent changes Backup   Help   RSS of recent changes