forked from hummel/PR1-Spreadsheet
parent
df6ff99a0c
commit
0c46be39b4
|
@ -1,8 +1,11 @@
|
||||||
package de.hs_mannheim.informatik.spreadsheet;
|
package de.hs_mannheim.informatik.spreadsheet;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Scanner;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
@ -26,10 +29,11 @@ public class Spreadsheet {
|
||||||
|
|
||||||
cells = new Cell[rows][cols];
|
cells = new Cell[rows][cols];
|
||||||
|
|
||||||
for (int r = 0; r < 99; r++)
|
for (int r = 0; r < rows; r++)
|
||||||
for (int c = 0; c < 26; c++)
|
for (int c = 0; c < cols; c++)
|
||||||
cells[r][c] = new Cell();
|
cells[r][c] = new Cell();
|
||||||
//Fehlermeldung wenn es über 99 Zeilen und 26 Spalten sind
|
//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,7 +83,34 @@ public class Spreadsheet {
|
||||||
*/
|
*/
|
||||||
public void readCsv(String path, char separator, String startCellName) throws FileNotFoundException {
|
public void readCsv(String path, char separator, String startCellName) throws FileNotFoundException {
|
||||||
// TODO: implement this
|
// TODO: implement this
|
||||||
|
ArrayList<String> 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<String> readFile(String path) throws FileNotFoundException {
|
||||||
|
ArrayList<String> 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.
|
* A method for saving data to a CSV file.
|
||||||
|
|
Loading…
Reference in New Issue