How to Empty a files data after the load is completed

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

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

Forteen 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
Don't forget to give kudos/accept the solution when a replay is helpful.
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.

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

Forteen 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
Don't forget to give kudos/accept the solution when a replay is helpful.
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.

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Tutorial

Introduction to Talend Open Studio for Data Integration.

Watch