Why my excel is corrupted while i am stopping Katalon?

Hello.
I just furious about my test data is getting corrupted 3 times (I have the files on it for documentation and remembering me for this pain). Why is my excel corrupt ? It doesnt have any trigget whatsoever.

1 Like

I did not get your question

Let me explain it little further.
I was running as Test Suite. I use Excel for documenting the case that i run. While i was stopping the test suite, i saw my excel size is become 0kb. It happens before when i was running as Test Case.
My question is why is my excel corrupted ?

Could you try recreating your excel and then check?

pls try json/yaml files as test data instead of excel

Lucky that i copied my excel. I test with that. and it works
IF its corrupt, what thing that i should check ? You can give me instruction so i can do checking / recreating with your step

Sorry for late replying. The excel is used for users too, not just engineer. Excel is expected to user-friendly and every user can test it without knowledge of katalon itself.

1 Like

I do not see what you mean here.

Please show us how your code is using an Excel file.

Some screenshot will do. Some copy&paste of your test case script will also do. Let us see it.

I cant do it since its credential, but i use excel for documenting means i write to excel about status on the case. For example, if i run the first column successful, i write to excel that the first column is success.
For the code itself, its similar to Katalon writing data to excel - #2 by grylion54
Also, i use some find row on excel. its similar to groovy - Katalon - get the no of rows in excel - Stack Overflow

I got my excel is corrupted from that 2.

You wrote:

You wrote your code is similar to the grylyon54 code, which has the following fragment:

...
cell.setCellValue(gUserLastName);

FileOutputStream fos = new FileOutputStream(gTestIdPathWay);
workbook.write(fos);
fos.close();
fis.close();

Are you sure your code does call fos.close()?

I guess your code does not call fos.close().

So when you stopped Katalon, the FileOutputStream was still opened; The FileOutputStream was interrupted by you stopping Katalon; so the xlsx file was corrupted.

You must call FileOutputStream.flush() and FileOutputStream.close() everytime your code updates the Workbook object.

1 Like

i do use .close() on the writing status
(sample codes)
FileOutputStream outFile = new FileOutputStream(new File(filePath))
workbook.write(outFile)
outFile.close().

But i dont put fis.close() on finding rows. My finding rows doesnt have fos. Is it okay to put fis.close() that doesnt have fos ?

You should call FileOutputStream.flush() as well.

workbook.write(outFile)
outFile.flush()
outFile.close()
1 Like

understood. i will try that. Thanks sir. I will open new forum if the corrupt happens again.

1 Like

Hello, i was trying 5 minutes ago and it stills doing corrupt. The last one that i stop is when its wiriting on excel.

@Keyword
writeToExcel(String filePath, String sheetName, int rowNo, int collNo, String cellValue) {
	FileInputStream file = new FileInputStream (new File(filePath))

	XSSFWorkbook workbook = new XSSFWorkbook(file)
	XSSFSheet sheet = workbook.getSheet(sheetName)

	'Write data to excel'
	sheet.getRow(rowNo).createCell(collNo).setCellValue(cellValue)

	file.close()
	FileOutputStream outFile = new FileOutputStream(new File(filePath))
	workbook.write(outFile)
	outFile.flush()
	outFile.close()
}

this is my keyword for it.

1 Like

show the log with error messages please

Its corrupt on there.
Honestly, i dont have the concrete screenshot that the excel is corrupt, BUT the size is 0kb. From xx sheets become 1 sheet and the name of sheet is name of files (so f.e. files is Excel Test. Sheet’s name Excel Test.

1 Like

I have no more idea. I will quit, sorry.

Thank you for your hard work sir. Much appreciate

Same issue was faced at my end, when we stop katalon in-between execution of testcases, then excel is corrupted with size 0kb

for me, test cases and test suites.