Ask Your Question
0

Sage and Excel: export / import files via Windows

asked 2015-12-14 20:42:08 +0100

roland gravatar image

Hi,

Please help. The purpose is to export easily a csv file from Sage to Excel (Windows) and via versa. I use VirtualBox. The reason is that Sage is excellent to calculate and Excel is (sometimes) handy to report.

I followed the instructions of 4. Sharing files between Sage and Windows, but I do not understand the last instruction "The files will be in /media/sf_<<volume name="">>".

An example code of reading and writing to a shared map would be great. Thanks!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-03-03 22:00:56 +0100

dan_fulea gravatar image

updated 2017-03-03 22:06:59 +0100

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, 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,
                       # 'columns' : columns_name_list, 
                       } )

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

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-12-14 20:42:08 +0100

Seen: 2,221 times

Last updated: Mar 03 '17