[C#] Can't set header text in Calc document

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
WilliamGorden
Posts: 3
Joined: Fri Jun 13, 2014 2:01 pm

[C#] Can't set header text in Calc document

Post by WilliamGorden »

I'm new here, so if this problem has a solution in another post, please show me where and I'll delete this.

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));

        }

I think the last line doesn't work. I've gotten the header content and set the text. However, I need to reassign it to the page style... I think...

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??
LibreOffice 4.1.6.2 on Windows 8.1
Post Reply