# # This file is part of the LibreOffice project. # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. # # This file incorporates work covered by the following license notice: # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed # with this work for additional information regarding copyright # ownership. The ASF licenses this file to you under the Apache # License, Version 2.0 (the "License"); you may not use this file # except in compliance with the License. You may obtain a copy of # the License at http://www.apache.org/licenses/LICENSE-2.0 . #
import uno
# a UNO struct later needed to create a document from com.sun.star.text.ControlCharacter import PARAGRAPH_BREAK from com.sun.star.text.TextContentAnchorType import AS_CHARACTER from com.sun.star.awt import Size
def createTable(): """Creates a new writer document and inserts a table with some data
(also known as the SWriter sample). """
ctx = uno.getComponentContext()
smgr = ctx.ServiceManager
desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx)
# open a writer document
doc = desktop.loadComponentFromURL( "private:factory/swriter", "_blank", 0, ())
text = doc.Text
cursor = text.createTextCursor()
text.insertString(
cursor, "The first line in the newly created text document.\n",
0)
text.insertString(
cursor, "Now we are in the second line\n",
0)
# create a text table
table = doc.createInstance("com.sun.star.text.TextTable")
# with 4 rows and 4 columns
table.initialize(4, 4)
text.insertControlCharacter(cursor, PARAGRAPH_BREAK, 0)
text.insertString(
cursor, "This is a colored Text - blue with shadow\n",
0)
text.insertControlCharacter(cursor, PARAGRAPH_BREAK, 0)
textInTextFrame = textFrame.getText()
cursorInTextFrame = textInTextFrame.createTextCursor()
textInTextFrame.insertString(
cursorInTextFrame, "The first line in the newly created text frame.",
0)
textInTextFrame.insertString(
cursorInTextFrame, "\nWith this second line the height of the rame raises.",
0)
text.insertControlCharacter(cursor, PARAGRAPH_BREAK, 0)
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.