Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

This is a linux box answering, so providing sample code is not so simple. The following "code" is useful only in the sense of a pseudocode. There are some packages / libs written to join python and excel. Sage is inside python, so following this path should give the solution. Packages names (te be imported) are, depending on purpose and implemented functionality, from the list:

xlrd (excel read), xlwt (excel write), xlsxwriter, openpyxl.

The packages do quickly the job. Pseudocode:

import xlsxwriter

workbook  = xlsxwriter.Workbook( outFullFileName )    # e.g. r'C:\temp\a.xlsx'
worksheet = workbook.add_worksheet( 'ABC' )

# prepare data to be written...
# it may be that tableData set to be the list of lists in
# sage: GL( 4, GF(2) ).random_element().list()
# [[0, 0, 0, 1], [0, 0, 1, 1], [1, 1, 1, 1], [0, 1, 1, 1]]
# works below...

worksheet.add_table( 0, 0,    # table to be added starting from cell A1
                                 k, l,     # cell delimiting the rectangle to paste into
                                 { 'data' : tableData , # 'header_row' : True, 'first_column' : True, 'columns' : columns_name_list
                                   } )

This should also work under Linux for the equivalent of excel.

This is a linux box answering, so providing sample code is not so simple. The following "code" is useful only in the sense of a pseudocode. There are some packages / libs written to join python and excel. Sage is inside python, so following this path should give the solution. Packages names (te be imported) are, depending on purpose and implemented functionality, the one or the other from the list:

xlrd (excel read), xlwt (excel write), xlsxwriter, openpyxl.

The packages should do quickly the job. Pseudocode:job, and let the programmer pay attention to the own problems. Pseudocode for the one i prefer:

import xlsxwriter

workbook  = xlsxwriter.Workbook( outFullFileName )    # e.g. r'C:\temp\a.xlsx'
worksheet = workbook.add_worksheet( 'ABC' )

# prepare data to be written...
# it may be that tableData set to be the list of lists in
# sage: GL( 4, GF(2) ).random_element().list()
# [[0, 0, 0, 1], [0, 0, 1, 1], [1, 1, 1, 1], [0, 1, 1, 1]]
# works below...

worksheet.add_table( 0, 0,    # table to be added starting from cell A1
                      k, l,     # cell delimiting the rectangle to paste into
                      { 'data' : tableData ,  # 'header_row'  : True, 
                       # 'first_column' : True, True,
                       # 'columns' : columns_name_list
            columns_name_list, 
                       } )

This should also work under Linux for the equivalent of excel.excel. (And this is a good point to start putting colors and fonts and formats and filters...)