Sujith Jetti (Sujith123)
NttData Services pvt ltd

NttData Services pvt ltd
Sujith123 Member since 2017 9 posts
NttData Services pvt ltd
Posted: March 26, 2018
Last activity: March 27, 2018
Posted: 26 Mar 2018 3:20 EDT
Last activity: 27 Mar 2018 4:09 EDT

How to open password protected excel solution

Hi All,

You can use below script to open the password protected excel file. it's working fine.

using System;
using System.Collections;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using System.Xml;
using Excel = Microsoft.Office.Interop.Excel;

namespace Dynamic.Script_8D590D1903B1064
	// Script generated by Pega Robotics Studio 8.0.1063.0
	// Please use caution when modifying class name, namespace or attributes
	public sealed class Script
		public void NewMethod1(string password)
		   Excel.Application excelApp = new Excel.ApplicationClass();

           // if you want to make excel visible to user, set this property to true, false by default
           excelApp.Visible = true;

           // open an existing workbook
           string workbookPath = @"C:\Users\Desktop\sample.xlsx";
           Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(workbookPath, 0, false, 5, password, "", false, Excel.XlPlatform.xlWindows, "",true, false, 0, true, false, false);
           // get all sheets in workbook
           Excel.Sheets excelSheets = excelWorkbook.Worksheets;
		  // get some sheet
          string currentSheet = "Sheet1";
          Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelSheets.get_Item(currentSheet);


***Updated by moderator: Lochan to add Categories***

Robotic Process Automation Developer Knowledge Share