1
0
Fork 0

Added the "readCsv" method.

main
Florian Hörner 2024-01-04 20:49:03 +01:00
parent 4f38207c3b
commit 43694e5845
1 changed files with 27 additions and 0 deletions

View File

@ -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<String> 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<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;
}
/**