# Unable to get values from excel

**URL:** <https://forum.katalon.com/t/unable-to-get-values-from-excel/52555>\
**Category:** Bug Report\
**Tags:** katalon-testops\
**Created:** [March 1, 2021, 2:12pm UTC](https://forum.katalon.com/t/unable-to-get-values-from-excel/52555 "2021-03-01T14:12:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaime.delgado](https://avatars.discourse-cdn.com/v4/letter/j/9fc348/32.png) [@jaime.delgado](https://forum.katalon.com/u/jaime.delgado)\
**Post date:** [March 1, 2021, 2:12pm UTC](https://forum.katalon.com/t/unable-to-get-values-from-excel/52555/1 "2021-03-01T14:12:29Z")

</div>

Hi I have a teste case where I write values on excel. However I’m trying to get the result of the formulas in the same excel and I’m unable to. When I open the excel outside the test both values (inserted and calculated) show. So why can´t the test retrieve them?

This is the test:  
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData  
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject  
import java.awt.Robot as Robot  
import java.awt.event.KeyEvent as KeyEvent  
import org.apache.poi.ss.usermodel.Cell as Cell  
import org.apache.poi.ss.usermodel.CellValue as CellValue  
import org.apache.poi.ss.usermodel.FormulaEvaluator as FormulaEvaluator  
import org.apache.poi.xssf.usermodel.XSSFSheet as XSSFSheet  
import org.apache.poi.xssf.usermodel.XSSFWorkbook as XSSFWorkbook  
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS  
import groovy.json.JsonSlurper as JsonSlurper  
import internal.GlobalVariable as GlobalVariable

‘Allow Key input.’  
Robot robot = new Robot()

‘Open excel.’  
FileInputStream file1 = new FileInputStream(new File(‘C:\…test.xlsm’))

XSSFWorkbook workbook1 = new XSSFWorkbook(file1)

XSSFSheet sheet0 = workbook1.getSheetAt(0)

‘Write data to excel’  
Cell cell1 = sheet0.getRow(10).getCell(2)

cell1.setCellValue(datNas1aPesSegura)

robot.keyPress(KeyEvent.VK\_ENTER)

robot.keyRelease(KeyEvent.VK\_ENTER)

Cell cell2 = sheet0.getRow(11).getCell(2)

cell2.setCellValue(datNas2aPesSegura)

robot.keyPress(KeyEvent.VK\_ENTER)

robot.keyRelease(KeyEvent.VK\_ENTER)

Cell cell3 = sheet0.getRow(10).getCell(4)

cell3.setCellValue(sex1aPesSegura)

robot.keyPress(KeyEvent.VK\_ENTER)

robot.keyRelease(KeyEvent.VK\_ENTER)

Cell cell4 = sheet0.getRow(11).getCell(4)

cell4.setCellValue(sex2aPesSegura)

robot.keyPress(KeyEvent.VK\_ENTER)

robot.keyRelease(KeyEvent.VK\_ENTER)

Cell cell5 = sheet0.getRow(10).getCell(6)

cell5.setCellValue(cap1aPesSegura)

robot.keyPress(KeyEvent.VK\_ENTER)

robot.keyRelease(KeyEvent.VK\_ENTER)

Cell cell6 = sheet0.getRow(11).getCell(6)

cell6.setCellValue(cap2aPesSegura)

robot.keyPress(KeyEvent.VK\_ENTER)

robot.keyRelease(KeyEvent.VK\_ENTER)

Cell cell7 = sheet0.getRow(3).getCell(1)

cell7.setCellValue(GlobalVariable.user\_UNW)

robot.keyPress(KeyEvent.VK\_ENTER)

robot.keyRelease(KeyEvent.VK\_ENTER)

robot.keyPress(KeyEvent.VK\_F9)

robot.keyRelease(KeyEvent.VK\_F9)

sheet0.forceFormulaRecalculation

workbook1.setForceFormulaRecalculation(true)

FileOutputStream outFile1 = new FileOutputStream(new File(‘C:\…test.xlsm’))

workbook1.write(outFile1)

outFile1.close()

FileInputStream file2 = new FileInputStream(new File(‘C:\…test.xlsm’))

XSSFWorkbook workbook2 = new XSSFWorkbook(file2)

XSSFSheet sheet1 = workbook2.getSheetAt(0)

robot.keyPress(KeyEvent.VK\_F9)

robot.keyRelease(KeyEvent.VK\_F9)

‘Read data from excel’

premium\_PremioTotalFraccionadoTrimestral = sheet1.getRow(68).getCell(4).getRawValue()

System.out.println(premium\_PremioTotalFraccionadoTrimestral)

premium\_PremioTotalFraccionadoSemestral = sheet1.getRow(69).getCell(4).getRawValue()

System.out.println(premium\_PremioTotalFraccionadoSemestral)

file2.close()

FileOutputStream outFile2 = new FileOutputStream(new File(‘C:\…test.xlsm’))

workbook2.write(outFile2)

outFile2.close()

When I run this is the outcome:

![image](https://europe1.discourse-cdn.com/katalon/optimized/3X/5/4/5499a6a6d2cb39658bc579f6e5193ca5ad747e26_2_690x58.png)

Can you help me?  
Thanks in advance

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [March 2, 2021, 2:34am UTC](https://forum.katalon.com/t/unable-to-get-values-from-excel/52555/2 "2021-03-02T02:34:25Z")

</div>

> [@jaime.delgado](#):
>
> However I’m trying to get the result of the formulas in the same excel and I’m unable to.

No, you are unable to. MS Excel evaluates the formulas. Katalon is not Excel. Katalon does not understand the formulas.

If you want to utilise the result calculated by formulas defined in the excel files, do the following:

1. You open the excel book, open the worksheet, then the “formulas” are evaluated by Excel app, and the results are present in the worksheet.
2. Operate excel to save the worksheet into a CSV file. The values as formula-evaluation-result will be saved into CSV as String or Number type (not as Formula).
3. Your Katalon Studio project reads the CSV file as input. Then the values as formular-evaluation-result in CSV will be available to Katalon scripts.
4. If you want to automate Excel operation (start Excel app, open a workbook, evaluate formulas, save worksheet into CSV), you should try PowerShell. See [Open Local File - #5 by kazurayam](http://forum.katalon.com/t/open-local-file/52006/5)
