Unable to Access Range of data in Excel using coding


#1

Hi,

I am trying to access the excel using coding but getting the error but same code is working perfectly in .net.
So can anybody please help me to know how to access range of excel sheet data to clear the contents of the cell using coding .


#2


These two activities will help.


#3

Thanks for your useful help but You can directly set using only write cell .
But my question is i want to do this thing using core coding for example:-

Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application(); Microsoft.Office.Interop.Excel.Workbook excelWorkbook = excel.Workbooks.Open(@“D:\Book1.xls”);
Microsoft.Office.Interop.Excel._Worksheet excelWorkbookWorksheet = excelWorkbook.Sheets[1];
var rng = excelWorkbookWorksheet.get_Range(“B2:E4”, Type.Missing);
rng.Cells.Clear();
excelWorkbook.Save();


#4

Yes you can.
But, You need to use VB not C#


#5

Hi!

Sorry to bring up an old topic. But does anyone know if this actually works?

I’ve tried importing the Microsoft.Office.Interop.Excel namespace, then within an Invoke code activity putting the following:
Dim xl As Microsoft.Office.Interop.Excel.Application

(Same as shown by @akhi_s27 above).

However, I get the following error message:

Main has thrown an exception

Source: Invoke code

Message: Error compiling code
error BC30002: Type 'Microsoft.Office.Interop.Excel.Application' is not defined. At line 1


Exception Type: ArgumentException

System.ArgumentException: Error compiling code
error BC30002: Type 'Microsoft.Office.Interop.Excel.Application' is not defined. At line 1

   at UiPath.Core.Activities.Workflow.CompilerRunner.Compile(String code, Int32 errLineOffset)
   at UiPath.Core.Activities.InvokeCode.GetCompilerRunner(String userCode, List`1 args, String imps)
   at UiPath.Core.Activities.InvokeCode.Execute(CodeActivityContext context)
   at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
   at System.Activities.ActivityInstance.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
   at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation) 

Anyone know what I’m doing wrong? Thanks for the help!


#6

can you send me that code please?


#7

Try adding below to your xaml file

<AssemblyReference>Microsoft.Office.Interop.Excel</AssemblyReference>

excel_Code.xaml (5.5 KB)


Opening an excel sheet without using excel application scope
#8

big help


#9

Is there away - through the application - to have this code post to the xaml?

I’ve added the Excel namespace, but I’m not seeing how - through the app - I can get the xaml to include the AssemblyReference.

Modifying the xaml isn’t an option in my case.

I appreciate any clarification you’re able to provide.

Thanks,
-J


#10

See if this activity helps


#11

hi ,

i am unable to view the xaml. i am using 2018.1.3.

i am trying to use excel code for that i have added dll using imports tab in uipath studio still i am getting reference error.


#12

There is something I’d like you to tell me.
I saw excel operation vb.net with the answer “Unable to access range of data in Excel using coding”.
I also wanted to make work that excel is realized.
However, although coding was done, it is not possible to deal with error easily.
The contents are posted in the forum.
If possible, I would like to teach you.