Suppose there is a matrix, I want to write it in excel using java. Do not tell me a similar implementation, with an example?

    2 answers 2

    There is such a library - apache poi

    Here is an example of its use for the formation of the xls file

    void printMatrixToXls(double[][] matrix, String filename) { HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet("matrix"); for (int i = 0; i < matrix.length; i++) { Row row = sheet.createRow(i); double[] rowData = matrix[i]; for (int j = 0; j < rowData.length; j++) { row.createCell(j).setCellValue(rowData[j]); } } FileOutputStream out = null; try { out = new FileOutputStream(new File(filename)); workbook.write(out); } catch (FileNotFoundException e) { e.ptintStackTrace(); } catch (IOException e) { e.ptintStackTrace(); } finally { IOUtils.closeQuietly(out); } } 
    • so it is understandable, and if I have already formed a matrix? Where to shove it? Well, let's say I created a 100 by 100 matrix there, filled in something like that, I have all of it. How can I put it in these {}? Sorry if I ask something stupid. - nnnn
    • double [] [] this format is nnnn

    In "Spring in action" there is a theme about working with Excel tables.