Well, you find the option in the respective page style of a sheet.
You can loop all page styles and set this property which should enable the grids for all possible print areas.
The following Java code written by the MRI tool enables grid printing for page style "Default":
Code: Select all
import com.sun.star.beans.PropertyVetoException;
import com.sun.star.beans.UnknownPropertyException;
import com.sun.star.beans.XPropertySet;
import com.sun.star.container.NoSuchElementException;
import com.sun.star.container.XNameAccess;
import com.sun.star.container.XNameContainer;
import com.sun.star.lang.IllegalArgumentException;
import com.sun.star.lang.WrappedTargetException;
import com.sun.star.style.XStyle;
import com.sun.star.style.XStyleFamiliesSupplier;
import com.sun.star.uno.AnyConverter;
import com.sun.star.uno.RuntimeException;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
public static void snippet(XComponentContext xComponentContext, Object oInitialTarget)
{
try
{
XStyleFamiliesSupplier xStyleFamiliesSupplier = UnoRuntime.queryInterface(
XStyleFamiliesSupplier.class, oInitialTarget);
XNameAccess xNameAccess = xStyleFamiliesSupplier.getStyleFamilies();
XNameContainer xNameContainer = UnoRuntime.queryInterface(
XNameContainer.class, xNameAccess.getByName("PageStyles"));
XNameAccess xNameAccess2 = UnoRuntime.queryInterface(
XNameAccess.class, xNameContainer);
XStyle xStyle = UnoRuntime.queryInterface(
XStyle.class, xNameAccess2.getByName("Default"));
XPropertySet xPropSet = UnoRuntime.queryInterface(
XPropertySet.class, xStyle);
boolean bPrintGrid = AnyConverter.toBoolean(xPropSet.getPropertyValue("PrintGrid"));
xPropSet.setPropertyValue("PrintGrid", true);
}
catch (IllegalArgumentException e1)
{
// , setPropertyValue
e1.printStackTrace();
}
catch (PropertyVetoException e2)
{
// setPropertyValue
e2.printStackTrace();
}
catch (WrappedTargetException e3)
{
// getByName, getPropertyValue, setPropertyValue
e3.printStackTrace();
}
catch (UnknownPropertyException e4)
{
// getPropertyValue, setPropertyValue
e4.printStackTrace();
}
catch (NoSuchElementException e5)
{
// getByName
e5.printStackTrace();
}
catch (RuntimeException e6)
{
// getByName
e6.printStackTrace();
}
}
[Tutorial] Introduction into object inspection with MRI