I am reading several csv sheet with the opencsv
libary. I am storing the "read" csv file in hugeList = reader.readAll();
Now I only want to only write the 5th value of this huge csv sheet columnwise in another sheet.
At the moment I am standing at:
//reading all entries in a huge list
//-740 as it would take to much time to run it in "dev mode"
for (int j = 0; j < (fileList.size() - 740); j++) {
String csvFile = "C:\\Users\\" + fileList.get(j);
reader = new CSVReader(new FileReader(csvFile), ';');
hugeList = reader.readAll();
List<String[]> data = new ArrayList<String[]>();
// for(int m = 0; m < hugeList.size(); m++) {
// String[] value = hugeList.get(m);
data.add(hugeList.get(5));
// }
writer.writeAll(data);
}
However I have no idea how to write them into another column and just take the 5th value?
I really appreciate your answer!
UPDATE 1
Goal: I have saved all values from one sheet at the time in hugeList. Now I want to write only the 5th column into a new sheet.
Problem: The logic behind this goal.
UPDATE 2
This is what my code looks like right now:
//reading all entries in a huge list
for (int j = 0; j < (fileList.size() - 740); j++) {
String csvFile = "C:\\" + fileList.get(j);
reader = new CSVReader(new FileReader(csvFile), ';');
hugeList = reader.readAll();
List<String[]> data = new ArrayList<String[]>();
List<String> tmp= new ArrayList<String>();
for(int m = 0; m < hugeList.size(); m++) {
String[] values = hugeList.get(m);
tmp.add(values[0]);
}
data.add(tmp.toArray(new String[0]));
writer.writeAll(data);
}
As you can see I get my data still vertically... Why?
I thing you are already on the right way.
You have 2 possibilities.
1. data.add(hugeList.get(4));
2. for(int m = 0; m < hugeList.size(); m++) {
if(m==4){
String[] values = hugeList.get(m);
data.add(values);
break;
}
}
UPDATE
Goal: I have saved all values from one sheet at the time in hugeList. Now I want to write only the 5th column into a new sheet. Problem: The logic behind this goal.
My Approach for a result in rows
List<String[]> data = new ArrayList<String[]>();
List<String> tmp= new ArrayList<String>();
for(int m = 0; m < hugeList.size(); m++) {
String[] values = hugeList.get(m);
tmp.add(values[4]);
}
data.add(tmp.toArray(new String[0]));
}
My Approach for a result in Column
for (int j = 0; j < fileList.size(); j++) {
String csvFile = readPath + fileList.get(j);
System.out.println("Read: " + csvFile);
reader = new CSVReader(new FileReader(csvFile), ';');
hugeList = reader.readAll();
String[] data = new String[1];
for (int m = 0; m < hugeList.size(); m++) {
String[] values = hugeList.get(m);
data[0] = values[0];
writer.writeNext(data);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.