 | OO-Snippets: Setting page to A3Commons| Keywords | page format, DIN Formats |
|---|
| Language | Java |
|---|
| Application | Calc |
|---|
| Authors | Tom Schindl (initial)
|
|---|
| Supported Versions | 1.1.4 1.1.x |
|---|
| Supported OS | All |
|---|
| 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. |
|---|
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 {
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) );
}
}
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") );
xPropertySet.setPropertyValue("Size",PageFormatUtils.A3);
PageFormatUtils.switchToLandscape(xPropertySet);
}
}
|
Changelog| Date | User | Modification |
|---|
| 2005-03-10 | tomsontom | Initial version |
|