diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index 4ed4cac..a9c85e2 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -1,10 +1,13 @@ 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.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.ArrayList; /** * A simplified spreadsheet class for the PR1 programming lab at Hochschule Mannheim. @@ -121,6 +124,30 @@ public class Spreadsheet { */ public void readCsv(String path, char separator, String startCellName) throws FileNotFoundException { // TODO: implement this + ArrayList lines = readFile(path); + String[] einzelnde_lines = new String[lines.size()]; + int row_startcell = getRow(startCellName); + int col_startcell = getCol(startCellName); + String[][] zwischenspeicher = new String[cells.length - row_startcell][cells[0].length - col_startcell]; + for (int i = 0; i < einzelnde_lines.length; i++) { + zwischenspeicher[i] = lines.get(i).split(separator+""); // +"" um aus dem Char ein String zu machen + for (int j = 0; j < zwischenspeicher[i].length; j++) { + put(row_startcell+i,col_startcell+j,zwischenspeicher[i][j]); + } + } + } + + public static ArrayList readFile(String path) throws FileNotFoundException { + ArrayList lines = new ArrayList<>(); + Scanner sc = new Scanner(new File(path)); + + while (sc.hasNextLine()) { + lines.add(sc.nextLine()); + } + + sc.close(); + + return lines; } /**