Цитата: JohnSUN от 22 марта 2013, 19:13Питоньяк, глава "6.17. Setting header and footer text"
По источнику получилось:
REM ***** BASIC *****
Sub SetLeftHeader
Dim oDoc, oSheet, oPstyle, oHeader
Dim oText, oCursor, oField, oDateTime
Dim oChar, oFont
Dim sService$
oDoc = ThisComponent
' Get the pagestyle for the currently active sheet.
oSheet = oDoc.CurrentController.getActiveSheet
oStyles = oDoc.StyleFamilies.getByName("PageStyles")
oPstyle = oStyles.getByName(oSheet.PageStyle)
' Turn headers on and then make them shared!
oPstyle.HeaderOn = True
oPstyle.HeaderShared = True
' The is also a RightText and a LeftText
oHeader = oPstyle.LeftPageHeaderContent
oText = oHeader.LeftText
' You may now set the text object to be anything you desire
' Use setSTring() from the text object to set simple text.
' Use a cursor to insert a field (such as the current sheet name).
' First, clear any existing text!
oText.setString("")
oCursor = oText.createTextCursor()
oText.insertString(oCursor, "Получено из Е-Mail." & CHR(10) & "Файл :", False)
' This will have the sheet name of the current sheet!
sService = "com.sun.star.text.TextField.FileName"
oField = oDoc.createInstance(sService)
oText.insertTextContent(oCursor, oField, False)
oText.insertString(oCursor, CHR(10) & "Печать :", False)
oDateTime = oDoc.createInstance("com.sun.star.text.TextField.DateTime")
oText.insertTextContent(oCursor, oDateTime, False)
' And now for the part that holds the entire thing together,
' You must write the header object back because we have been
' modifying a temporary object
oPstyle.RightPageHeaderContent = oHeader
End Sub
Подскажите, пожалуйста, как сделать формат вставленного текста, например, Times New Roman, Italic, 7 ?
Как насчет того, чтобы заранее отформатировать через Формат-Страница-Колонтитул?
[вложение удалено Администратором]
Цитата: JohnSUN от 29 марта 2013, 18:05Как насчет того, чтобы заранее отформатировать через Формат-Страница-Колонтитул?
Файлы поступают секретарю, ее задача - по нажатию назначенной кнопки макросом в документ прописать необходимые пометки. Дополнительные ручные действия не желательны (все должно быть аналогично как для Writer, где таких трудностей нет).
Тогда, наверное, - не проверял, не знаю сработает ли - после того как получил oText = oHeader.LeftText попробуй копнуть чуть глубже, получи свойство Text этого oText.
vText = oText.getText()
vText.setPropertyValue("CharFontName","Times New Roman")
vText.setPropertyValue("CharHeight",7)
Где-то там же, по идее, закопан и курсив...
Цитата: JohnSUN от 29 марта 2013, 19:44Где-то там же, по идее, закопан и курсив...
Все получилось, спасибо. Вопрос решен.
Окончательный вариант:
...
oText.setString("")
vText = oText.getText()
vText.setPropertyValue("CharFontName","Times New Roman")
vText.setPropertyValue("CharHeight",7)
vText.setPropertyValue("CharPosture",3)
vText.setPropertyValue("CharColor",8421401)
...