How to Empty a files data after the load is completed

Four Stars

How to Empty a files data after the load is completed

Requirement is:

Tfileinputexcel ----> Tfileoutputexcel  ------> after loading into the output. i want to empty the inputexcel file without deleting the file.

How to achieve this.

Eleven Stars

Re: How to Empty a files data after the load is completed

count number of rows and fill them with null or blank.

Francois Denis

Tag as "solved" for others! Kudos to thanks!

Four Stars

Re: How to Empty a files data after the load is completed

@TRF @fdenis @manodwhb

 

Can you explain me in steps.

Thirteen Stars

Re: How to Empty a files data after the load is completed

@ravi777,Once the file has loaded and then take on subjob ok and delete the existing file or archive the file and create a new file as similar with your source file columns.

Manohar B
Four Stars

Re: How to Empty a files data after the load is completed

But when i am creating new .xlsx file using tfiletouch. it is creating but not able to open it.

Eleven Stars

Re: How to Empty a files data after the load is completed

tfiletouch create an empty file not an xlsx one

Francois Denis

Tag as "solved" for others! Kudos to thanks!

Thirteen Stars

Re: How to Empty a files data after the load is completed

@ravi777,you need to create with below way.

 

tFilxedInputFlow-->tFileExceloutput

Manohar B
Nine Stars

Re: How to Empty a files data after the load is completed

@ravi777 - if you want a java solution to handle excel files then you can write a routine and invoke that in your talend job something like this - 

JavaRoutine-1.JPG

And, you can use below code to check and delete all rows from your excel file - 

FileInputStream ExcelFileToRead = new FileInputStream(filePath);
XSSFWorkbook workbook = new XSSFWorkbook(ExcelFileToRead);
Sheet sheet = workbook.getSheetAt(0);
String sheetName = sheet.getSheetName();
int numberOfRows = sheet.getPhysicalNumberOfRows();
if(numberOfRows > 0) {
		for (int index = sheet.getLastRowNum(); index >= sheet.getFirstRowNum(); index--) {
		//System.out.println(index);
		if(sheet.getRow(index) != null) {
		sheet.removeRow( sheet.getRow(index));
		}
		else{
		    System.out.println("Info: clean sheet");
		}
} } ExcelFileToRead.close(); // Write the output to the file FileOutputStream ExcelFileToWrite = new FileOutputStream(filePath); workbook.write(ExcelFileToWrite); ExcelFileToWrite.close();
// Closing the workbook workbook.close(); }

 

 

Moderator

Re: How to Empty a files data after the load is completed

Hello ravi777,

Is there any update for your issue?

Best regards

Sabrina

--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.