OO-Snippets: Setting page to A3

Commons

Keywordspage format, DIN Formats
LanguageJava
ApplicationCalc
AuthorsTom Schindl (initial)
Supported Versions1.1.4  1.1.x  
Supported OSAll  
Question How can I set the page format to A3

In the GUI when I switch the Format in the DropDown the size is set automatically.

Isn't there any uno-service I could use for this purpose

Answer

No. The dialog has an internal list but there is no uno-service available for this purpose.

Code-Snippet-Listing (snippet-source)

import com.sun.star.awt.Size;
import com.sun.star.beans.PropertyVetoException;
import com.sun.star.beans.UnknownPropertyException;
import com.sun.star.beans.XPropertySet;
import com.sun.star.lang.IllegalArgumentException;
import com.sun.star.lang.WrappedTargetException;

public class PageFormatUtils {
    public final static Size A5, A4, A3;
    public final static Size B4, B5, B6;
    
    static {
        A5 = new Size(14800,21000);
        A4 = new Size(21000,29700);
        A3 = new Size(29700,42000);
        
        B4 = new Size(25000,35300);
        B5 = new Size(17600,25000);
        B6 = new Size(12500,17600);
    }
    
    public static void switchToLandscape( XPropertySet pageProperties ) throws UnknownPropertyException, WrappedTargetException, PropertyVetoException, IllegalArgumentException {
        
        /*
         * Check if it is not already landscape
         */
        if( ! ((Boolean)pageProperties.getPropertyValue("IsLandscape")).booleanValue() ) {
            Size size = (Size)pageProperties.getPropertyValue("Size");
            int width = size.Width;
            size.Width = size.Height;
            size.Height = width;
            pageProperties.setPropertyValue("Size",size);
            pageProperties.setPropertyValue("IsLandscape",new Boolean(true) );
        }
    }

     /*
      * Great bunch of code
      * .........
      */

     public void settingPageOrientationAndSize() {
         XSpreadsheetDocument xSpreadsheetDocument = (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class, xCalcComponent);
         
          XStyleFamiliesSupplier xSupplier = ( XStyleFamiliesSupplier ) UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, xSpreadsheetDocument );
          XNameAccess xNameAccess = xSupplier.getStyleFamilies();
          XNameContainer xPageStyleCollection = (XNameContainer) UnoRuntime.queryInterface(XNameContainer.class, xNameAccess.getByName( "PageStyles" ));
          XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xPageStyleCollection.getByName("Default") );

          // Switch the size
          xPropertySet.setPropertyValue("Size",PageFormatUtils.A3);
          // Switch the orientation to landscape
          PageFormatUtils.switchToLandscape(xPropertySet);
     }
}

Changelog

DateUserModification
2005-03-10tomsontomInitial version

and