Excel File execution error

Hi,

While handling with the excel file in katalon, I am receiving the attached error and below is the code that I have used for execution.

Can you please look into this and guide me ?

Groovy Code:

public XSSFWorkbook workbook
public FileInputStream file

@And(“testing the running file indicator”)
def test_running_file_indicator() {
file = new FileInputStream (new File(“D:\Test5.xlsx”))
workbook = new XSSFWorkbook(file)
XSSFSheet sheet = workbook.getSheet(‘Sheet1’)

sheet.getRow(0).createCell(0).setCellValue(“Venkat”)
WebUI.delay(10)
file.close()

FileOutputStream outFile = new FileOutputStream(new File(“D:\Test5.xlsx”))
workbook.write(outFile)
outFile.close()

hei, i think you should explain what are you trying to achieve here…

@purbo
As per the code above, I just want to enter some value in the excel sheet , save and close it.
Please let me know if any questions.

okay.

def updateExcelSingle(def file_name, def singleData){

	FileInputStream inputStream = new FileInputStream(new File(file_name))
	Workbook workbook = WorkbookFactory.create(inputStream)
	Sheet sheet = workbook.getSheetAt(0)
	Object[][] results = singleData
	def intRow = sheet.getLastRowNum()
	Row row = sheet.createRow(intRow+1);
	int columnCount = 0;
	for (Object field : singleData) {
		Cell cell = row.createCell(columnCount++);
		if (field instanceof String) {
			cell.setCellValue((String) field);
		} else if (field instanceof Integer) {
			cell.setCellValue((Integer) field);
		}
	}
	inputStream.close();
	FileOutputStream outputStream = new FileOutputStream(file_name);
	workbook.write(outputStream);
	outputStream.close();
}

try this…
file_name = “Data Files/Report/report.xlsx” //you change it to wherever your excel file is
data = [“data1”, “data2”] //change it to your data, this is function to add new data

@purbo, It is working… Thank You.

1 Like