ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 03 Mar 2017 22:00:56 +0100Sage and Excel: export / import files via Windowshttps://ask.sagemath.org/question/31565/sage-and-excel-export-import-files-via-windows/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](http://wiki.sagemath.org/SageAppliance#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!Mon, 14 Dec 2015 20:42:08 +0100https://ask.sagemath.org/question/31565/sage-and-excel-export-import-files-via-windows/Answer by dan_fulea for <p>Hi,</p>
<p>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.</p>
<p>I followed the instructions of <a href="http://wiki.sagemath.org/SageAppliance#Sharing_files_between_Sage_and_Windows">4. Sharing files between Sage and Windows</a>, but I do not understand the last instruction "The files will be in /media/sf_<<volume name="">>".</p>
<p>An example code of reading and writing to a shared map would be great. Thanks!</p>
https://ask.sagemath.org/question/31565/sage-and-excel-export-import-files-via-windows/?answer=36811#post-id-36811This 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...)Fri, 03 Mar 2017 22:00:56 +0100https://ask.sagemath.org/question/31565/sage-and-excel-export-import-files-via-windows/?answer=36811#post-id-36811