Talk:Documentation/DevGuide/Text/Text Fields
From Apache OpenOffice Wiki
Hi.
I am having a little problem: I need to get sheet number instead of page number;
I made this routine:
Sub SetCurrSheet
dim NumFol, NumPg, TotFol, oDoc as object, dispatcher as object, gVC
oDoc = ThisComponent
gVC = oDoc.CurrentController.getViewCursor()
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
TotFol = oDoc.CurrentController.PageCount ' Total de Páginas
gVC.jumpToFirstPage rem posiciona primeira pagina
for M = 1 to TotFol
sName = oDoc.getCurrentController().getViewCursor().PageStyleName
oST = oDoc.StyleFamilies.getByName("PageStyles").getByName(sName)
oST.HeaderIsOn = false
oST.HeaderIsShared = false
oST.HeaderIsOn = true
oST.HeaderIsShared = false
oText = oST.HeaderText
oCur = oText.createTextCursor()
NumPg = gVC.getPage()
msgbox "Pagina atual: " & NumPg
Select Case NumPg
Case NumPg = 1
NumFol = 1
Case Else
NumFol = iif(NumPg Mod 2, int(NumPg / 2 + 1),NumPg / 2)
End Select
MsgBox "Folha Passada: " & NumFol
' oCur.setString("Folha " & NumFol)
oText.setString("Folha " & NumFol, False)
msgbox "Numero de Páginas: " & TotFol
gVC.jumpToNextPage()
next M
End Sub
But i returns only a static information, not a user field. I did like to utilize that routine used on our wiki, at final of page:
/** This method inserts both a date field and a user field containing the number '42' */ protected void TextFieldExample() { try { // Use the text document's factory to create a DateTime text field, // and access it's // XTextField interface XTextField xDateField = (XTextField) UnoRuntime.queryInterface( XTextField.class, mxDocFactory.createInstance( "com.sun.star.text.textfield.DateTime")); // Insert it at the end of the document mxDocText.insertTextContent ( mxDocText.getEnd(), xDateField, false ); // Use the text document's factory to create a user text field, // and access it's XDependentTextField interface XDependentTextField xUserField = (XDependentTextField) UnoRuntime.queryInterface ( XDependentTextField.class, mxDocFactory.createInstance( "com.sun.star.text.textfield.User")); // Create a fieldmaster for our newly created User Text field, and access it's // XPropertySet interface XPropertySet xMasterPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, mxDocFactory.createInstance( "com.sun.star.text.fieldmaster.User")); // Set the name and value of the FieldMaster xMasterPropSet.setPropertyValue ("Name", "UserEmperor"); xMasterPropSet.setPropertyValue ("Value", new Integer(42)); // Attach the field master to the user field xUserField.attachTextFieldMaster (xMasterPropSet); // Move the cursor to the end of the document mxDocCursor.gotoEnd(false); // insert a paragraph break using the XSimpleText interface mxDocText.insertControlCharacter( mxDocCursor, ControlCharacter.PARAGRAPH_BREAK, false); // Insert the user field at the end of the document mxDocText.insertTextContent(mxDocText.getEnd(), xUserField, false); } catch (Exception e) { e.printStackTrace (System.out); } }
Instead of "42", to bring sheet # (that is: PageNumber MOD 2). I do not know to codificate this. Somebody help me to achieve it, please... Morvan, Linux User #433640 (talk) 11:31, 4 February 2013 (UTC)