First time here? Check out the FAQ!

Ask Your Question
0

Sage and Excel: export / import files via Windows

asked 9 years ago

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!

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
0

answered 8 years ago

dan_fulea gravatar image

updated 8 years ago

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...)

Preview: (hide)
link

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: 9 years ago

Seen: 2,363 times

Last updated: Mar 03 '17