Exportera matris till Excel


"""
Programmet exporterar matris till Excel
"""


import numpy as np
import openpyxl as op


def matrix_to_excel(matrix: np.array, filename: str):
    wb_out = op.Workbook()
    sheet = wb_out.active
    rows, columns = matrix.shape
    for i in range(1, rows + 1):
        for j in range(1, columns + 1):
            sheet.cell(row=i, column=j).value = matrix[i - 1, j - 1]
    wb_out.save(filename)
    wb_out.close()
    return matrix

matris = np.ones([5, 5])
matrix_to_excel(matris, './matrix_from_python.xlsx')