aloizio schreef:
Andrew,
I am using this two methods to put header in my document, the problem is
that the header appear in all pages. It must appear only in the first page.
I using XStyle but doesn't modify anything.
You must have 2 Pagestyles:
Page1_style: with a Header and a "next_style" who is ponting to
a Page2_Style
Page2_Style with no Header and a "nest_style" who is now also Page2_Style
You can define the Styles with te API or simply inclose themin a
template or the Doc you are using
Fernand
public void setHeader(String p_jlsHF, String p_jlsImagePath,XTextDocument
m_xTextDocument)
{
try
{
XTextCursor m_xTextCursor =
m_xTextDocument.getText().createTextCursor();
final String f_jlsPrefix = p_jlsHF.equals("H") ? "Header" : "Footer";
//m_xTextCursor é classe membro que especifica o XTextCursor do
XTextDocument atual
XPropertySet xPageProps = (XPropertySet)UnoRuntime.
queryInterface(XPropertySet.class, m_xTextCursor);
String jlsPageStyleName = (String)xPageProps.
getPropertyValue("PageStyleName");
XStyleFamiliesSupplier xSupplier = (XStyleFamiliesSupplier)UnoRuntime.
queryInterface(XStyleFamiliesSupplier.class, m_xTextDocument);
//Usa a interface StyleFamiliesSupplier para obter a interface
XNameAccess
// da familia de estilos atual
XNameAccess xFamilies = (XNameAccess)UnoRuntime.
queryInterface(XNameAccess.class, xSupplier.getStyleFamilies());
//acessa a familia 'PageStyles'
XNameContainer xFamily = (XNameContainer)UnoRuntime.
queryInterface(XNameContainer.class,
xFamilies.getByName("PageStyles"));
//obter o estilo para a familia PageStyles
XStyle xStyle = (XStyle)UnoRuntime.queryInterface(XStyle.class,
xFamily.getByName(jlsPageStyleName));
/*XStyle xStyle = (XStyle)
UnoRuntime.queryInterface(
XStyle.class, xFamily.getByName("First Page"));
XPropertySet xStyleProps = (XPropertySet)
UnoRuntime.queryInterface(XPropertySet.class, xStyle);
xStyleProps.setPropertyValue("FollowStyle", "Right Page");*/
//obter a propriedade do TextCursor Sabe
XPropertySet xStyleProps = (XPropertySet)UnoRuntime.
queryInterface(XPropertySet.class, xStyle);
//O cabeçalho/rodapé deve existir
xStyleProps.setPropertyValue(f_jlsPrefix + "IsOn", new Boolean(true));
//obter cabeçalho/rodapé
XText xText = (XText)UnoRuntime.queryInterface(XText.class,
xStyleProps.
getPropertyValue(f_jlsPrefix + "Text"));
XTextCursor xTextCursor = xText.createTextCursor();
getFachadaOpenOffice().inserirCabecalho(m_xTextDocument,
xText.getStart());
xTextCursor.gotoEnd(false);
//p_jlsText é o parâmetro a ser inserido no cabeçalho/rodapé
//xText.insertString(xTextCursor, p_jlsText, false);
} catch (UnknownPropertyException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (PropertyVetoException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (WrappedTargetException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchElementException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
public void inserirCabecalho(XComponent document, XTextRange bookmark) {
try {
String imageUrl= "";
String imageName = getDiretorioBase() + "imagens//" +
getCabecalhoDocumento();
Image image = null;
File imageFile = new File(imageName);
try
{
imageUrl = ("file:///" + imageFile.getCanonicalPath()).replace('\\',
'/');
image = ImageIO.read(imageFile);
} catch (java.io.IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
short hOrientation = HoriOrientation.LEFT; // Escolher HoriOrientation
short vOrientation = VertOrientation.TOP; // Escolher VertOrientation
int imageWidth;
int imageHeight;
int enlargement = 18; // depende do tamanho da imagem
if (image != null) {
imageWidth = (image.getWidth(null) * enlargement);
imageHeight = (image.getHeight(null) * enlargement );
image.flush();
} else {
imageWidth = 100;
imageHeight = 100;
System.out.println("Something is wrong with the image.");
}
TextContentAnchorType oTCAT = null; // Choose among
TextContentAnchorType elements
WrapTextMode oWTM = null; // Choose among WrapTextMode elements
// Create graphic object
XMultiServiceFactory xWriterFactory = (XMultiServiceFactory)
UnoRuntime.
queryInterface(XMultiServiceFactory.class, document);
Object graphicObject =
xWriterFactory.createInstance("com.sun.star.text.GraphicObject");
// set propriedades
XPropertySet xPropSet = (XPropertySet) UnoRuntime.
queryInterface(XPropertySet.class, graphicObject);
xPropSet.setPropertyValue("GraphicURL", imageUrl);
xPropSet.setPropertyValue("HoriOrient", new Short(hOrientation));
xPropSet.setPropertyValue("VertOrient", new Short(vOrientation));
xPropSet.setPropertyValue("Width", new Integer(imageWidth));
xPropSet.setPropertyValue("Height", new Integer(imageHeight));
xPropSet.setPropertyValue("AnchorType", oTCAT);
xPropSet.setPropertyValue("TextWrap", oWTM);
XStyleFamiliesSupplier xSupplier = (XStyleFamiliesSupplier)UnoRuntime.
queryInterface(XStyleFamiliesSupplier.class, document);
XNameAccess xFamilies = (XNameAccess)UnoRuntime.
queryInterface(XNameAccess.class, xSupplier.getStyleFamilies());
XNameContainer xFamily = (XNameContainer)UnoRuntime.
queryInterface(XNameContainer.class,
xFamilies.getByName("PageStyles"));
XStyle xStyle = (XStyle)
UnoRuntime.queryInterface(
XStyle.class, xFamily.getByName("First Page"));
XPropertySet xStyleProps = (XPropertySet)
UnoRuntime.queryInterface(XPropertySet.class, xStyle);
xStyleProps.setPropertyValue("FollowStyle", "Right Page");
// Inserir objeto gráfico
XTextContent xGraphicObjectTextContent = (XTextContent) UnoRuntime.
queryInterface(XTextContent.class, graphicObject);
bookmark.getText().insertTextContent(bookmark,
xGraphicObjectTextContent, false);
} catch (com.sun.star.uno.Exception e) {
e.printStackTrace();
} catch (com.sun.star.uno.RuntimeException e) {
e.printStackTrace();
}
}
Andrew Douglas Pitonyak wrote:
aloizio wrote:
I don't understand styles well enough yet. Have you some example code? I
have been working with OpenOffice API for three months.
First, you need to know how to do this using the GUI. In other words,
you must understand how styles work. After you understand styles and how
to use them, then, and only then, should you attempt to code it using
the API. If you do not understand how styles work, then understanding
how to manipulate them from the API will not help.
I recommend that you start with the documentation project and/or the
user's guide to first learn how to use styles.
--
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.odt
My Book: http://www.hentzenwerke.com/catalog/oome.htm
Info: http://www.pitonyak.org/oo.php
See Also: http://documentation.openoffice.org/HOW_TO/index.html
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]