634 | def export_matrix_to_excel(row_names, col_names, matrix, filepath='export.xlsx', sheetname='Export'): |
635 | workbook = xlsxwriter.Workbook(filepath) |
636 | ws = workbook.add_worksheet(sheetname) |
637 | |
638 | |
639 | format_border = workbook.add_format() |
640 | format_border.set_border(1) |
641 | format_border.set_font_size(9) |
642 | |
643 | format_border_text_wrap = workbook.add_format() |
644 | format_border_text_wrap.set_text_wrap() |
645 | format_border_text_wrap.set_border(1) |
646 | format_border_text_wrap.set_font_size(9) |
647 | |
648 | ws.set_column(0, 1, width=15, cell_format=None) |
649 | ws.set_column(1, 50, width=9, cell_format=None) |
650 | |
651 | for i, p in enumerate(col_names): |
652 | ws.write(0, i+1, p, format_border_text_wrap) |
653 | for i, p in enumerate(row_names): |
654 | ws.write(i+1, 0, p, format_border) |
655 | for i, row in enumerate(range(matrix.shape[0])): |
656 | ws.write_row(i+1, 1, matrix[i, :], format_border) |
657 | workbook.close() |