Apply Password to the existing excel without using excel application scope

HI All,

i want to apply password to the excel but office is not installed in prod. machine so cant use excel application scope.
Also cant use any external package from manage packages.
is their any way i can achieve it.

zip an excel and apply password to zip folder is my current approach but it is not working when we need to edit content in the excel.After editing manually need to apply password.as password is initially applied on zip and not on excel

so i want to apply password directly on excel

You can try using the Invoke Code activity to manipulate the Excel file. You’ll need the OpenXML library since Excel isn’t installed. If Excel were installed, you’d be able to use Interops.Excel.
VB Code.txt (670 Bytes)

Hope this works for you!

@TUSHAR_DIWASE,

Try this approach.
Use Append Range Workbook activity and provide password in password property.

Here you can use a temporary datatable with no rows so your original file will not be affected.

1 Like

thanks for reply . it gives error “file is not encrypted but you provided password.”

thanks for the quick feedback.
i am getting error after putting vb into invoke code + openxml is not able to find in import section of studio.

small sample workflow will be very helpful

@TUSHAR_DIWASE, Ohh ok.

Is your original file too much formatted or have just the data. If not formatted, you can use Read Range activity to read the data and write range to write it to another file with password.

thanks for suggestion but file contain formate and thousands of record .so creating new one will not work in my case

Ok @TUSHAR_DIWASE,

Without Excel it would be a hard solution but let’s see what other experts suggests.

1 Like

Your request is a bit unclear…
How do you “edit content in the excel” without having excel installed?
What means “editing manually”?

Cheers

Maybe this might help. Creating password protected sheet is discussed from 19:00.

Cheers

@J0ska
thanks for reply.
due to environment restriction, i am not able to upload any external package.
Microsoft office is not present .
I want to apply password to existing excel

As I wrote before it is no very clear what you want to achieve.
You mentioned working with excel and zip, some manual editing etc…

In principle there are two levels of password protection in Excel:
1/ file openning protection (encryption)


you can’t achieve this without excel

2/ file editing protection


this can be achieved by “ClosedXML” package that is a dependency of UiPath.Excel.Activities
image

e.g. following code can be used for it:

xls = New ClosedXML.Excel.XLWorkbook("protect.xlsx")
Dim sheet = xls.Worksheet("Sheet1")
Dim prot = sheet.Protect("123")
prot.AllowedElements = XLSheetProtectionElements.InsertRows Or XLSheetProtectionElements.InsertColumns
xls.SaveAs("protect.xlsx")

Cheers

1 Like