Home » excel » excel – R: Hide worksheet with package xlsx

excel – R: Hide worksheet with package xlsx

Posted by: admin April 23, 2020 Leave a comment

Questions:

I’ve had great success with the R package xlsx for many things. However, in the documentation, it says “the user has control to set colors, fonts, data formats, add borders, hide/unhide sheets, add/remove rows, add/remove sheets, etc.” (Emphasis mine.)

However, I’ve scoured the documentation and can’t find the function to hide sheets. Can someone point me to it? Thanks!

Documentation at http://cran.r-project.org/web/packages/xlsx/xlsx.pdf if this helps.

How to&Answers:

So that others having the same problem can find the answer, here is how developer Adrian Dragulescu replied to my email:

Once you have a workbook

wb <- createWorkbook()

you can do

wb$setSheetHidden(0L, 1L)

if you want to hide the first sheet (0-based indexing in Java).
See the documentation here: http://poi.apache.org/apidocs/org/apache/poi/xssf/usermodel/XSSFWorkbook.html#setSheetHidden(int, int)

I can confirm this works, and many thanks to Mr. Dragulescu.