From d9b6ff91400299c4f9a74b97be801a84688977a7 Mon Sep 17 00:00:00 2001 From: selim Date: Tue, 26 Dec 2023 03:12:33 +0100 Subject: [PATCH] Spreadsheet readCsv implemented. --- .../informatik/spreadsheet/Spreadsheet.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index a85722f..b1b25d9 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -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 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