1
0
Fork 0

vorheriges

main
ERANZER 2024-01-09 14:32:26 +01:00
parent 0a6ad90343
commit 7cf156f229
2 changed files with 40 additions and 26 deletions

View File

@ -13,18 +13,24 @@ public class Axel {
public static void main(String[] args) throws FileNotFoundException { public static void main(String[] args) throws FileNotFoundException {
String cell, in; String cell, in;
int rows, cols; int rows, cols;
Spreadsheet spr=new Spreadsheet(99,26);
Scanner kb = new Scanner(System.in); Scanner kb = new Scanner(System.in);
System.out.printf("1. New\n"
+ "2. Load\n"
+ "Eingabe:");
in=kb.nextLine();
switch(in) {
case("1"):
System.out.print("Rows:"); System.out.print("Rows:");
rows=Integer.parseInt(kb.nextLine()); rows=Integer.parseInt(kb.nextLine());
System.out.print("Cols:"); System.out.print("Cols:");
cols=Integer.parseInt(kb.nextLine()); cols=Integer.parseInt(kb.nextLine());
Spreadsheet spr=new Spreadsheet(rows,cols); spr=new Spreadsheet(rows,cols);
//spr.put("A3", "3"); case("2"):
//spr.put("A2", "2"); System.out.print("File Name:");
spr.put("A1","=19+4"); in=kb.nextLine();
spr.put("B9", "=41+A2"); spr.readCsv("tmp/"+in);
spr.put("J5", "=7*6"); }
spr.put("J6", "=4/2");
while(true) { while(true) {
System.out.println(spr); System.out.println(spr);

View File

@ -1,8 +1,10 @@
package de.hs_mannheim.informatik.spreadsheet; package de.hs_mannheim.informatik.spreadsheet;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.Scanner;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -80,8 +82,18 @@ public class Spreadsheet {
* @return Nothing. * @return Nothing.
* @exception IOException If path does not exist. * @exception IOException If path does not exist.
*/ */
public void readCsv(String path, char separator, String startCellName) throws FileNotFoundException { public void readCsv(String path) throws FileNotFoundException {
// TODO: implement this Scanner file=new Scanner(new File(path));
String[] rowRead;
int row=0;
while(file.hasNextLine()) {
rowRead=file.nextLine().split(",");
for(int col=0;col<=rowRead.length-1;col++) {
put(row,col,rowRead[col]);
}
row++;
}
} }
/** /**
@ -95,11 +107,7 @@ public class Spreadsheet {
for (Cell[] row : cells) { for (Cell[] row : cells) {
for (Cell cell : row) { for (Cell cell : row) {
if (!cell.getFormula().isEmpty())
out.print("=" + cell.getFormula());
else
out.print(cell.getValue()); out.print(cell.getValue());
if (cell != row[cells.length-1]) if (cell != row[cells.length-1])
out.print(","); out.print(",");
} }