Como faço para definir as propriedades para um xTextTable no OpenOffice.org UNO usando C#?
-
22-09-2019 - |
Pergunta
Em Python, eu posso fazer algo assim:
table.BreakType = PAGE_BEFORE
table.HoriOrient = 0
table.RightMargin = 6.93 * 2540 - table_width
Em C#, não consigo encontrar uma maneira de definir propriedades. O XTableTable possui apenas alguns métodos disponíveis, e nenhum deles parece fazer algo assim. Como faço para definir propriedades em C#?
Solução
Você precisa acessar a tabela através da interface XPropertySet. Você pode fazer isso lançando a tabela para um XPropertSet:
// Example
XPropertySet tablePropSet = (XPropertySet)textTable;
// This is how you set a property in C#
// You have to create a new Any object to pass it as parameter
tablePropSet.setPropertyValue("HeaderRowCount", new Any(typeof(int), 1));
O objeto "qualquer" está no espaço para nome "uno" (não unoidl.com.sun.star.uno). Você realmente não precisa fazer
typeof(int)
A menos que o tipo não seja um tipo básico.
new Any(1)
Funciona bem para tipos básicos.
Exemplo de BreakType:
XPropertySet tablePropertySet = (XPropertySet)table;
tablePropertySet.setPropertyValue
("BreakType", new Any(typeof(BreakType), BreakType.PAGE_BEFORE));
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow