Answer the question
In order to leave comments, you need to log in
How to add a matrix to an Excel file in Java?
Hello!
I am working on one project, purely for myself, for practice, the essence of the program is to solve a system of equations by Jordan transformations. That is, there is a matrix, it is processed a certain number of times, I want the matrix to be entered into Excel after each processing, each new matrix should be added below the previous one. But it turns out only to overwrite, as a result, only the last matrix in the file.
Workbook workbook = new HSSFWorkbook();
Sheet sheet = workbook.createSheet("Жорданові перетворення");
for (int i = 0; i < arr.length; i++) {
Row row = sheet.createRow(i);
for (int j = 0; j < arr[i].length; j++) {
Cell cell = row.createCell(j);
cell.setCellValue(arr[i][j]);
}
}
workbook.write(new FileOutputStream("C:\\Users\\dimic\\Desktop\\Jordan.xls"));
workbook.close();
Answer the question
In order to leave comments, you need to log in
1. Workbook needs to be created through WorkbookFactory, which will load an existing file
2. Take the first sheet, determine the number of rows in the sheet and add a new matrix
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question