However, I've been trying to solve this for 2 days and I also have searched for an answer.
Here's my code:
Code: Select all
public void SetHeader(Header header)
{
// get an XPropertySet
unoidl.com.sun.star.style.XStyleFamiliesSupplier xSupplier = (unoidl.com.sun.star.style.XStyleFamiliesSupplier)mXDocument;
unoidl.com.sun.star.container.XNameAccess xFamilies = (unoidl.com.sun.star.container.XNameAccess)xSupplier.getStyleFamilies();
unoidl.com.sun.star.container.XNameContainer xFamily = (unoidl.com.sun.star.container.XNameContainer)xFamilies.getByName("PageStyles").Value;
unoidl.com.sun.star.style.XStyle xStyle = (unoidl.com.sun.star.style.XStyle)xFamily.getByName("Default").Value;
unoidl.com.sun.star.beans.XPropertySet xPropSet = (unoidl.com.sun.star.beans.XPropertySet)xStyle;
// set some properties - This works great!!
xPropSet.setPropertyValue("HeaderIsOn", new uno.Any(header.HeaderIsOn));
xPropSet.setPropertyValue("HeaderIsDynamicHeight", new uno.Any(header.HeaderIsDynamicHeight));
if (!header.HeaderIsDynamicHeight && header.HeaderHeight>0)
xPropSet.setPropertyValue("HeaderHeight", new uno.Any(header.HeaderHeight));
xPropSet.setPropertyValue("HeaderBodyDistance", new uno.Any(header.HeaderBodyDistance));
// set the header text in a calc document - this compiles fine but doesn't work!!
unoidl.com.sun.star.sheet.XHeaderFooterContent headercontent = (unoidl.com.sun.star.sheet.XHeaderFooterContent)xPropSet.getPropertyValue("LeftPageHeaderContent").Value;
unoidl.com.sun.star.text.XText text = (unoidl.com.sun.star.text.XText)headercontent.getCenterText();
text.setString(header.HeaderText);
// this might be the problem...
xPropSet.setPropertyValue("LeftPageHeaderContent", new uno.Any(typeof(unoidl.com.sun.star.sheet.XHeaderFooterContent),headercontent));
}
What am I doing wrong here??
I simply want to define headers/footers in calc documents in a c# program where I also have a lot of data to write in the spreadsheets.
Can anyone help me??