1
0
Fork 0

Spreadsheet readCsv implemented.

pull/1/head
selim 2023-12-26 03:12:33 +01:00
parent be62fac688
commit d9b6ff9140
1 changed files with 20 additions and 1 deletions

View File

@ -1,8 +1,11 @@
package de.hs_mannheim.informatik.spreadsheet;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -79,7 +82,23 @@ public class Spreadsheet {
* @throws IOException If path does not exist.
*/
public void readCsv(String path, char separator, String startCellName) throws FileNotFoundException {
// TODO: implement this
Scanner sc = new Scanner(new File(path));
ArrayList<String> memList = new ArrayList<>();
while (sc.hasNextLine()) {
memList.add(sc.nextLine());
}
String[][] memArr = new String[memList.size()][];
for(int i = 0; i < memList.size(); i++)
memArr[i] = (memList.get(i)).split(String.valueOf(separator));
for (int r = getRow(startCellName); r < memList.size(); r++)
for (int c = getCol(startCellName); c < memList.get(0).length(); c++)
if(c<memArr[r].length)
put(r, c, memArr[r][c]);
sc.close();
}
/**