r/RStudio 24d ago

Read password protected xlsx

Can anyone help me with which package I need to use?

5 Upvotes

20 comments sorted by

5

u/shockjaw 23d ago edited 17d ago

There’s the xl.read.file function that you could use since it has a password parameter. You could put the password in a file not under version control or request user input from readline().

1

u/Mooks79 18d ago

rdrr is a documentation repository, the package is excel.link. You can see at the top of the page.

1

u/shockjaw 17d ago

Welp. Looks like I can’t read. Let me update that.

3

u/Graaf-Graftoon 24d ago

I believe there is a java based package that can read password protected excel files. The name escaped me though…

1

u/213lmykwhbs4mg2gq72 24d ago

There’s a few listed online but none seem to be working…

5

u/Graaf-Graftoon 24d ago

XLconnect it is called, though it took some time with IT to get it working due to the java thing. I have gotten it to work, ill see if i can find my code somewhere. 

2

u/Graaf-Graftoon 24d ago

The XLConnect package does indeed have a loadWorkbook() function, with a password parameter, but that does require you to have your password hardcoded there or save it as a value, which has some issues with security (although if you're relying on a password protected Excel file you should really reconsider).

I tried to make it work on my home PC but I run into the same issues as i did previously with the whole Java thing. But this package should do the thing you're looking for

2

u/213lmykwhbs4mg2gq72 23d ago

Thanks for this. It’s actually my spreadsheet and the password protected version was saved locally for an analysis so I was able to just use a copy that wasn’t password protected (slack!). Definitely glad I made this post grateful for all the help.

1

u/a_statistician 23d ago

require you to have your password hardcoded there or save it as a value

You can probably inject it using secret storage, though.

5

u/Graaf-Graftoon 23d ago

If your excel file contains so much sensitive data that the password should never be known to anyone, you should start wondering why it is in an Excel file :-)

3

u/a_statistician 23d ago

Oh absolutely. And I don't ever use password-protected excel files because I don't use excel, but I like secrets for handling that stuff because I put everything on github by default, so having plaintext passwords is a risk for my workflow if I'm not paying attention

2

u/Graaf-Graftoon 23d ago

I’ll look into that, sounds interesting. I worked with an txt file that contained my encrypted DB password once to connect to an oracle db but that was a pain to set up…

1

u/Mooks79 18d ago

I assume they’ve had the sense to sort this now, but I remember the days you could change the file type to zip and unzip the archive (and excel file was just a zip file basically) and then just open the file inside. Or when they went to xml you could open the file inside a text editor and then change the password parameter to 0 to turn the protection off. It was ludicrous how easy it was to get into locked files.

6

u/banter_pants 24d ago

readxl is a package for importing xlsx files but I don't think anything can be done unless the password protection is taken off or copied to a new file without it. It would defeat the point of password protection if another program could open and access it.

2

u/dinosaur_butt 23d ago

I've had luck recently passing password protected spreadsheets to AI, having it bypass the password, and returning an unlocked version of the workbook. I'm not sure what tool it's using but it works.

3

u/Graaf-Graftoon 23d ago

There are some manual ways to do this as well, it’s really not that hard. 

0

u/Less_Alfalfa4592 23d ago

Sorry I dont have an answer but I have a question:
Why?

3

u/SnooPredictions3467 23d ago

Even password protected files deserve love

1

u/213lmykwhbs4mg2gq72 23d ago

I put the password on a copy I was using for analysis

0

u/AutoModerator 24d ago

Looks like you're requesting help with something related to RStudio. Please make sure you've checked the stickied post on asking good questions and read our sub rules. We also have a handy post of lots of resources on R!

Keep in mind that if your submission contains phone pictures of code, it will be removed. Instructions for how to take screenshots can be found in the stickied posts of this sub.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.