How to put password on excel fileand make it password protected

I want to apply password on excel file. But due to restriction , Microsoft office is not installed so cant use excel application scope.

How can we archive this

Does any kind of code will help

Hi TUSHAR_DIWASE,
Please check this activity in marketplace.


image

Cheers!

@TUSHAR_DIWASE ,

Sorry buddy hard luck there is no way without MS Office installation.

@jose.ordonez1 's way also will not work as it also has dependency on MS Office library.

Thanks,
Ashok :slight_smile:

Why not use a credentials asset to store the password, since that’s what it’s designed for?

Hi TUSHAR_DIWASE,
Please check this url.

Cheers!

Yes, you can use UiPath to apply a password to an Excel file without using the Excel Application Scope activity. You can achieve this by using the Invoke Code activity in UiPath along with the Interop library to manipulate Excel files. Here’s a general outline of the steps you can follow:

  1. Install the “UiPath.Excel.Activities” package if you haven’t already.
  2. Add an Invoke Code activity to your workflow.
  3. Write C# or VB.NET code inside the Invoke Code activity to open the Excel file, set a password, and save the file.

Here’s an example of C# code you can use inside the Invoke Code activity:

csharpCopy code

using Microsoft.Office.Interop.Excel;

public void SetExcelPassword(string filePath, string password)
{
    Application excelApp = new Application();
    Workbook workbook = excelApp.Workbooks.Open(filePath);
    workbook.Password = password;
    workbook.Save();
    workbook.Close();
    excelApp.Quit();
}

Make sure to adjust the file path and password parameters according to your needs.

Remember to handle exceptions and error checking appropriately in your workflow. Also, note that using the Interop library may require additional setup on your machine, such as installing the “Microsoft.Office.Interop.Excel” package via NuGet.

How about compressing the file to a zip and apply password? It could be done with UiPath activities (Activities - Compress/Zip Files).