Using custom action to open an Excel file

excel

#1

Hi,

I see from the documentation that com.workfusion.rpa.helpers provides support for excel file manipulation. Reliably opening files is one issue that I have a problem making work and I would like to make a custom action for this.

Unfortunately I can’t get this to work. Could someone help with writing a simple script to open a file so that I can see the structure of how to use the Custom Action, the existing samples have not really helped me understand how to use this new feature.

All help welcome!


#2

Here is a very basic script to open a file and copy cell value.

@CustomScriptAction(
output='cell_value'
 )
def customScript() {

openExcel("path/to/excel/file")
cell_value = RString.of(getCell("path/to/excel/file", "cell/position"))
saveExcel("path/to/excel/file")
closeExcel("path/to/excel/file")

}

But it is already implemented in the excel actions we have in the library, and you need to be an experienced developer for more complex excel automation.

What are the issues that you currently have with opening excel files? Is it working unstably?


#3

I do actually have some issues with opening a file when I want to open it without using the excel actions. I usually try to do it using images but it is not reliable, even when I pin the file.

However, I would like to play around with Groovy except that I can’t even get very basic scripts to work so I’m clearly doing something wrong. I couldn’t get your example to run with the following code:

Am I missing some step to get the code to execute?


#4

You should use double backslashes in the path instead of single one.
Sorry, forgot to write about it in my previous post.


#5

Missed that in your message at first.
The script above actually opens Excel in background, too.
Do you need to open the file and be able to use Excel UI?


#6

That’s exactly right. If I want to open an excel file and make some manipulations (such as make calculations and then copy some things back to recorder) then I have problems with reliably opening the file in a persistent Excel instance. The only way I know to do this is using image recognition but I have real difficulty making it work reliably even with the file pinned in explorer.

I would like to make a custom object to open excel and a file path so that I could pass a parameter with the file name and path and be sure it would open on every try. I have made some progress with learning groovy so may get this done myself eventually…but if anybody can help? Well that would be just great!!!


#7

Have you tried opening the file via Win+r? That should be stable as long as the path to the file doesn’t change.


#8

When I try to do that I get the following error:

It does not open the file - I still need to select Excel even with the full path including .xlsx extention and then Excel gives the above error.


#9

Does it happen to all Excel files? Must be excel-related issue.
This should open the file just like via images.


#10

@Bonnero If you want to use custom actions, you can open Excel file like this

@CustomScriptAction(
)
 
def customScript() {
    openAndFocus("C:\\Program Files (x86)\\Microsoft Office\\root\\Office16\\EXCEL.EXE D:\\file-name.xlsx", 5000, 300)
}