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.

7 REPLIES
Ten 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

Don't forget to tag when it's "solved"!

Four Stars

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

@TRF @fdenis @manodwhb

 

Can you explain me in steps.

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

Ten Stars

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

tfiletouch create an empty file not an xlsx one

Francois Denis

Don't forget to tag when it's "solved"!

Twelve 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
Seven 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(); }