on 08-10-2007 6:43 PM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.