Modérateur: Vilains modOOos
Balisage obligatoire dans cette section !
Sub rotationTexte()
otext = thisComponent.getText()
otable = thisComponent.getTextTables().getByIndex(0)
ocell = otable.getCellByName("A1")
cellcontent = ocell.getText()
cellcontent.setString("[VERT]")
cursor = cellcontent.createTextCursor()
cursor.goToStart(False)
cursor.goToEndOfWord(True)
cursor.setPropertyValue("CharRotation", 900)
End Sub
mimi31110 a écrit:je dois le faire en java, c'est ça qui me pose problème.


// création objet curseur
XTextCursor oCurs = oTableText.createTextCursor();
// obtenir les propriétés
XPropertySet oCursP = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, oCurs);
try {
// obtenir propriété à changer
short rotation = ((Short)oCursP.getPropertyValue("CharRotation")).shortValue();
// ajuster la propriété
rotation = 900;
// rotation du texte à la nouvelle valeur
oCursP.setPropertyValue("CharRotation", new Short(rotation));
} catch (Exception ex) { // exception }
XTextDocument xTextDoc = (com.sun.star.text.XTextDocument)UnoRuntime.queryInterface(com.sun.star.text.XTextDocument.class, xWriterComponent);
//***********************************************************
// RECHERCHE LA BALISE [VERT] ET RETOURNE LE TEXTE ASSOCIE
//***********************************************************
// ajuster la propriété
short rotation = 900;
short noRotation = 0;
// Create textdocument
XTextCursor xTextCursor = null;
XText xText = (XText)xTextDoc.getText();
xTextCursor = (XTextCursor) xText.createTextCursor();
//recherche la balise [VERT]
XSearchable xSearch = (XSearchable) UnoRuntime.queryInterface(XSearchable.class, xWriterComponent);
XSearchDescriptor xSearchDesc = xSearch.createSearchDescriptor();
xSearchDesc.setSearchString("[VERT]");
Object result = xSearch.findFirst(xSearchDesc);
while (result != null)
{
XPropertySet xCPS = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, result);
xCPS.setPropertyValue("CharRotation", new Short (rotation));
result = xSearch.findNext(result, xSearchDesc);
}
//***************************************************************
//RECHERCHE ET REMPLACE LA BALISE [VERT]
//***************************************************************
XReplaceable xReplaceable = (XReplaceable) UnoRuntime.queryInterface(XReplaceable.class, xWriterComponent);
XReplaceDescriptor xRepDesc = xReplaceable.createReplaceDescriptor();
// set a string to search for
xRepDesc.setSearchString("[VERT]");
// set the string to be inserted
xRepDesc.setReplaceString("test");
// create an array of one property value for a CharWeight property
PropertyValue[] aReplaceArgs = new PropertyValue[1];
aReplaceArgs[0] = new PropertyValue();
aReplaceArgs[0].Name = "CharWeight";
aReplaceArgs[0].Value = new Float (com.sun.star.awt.FontWeight.BOLD);
// set our sequence with one property value as ReplaceAttribute
XPropertyReplace xPropRepl = (XPropertyReplace) UnoRuntime.queryInterface(XPropertyReplace.class, xRepDesc);
xPropRepl.setReplaceAttributes(aReplaceArgs);
// replace
int nResult = xReplaceable.replaceAll(xRepDesc);


while (result != null)

while (result != null)
{
System.out.println("entrée dans la boucle...");
XPropertySet xCPS = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, result);
System.out.println("property set...");
XTextRange test = (XTextRange) result;
XTextCursor xTextCursor = (XTextCursor) xText.createTextCursorByRange(test);
xTextCursor.getText().insertString( xTextCursor, "Insertion de texte pour localiser le curseur...", true);
xCPS.setPropertyValue("CharRotation", new Short (rotation));
System.out.println("balise suivante...");
result = xSearch.findNext(result, xSearchDesc);
}
entrée dans la boucle...
property set...
null
java.lang.ClassCastException
at test.tests2.executeVert(tests2.java:94)
at test.tests2.useWriter(tests2.java:53)
at test.tests2.useDocuments(tests2.java:45)
at test.tests2.main(tests2.java:30)
XTextRange test = (XTextRange) result;
//***********************************************************
// RECHERCHE TOUS LES TABLEAUX DU DOCUMENT
// SI LA CELLULE A2 A SON TEXTE QUI DE TERMINE PAR "[VERT]"
// ALORS JE REECRIS LA PRHASE AVEC LA PROPRIETE VERTICALE
// SINON, JE NE FAIS RIEN
//***********************************************************
// ajuster la propriété
short rotation = 900;
XTextDocument xTextDoc = (XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, xWriterComponent);
XText xText = (XText)xTextDoc.getText();
XTextTablesSupplier tab = (XTextTablesSupplier)UnoRuntime.queryInterface(XTextTablesSupplier.class, xWriterComponent);
XNameAccess tables = tab.getTextTables();
System.out.println(tables);
// create instance of a text table
XTextTable xTT = (XTextTable) UnoRuntime.queryInterface(XTextTable.class, xWriterComponent);;
//récupération des nom de tous les tableaux présents dans le document
String[] tableName = tables.getElementNames();
//pour tous les tableaux du document ...
for (int i = 0 ; i<tableName.length; i++)
{
System.out.println(tableName[i]);
xTT = (XTextTable)UnoRuntime.queryInterface(XTextTable.class, tables.getByName(tableName[i]));
XTextTableCursor xTTC = xTT.createCursorByCellName("A2");
XText xCellA2Text = (XText)UnoRuntime.queryInterface(XText.class,xTT.getCellByName("A2"));
//récupération de la phrase contenu dans la cellule A2
String phraseA2 = xCellA2Text.getString();
//si la phraseA2 se termine par la balise [VERT]...
if (phraseA2.endsWith("[VERT]"))
{
//ajustement de la propriété verticale
XPropertySet xTPS = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTTC);
xTPS.setPropertyValue("CharRotation", new Short(rotation));
//réécriture de la phrase en vertical
xCellA2Text.setString(phraseA2);
}
}

Utilisateurs parcourant actuellement ce forum : Aucun utilisateur inscrit et 1 invité