diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index 53cd48e..7abba47 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; @@ -26,10 +29,11 @@ public class Spreadsheet { cells = new Cell[rows][cols]; - for (int r = 0; r < 99; r++) - for (int c = 0; c < 26; c++) + for (int r = 0; r < rows; r++) + for (int c = 0; c < cols; c++) cells[r][c] = new Cell(); //Fehlermeldung wenn es über 99 Zeilen und 26 Spalten sind + //Oben genanntes bringt nichts. Bugfix durch zurücksetzen auf vorherigen Wert. Fehlermeldung unnötig durch if Abfrage. } // ----- @@ -79,8 +83,35 @@ public class Spreadsheet { */ public void readCsv(String path, char separator, String startCellName) throws FileNotFoundException { // TODO: implement this + ArrayList lines = readFile(path); + String[] seperateLines = new String[lines.size()]; + int startingCellRow = getRow(startCellName); + int startingCellCol = getCol(startCellName); + String[][] quickSave = new String[cells.length - startingCellRow][cells[0].length - startingCellCol]; + for (int i = 0; i < seperateLines.length; i++) { + quickSave[i] = lines.get(i).split(separator+""); //Seperator erstellt + for (int j = 0; j < quickSave[i].length; j++) { + put(startingCellRow+i,startingCellCol+j,quickSave[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; + } + + + + /** * A method for saving data to a CSV file. * @param path The file to write.