Export .xlsx file to .pdf with grid lines

The Application Programming Interface and the OASIS Open Document Format

Export .xlsx file to .pdf with grid lines

Postby kimura » Thu Sep 25, 2014 8:44 pm

When I try to export an .xlsx file to .pdf, the exported file does not contain gridlines. I have been looking for an option that forces gridlines to show for exported files. Many of my search results have only turned up results for handling exports in the actual GUI application. I am running Java code that does the conversions for me.

I've tried to set the PrintGrid property to be true, but I was unsuccessful. Here is the code:
Code: Select all   Expand viewCollapse view
// this.document refers to the XComponent in question
XPropertySet xProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, this.document);
xProp.setPropertyValue("PrintGrid", new Boolean(true));

Any idea of how to enable the grid while exporting to PDF?
OpenOffice 3.5
Ubuntu 12
Posts: 1
Joined: Thu Sep 25, 2014 8:33 pm

Re: Export .xlsx file to .pdf with grid lines

Postby Villeroy » Thu Sep 25, 2014 9:37 pm

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   Expand viewCollapse view
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)
      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
   catch (PropertyVetoException e2)
      // setPropertyValue
   catch (WrappedTargetException e3)
      // getByName, getPropertyValue, setPropertyValue
   catch (UnknownPropertyException e4)
      // getPropertyValue, setPropertyValue
   catch (NoSuchElementException e5)
      // getByName
   catch (RuntimeException e6)
      // getByName

[Tutorial] Introduction into object inspection with MRI
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.4
User avatar
Posts: 27886
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Return to UNO API and ODF

Who is online

Users browsing this forum: No registered users and 1 guest