Ask a Question

How to use a regex in groovy for reading a excel file and assign a value.

New Member

How to use a regex in groovy for reading a excel file and assign a value.

hallo, I am trying to read an xls file having few columns and rows. I am getting a string value from an api and from this string value i am trying to look into the row having six values. There is an output value which i then compare and assign a closest value to it and choose which columnnamenumber.

Let me explain with an example with the picture i have attached. In this case, i get a string value "test8" this excel makes a search and i have already implemented and i get the result for example "test8" with a output value 176. Now the row values which are in test8 are 174 181 192 204 211 My task is in reading this alle row cell values which is assigned to row "test8" If have a output value for a number 176 from the below code def output= bucket.getoutput(). Here maybe i need to use regex. i do not know! i wanted to use it for the previous row value in this case for 174 from six row values. Then it would search for which column header it is assigned, in this case it would be -1. If the output value was somewhere in around 191-204 ex(198). Then it should setcolumn name to +1. Please helpme in building/suggesting it. I have added my class file. I am not getting the right output i need. I have defined in the line def value.
ps: Sheet1 code looks for the program from the data slotnumber which is already been implented. case1,case2 is minimumvalue and maximumvalue.

I tried :

private void calculateweight(BBucket bucket, ZWorkbookImpl workbook)
//find right row, extract data
try {
def testProgram = bucket.getTestProgram()
workbook.goToPosition(0, 0) //Searches for particular test program in the first column ex:Test8

if(workbook.readCell(false).contentEquals(testProgram)) // Here it finds Test8, now how to get the values of row Test8 ??
der value = //Todo "read the values of particular row and take one value which fits"
container.getAll(new FilterAllDomainObjects()).each{e ->
//calculate program
//Store program on the stent

catch (Exception e)
throw new Exception("Error parsing ${fileName} file", e)


Community Hero

Hey @Aiyapcode,

You didnt attach any spreadsheet or anything. Can you attach the spreadsheet you mention so we can visualise what youre talking about?


if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Community Hero

Can you please simplify the question and tell what regular expression you need?

SmartBear Alumni (Retired)

Hi @Aiyapcode ! Looks like the Community needs more info from you to help you solve this! Could you provide the details, or share your solution if you managed to find it already!


Alternatively, you can contact our Customer Care team here.

Sonya Mihaljova
Community and Education Specialist

Showing results for 
Search instead for 
Did you mean: