Kiev1.org Карта сайта Файлы Фотографии Киева
  
Реклама:






Разделы
 
 Sysadmin
 Антиглобалисты
 Ереси и секты
 Катастрофы
 Компьютерные новости
 Непроверенное
 О проекте
 О фотогалерее
 Политика и власть
 Православие
 Предприятия Украины
 Протесты Людей против нового мирового концлагеря
 Разное
 Россия
 Старец Паисий 1924-1994
 Стояние за Истину
 Суды в Украине
 Тайна беззакония
 экуменизм


Внимание! Читая пророчества на этом сайте помните что достоверность трудно проверить и все может во времени изменяться - самое главное думать своей головой и не верить легкомысленно всему что говорят, особенно советское телевидение
"О дне же том, или часе, никто не знает, ни Ангелы небесные, ни Сын, но только Отец (Мк. 13, 32)"

Using regular expressions



Примеры использования regular expressions в офисном пакете OpenOffice.org
Using regular expressions
To find strings in a certain context, you should use regular expressions. We will not
explain them in detail here since the StarOffice documentation contains all necessary
information. Suppose that in a bibliography each entry starts with the title followed
by the author. You cannot search for only the lines in the document containing these
entries with a simple string, since there is no common word for all entries. However,
they share a common structure- each line starts with a number contained in brackets.
Using a regular expression, you can search for this structure. The following program
fragment exchanges title and author:
Dim oSearchDesc As Object, oCursor As Object
Dim oFoundAll As Object, oFound As Object
Dim nLen As Integer, n As Integer
Dim nEndAuthor As Integer
Dim nStartTitle As Integer, nEndTitle As Integer
Dim sAuthor As String, sTitle As String
Dim s As String, sRest As String
oSearchDesc = oDocument.createSearchDescriptor()
oSearchDesc.SearchString = "^[[0-9]+]"
oSearchDesc.SearchRegularExpression = TRUE
oFoundAll = oDocument.findAll( oSearchDesc )
For n = 0 To oFoundAll.Count - 1
oFound = oFoundAll(n)
REM Or: oFound=oFoundAll.getByIndex(n)
oCursor = oText.createTextCursorByRange(oFound)
oCursor.gotoNextWord(FALSE)
oCursor.gotoEndOfParagraph(TRUE)
Using StarOffice API - Building blocks 57
s = oCursor.String
nEndAuthor = InStr(1, s, ";") -1
nLen = nEndAuthor
sAuthor = Left(s, nLen)
nStartTitle = nEndAuthor + 2
nEndTitle = InStr(nStartTitle, s, ";") -1
nLen = nEndTitle - nStartTitle + 1
sTitle = Mid(s, nStartTitle, nLen)
nLen = Len(s) - nEndTitle
sRest = Right(s, nLen)
oCursor.String = sTitle + " " + sAuthor + sRest
Next n
After creating the search descriptor, its SearchString is set to ^[[0-9]+]. In
plain words this means: "Find all lines beginning with a left bracket. This bracket
must be followed by at least one digit and a closing bracket.". The caret (^) stands
for "beginning of the line", "[0-9]" denotes all digits, and the following plus sign
means "at least one". We’ll not go into more detail here, the StarOffice API Reference
Manual contains more information on regular expressions. The search descriptor’s
searchRegularExpression attribute must be set to TRUE to let it know that it
should not look for the literal string "^[[0-9]+]".
All lines matching the regular expression are then found with findAll(). It returns
an XTextRange() interface which is passed to createTextCursorByRange().
The new cursor is thus automatically positioned at the matching regular expression.
By moving it to the next word and then to the end of the paragraph, we span a text
range that contains the whole bibliography entry but the leading number. This string
is finally modified with some lines of pure StarBasic. They simply find the semicolons
separating the author and the title and re-assemble the string from these parts.
4.3.7 Inserting tables, frames, etc.
As mentioned in Section 4.3.1 “The structure of text documents” on page 47, a text
document can contain tables and other elements besides paragraphs of text. We’ll
show you how to insert tables and frames in your text document in this section.
A table is a special object that you can insert into a text document. You can think of
it as a simple spreadsheet - a very simple one, in fact. First of all, you will see how to
insert a simple table:
Dim oTable As Object
oCursor = oText.createTextCursor()
oCursor.gotoStart(FALSE)
oTable = oDocument.createInstance("com.sun.star.text.TextTable")
oTable.initialize(5,9)
oText.insertTextContent(oCursor, oTable, FALSE)
The table is created by calling createInstance() and then initialized to contain
five rows and nine columns. It is then placed in the current document with a call to

insertTextContent(). This methods expects a textCursor as its first element.
In our example, this cursor is simply placed at the beginning of the document.
Your document now contains an empty table. Since you would probably want to
place text or other things inside this table, we’ll show you how to do this next:
Dim oTableCursor As Object
Dim sCellName As String
Dim oCell As Object
oTableCursor = oTable.createCursorByCellName(oTable.CellNames(0))
oTableCursor.gotoStart(FALSE)
Dim mTableHeaders(8) As String
mTableHeaders(0) = "Field"
mTableHeaders(1) = "Format"
mTableHeaders(2) = "AutoIncrement"
mTableHeaders(3) = "Descending"
mTableHeaders(4) = "PartOfPrimaryKey"
mTableHeaders(5) = "Required"
mTableHeaders(6) = "Scale"
mTableHeaders(7) = "Size"
mTableHeaders(8) = "Type"
For n = 0 To 8
sCellName = oTableCursor.getRangeName()
oCell = oTable.getCellByName(sCellName)
oCell.String=mTableHeaders(n)
oTableCursor.goRight(1,FALSE)
Next n
To move around in a table, you have to create a tableCursor first. The sample
code above uses the method createCursorByCellName() for this and then
moves the cursor to the top left cell of the table. After initializing the array
tableHeaders with the column headers of the table, it moves the cursor to each of
the cells in the first row with goRight(). The content of the cell is then set by
assigning to its String property.
If you want to insert numbers into a table, you’ll probably not want them to be
displayed left justified, which is the default for all cells. To change the justification
for a cell depending on its content, you can use this code snippet:
s=oCell.String
If IsNumeric(s) Then
oCellCursor = oCell.createTextCursor()
oCellCursor.paraAdjust = com.sun.star.style.ParagraphAdjust.RIGHT
End If
We are using a text cursor here to hard format a cell if it contains a number.
Alternatively, you might define a special style for numbers and assign it to the cell:
oCellCursor.paraStyle="myNumberStyle"





 Макросы в OpenOffice Calc
 Компания "Интерактив" interactiv.com.ua пытается присвоить себе права на офисный пакет OpenOffice http://openoffice.org
 Компания "Интерактив", зарегистрировавшая товарный знак в точности повторяющий известную марку OpenOffice.org, в не тактичном тоне дает на своем сайте объяснения по поводу происшедшего.


Внимание! Читая пророчества на этом сайте помните что достоверность трудно проверить и все может во времени изменяться
"О дне же том, или часе, никто не знает, ни Ангелы небесные, ни Сын, но только Отец (Мк. 13, 32)"