cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the actual data of a file held in IWDResource object?

Former Member
0 Kudos

Hello,

I am uploading a csv/excel file and writing it to the server using the FuleUpload UI and IWDResource Interface.

I need to make some things on the data before I write it:

1. count the number of columns are in the csv/excel file in each line.

2. replace special characters in the file using replaceAll for example.

My problem is how to access the data once it is stored in the IWDResource interface? All I have there is the read method which generated an InputStream object to read bytes from the file.

Any ideas?

Roy

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member182294
Active Contributor
0 Kudos

If you want to read cell level or row level data from excel you should use third party APIs. Apache POI provides such an API, you can use and read the excel documents. You can refer the POI API

<a href="http://poi.apache.org/hssf/quick-guide.html#ReadWriteWorkbook">here</a>.

And if you want to read the CSV file content do the following..

FileInputStream fis=(FileInputStream)wdContext.currentContextElement().get<attribute anme>().read(false);

byte in[] = new byte[512];

String csvData;

StringBuffer csvBuffer = new StringBuffer();

while(fis.read(in)>0)

{

csvData = new String(in);

csvBuffer.append(csvData);

}

//now write the logic to validate the csv data.

Regards

Abhilash

Former Member
0 Kudos

Hi Abhilash,

Thanks a lot for your helpful response.

Actually I am familiar with POI but I find it not useful for csv's which are my main files in this case.

Can I ask why you are using this approach in case of a csv file ?

This approach indeed gives my cell by cell Strings and I can replace data but how can I count the number of columns in each row using it?

Roy

Former Member
0 Kudos

Is it possible at least to determine when a row is ending?

This way, I will be able to count the number of commas which we are using as a delimiter...

Roy

Former Member
0 Kudos

I was able to solve it with opencsv, a great Java opensource to handle csv files.

Whoever is interested can download it from <a href="http://sourceforge.net/projects/opencsv">sourceforge</a>

Roy