Forum Discussion

Aiyapcode's avatar
Aiyapcode
New Member
4 years ago
Solved

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.goToSheet("Sheet2")
workbook.goToPosition(0, 0) //Searches for particular test program in the first column ex:Test8

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

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

}

  • 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.

3 Replies

  • richie's avatar
    richie
    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?

    Ta

    Rich
  • nmrao's avatar
    nmrao
    Champion Level 3
    Can you please simplify the question and tell what regular expression you need?
    • sonya_m's avatar
      sonya_m
      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.