Discussion

1
Replies
523
Views
Sujith123 Member since 2017 9 posts
NttData Services pvt ltd
Posted: 2 years ago
Last activity: 2 years 6 months ago

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
	[OpenSpan.TypeManagement.DynamicTypeAttribute()]
	[OpenSpan.Design.ComponentIdentityAttribute("Script-8D590D1903B1064")]
	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
Share this page LinkedIn