Prevent Unoconv From Exporting Hidden Sheets From Excel Documents

At work we use unoconv—a python script that serves as a nice frontend to the UNO document APIs in LibreOffice/OpenOffice—as part of our pipeline for creating preview PDFs and rasterized thumbnail images for a variety of document formats. Recently we had an issue where our thumbnail for a Excel spreadsheet document inexplicably didn’t match the original document. It turned out that the thumbnail was being created for the first sheet, which didn’t display in Excel because it was marked hidden. I couldn’t find any toggle or filter to prevent unoconv from “printing” hidden sheets to PDF, and ended up having to just add a few lines to unconv itself:

# Remove hidden sheets from spreadsheets:
phase = "remove hidden sheets"
try:
  for sheet in document.Sheets:
    if sheet.IsVisible==False:
      document.Sheets.removeByName(sheet.Name)
except AttributeError:
  pass

I added that just before the “# Export phase” comment, around line 1110 of the current version of unoconv (0.8.2) as I write this.

I don’t know why this wasn’t the default behavior in LibreOffice, since non-printing export targets like HTML correctly skip the hidden sheet—shouldn’t your printout match what you see on screen?

I’m sharing this as a blog post (rather than submitting a pull request) because unoconv is now “deprecated” according to its GitHub page, which recommends using a rewrite called unoserver in its place. That sounds nice, but for now our unoconv setup is working nicely, especially now that we aren’t creating thumbnails of hidden sheets!

Leave a comment