forked from hummel/PR1-Spreadsheet
vorheriges
parent
0a6ad90343
commit
7cf156f229
|
@ -13,18 +13,24 @@ public class Axel {
|
|||
public static void main(String[] args) throws FileNotFoundException {
|
||||
String cell, in;
|
||||
int rows, cols;
|
||||
Spreadsheet spr=new Spreadsheet(99,26);
|
||||
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:");
|
||||
rows=Integer.parseInt(kb.nextLine());
|
||||
System.out.print("Cols:");
|
||||
cols=Integer.parseInt(kb.nextLine());
|
||||
Spreadsheet spr=new Spreadsheet(rows,cols);
|
||||
//spr.put("A3", "3");
|
||||
//spr.put("A2", "2");
|
||||
spr.put("A1","=19+4");
|
||||
spr.put("B9", "=41+A2");
|
||||
spr.put("J5", "=7*6");
|
||||
spr.put("J6", "=4/2");
|
||||
spr=new Spreadsheet(rows,cols);
|
||||
case("2"):
|
||||
System.out.print("File Name:");
|
||||
in=kb.nextLine();
|
||||
spr.readCsv("tmp/"+in);
|
||||
}
|
||||
|
||||
while(true) {
|
||||
System.out.println(spr);
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package de.hs_mannheim.informatik.spreadsheet;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Scanner;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
@ -80,8 +82,18 @@ public class Spreadsheet {
|
|||
* @return Nothing.
|
||||
* @exception IOException If path does not exist.
|
||||
*/
|
||||
public void readCsv(String path, char separator, String startCellName) throws FileNotFoundException {
|
||||
// TODO: implement this
|
||||
public void readCsv(String path) throws FileNotFoundException {
|
||||
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 cell : row) {
|
||||
if (!cell.getFormula().isEmpty())
|
||||
out.print("=" + cell.getFormula());
|
||||
else
|
||||
out.print(cell.getValue());
|
||||
|
||||
if (cell != row[cells.length-1])
|
||||
out.print(",");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue