1
0
Fork 0
main
Jan 2024-01-07 14:42:58 +01:00
parent f5c29329fe
commit e5d531a7a4
3 changed files with 32 additions and 16 deletions

View File

@ -1,4 +1,10 @@
1,2 ,24,,,,
3,4 ,28,,,,
5,6 123,24,,,,
7,8 ,24,,,,
,5,,,,
,5,,,,
,200,,,,
,200,,,,
,=41+A2+10-2/3,,,,
,,,,,

1 1 2 24
2 3 4 28
3 5 123 6 24
4 7 8 24
5 5
6 5
7 200
8 200
9 =41+A2+10-2/3
10

View File

@ -1,6 +1,9 @@
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.FileOutputStream;
import java.io.PrintWriter;
import java.util.Scanner; import java.util.Scanner;
/** /**
@ -11,17 +14,17 @@ import java.util.Scanner;
public class Axel { public class Axel {
public static void main(String[] args) throws FileNotFoundException { public static void main(String[] args) throws FileNotFoundException {
Spreadsheet spr = new Spreadsheet(10,10); Spreadsheet spr = new Spreadsheet(10,6);
@SuppressWarnings("resource") @SuppressWarnings("resource")
Scanner input = new Scanner(System.in); Scanner input = new Scanner(System.in);
spr.put("A3", "123"); spr.put("A3", "123");
spr.put("B9", "=41+A2+10-2/3"); spr.put("B9", "=41+A2+10-2/3");
spr.put("B8", "2"); spr.put("B8", "200");
spr.put("B7", "20"); spr.put("B7", "200");
spr.put("B6", "42"); spr.put("B6", "5");
spr.put("B5", "23"); spr.put("B5", "5");
spr.put("B4", "24"); spr.put("B4", "24");
spr.put("B3", "24"); spr.put("B3", "24");
spr.put("B2", "28"); spr.put("B2", "28");
@ -60,7 +63,14 @@ public class Axel {
} }
}while(true); }while(true);
spr.saveCsv("tmp/test.csv"); String filePath = "Axel/resources/zahlen.csv";
try (PrintWriter writer = new PrintWriter(new FileOutputStream(filePath))) {
spr.saveCsv(writer);
System.out.println("CSV file saved successfully.");
} catch (FileNotFoundException e) {
System.err.println("Error: " + e.getMessage());
}
} }
} }

View File

@ -25,12 +25,13 @@ public class Spreadsheet {
*/ */
public Spreadsheet(int rows, int cols) { public Spreadsheet(int rows, int cols) {
// TODO limit the maximum size on 99 (1..99) rows and 26 (A..Z) columns int rowWithMax99= Math.min(rows, 99);
int colWithMax26= Math.min(cols, 26);
cells = new Cell[rows][cols]; cells = new Cell[rowWithMax99][colWithMax26];
for (int r = 0; r < rows; r++) for (int r = 0; r < rowWithMax99; r++)
for (int c = 0; c < cols; c++) for (int c = 0; c < colWithMax26; c++)
cells[r][c] = new Cell(); cells[r][c] = new Cell();
} }
@ -100,8 +101,7 @@ public class Spreadsheet {
* @return Nothing. * @return Nothing.
* @exception IOException If path does not exist. * @exception IOException If path does not exist.
*/ */
public void saveCsv(String path) throws FileNotFoundException { public void saveCsv(PrintWriter out) throws FileNotFoundException {
PrintWriter out = new PrintWriter(path);
for (Cell[] row : cells) { for (Cell[] row : cells) {
for (Cell cell : row) { for (Cell cell : row) {