0

I have the following code

   awk test1 > out.xsl
 mail -a out.xsl "Test Subject" abc@gmail.com < /dev/null

So I have a file in csv format and i need to convert it into excel when the mail is being sent. I do receive the mail but it gets corrupted when I try to open it. Test1 is a CSV file and Iam converting it in excel file named out.xsl. Iam sending the excel file in mail but Iam not able to open it or view anything inside it Please help

Rahul mehta
  • 35
  • 1
  • 5
  • excel files are "zipped xml" files so renaming a csv into xls will not make it an excel file. Keep it in csv format, excel can handle it directly. Another way is to convert it by excel itself before the send – NeronLeVelu Apr 27 '17 at 06:04

3 Answers3

0

Use unoconv:

unoconv -i FilterOptions=9,,76 -f xls  tables.csv

Here 9 is a tab symbol used as field delimiter, and 76 is a codepage (UTF-8).

(unoconv doesn't support xlsx, only xls).

Or write a simple python script with the use of xlsxwriter: example is here.

Michael
  • 5,095
  • 2
  • 13
  • 35
0

This script convert all csv to xlsx format

for f in *.csv; do 
mv -- "$f" "${f%.csv}.xlsx"
done

It convert all files in the folder

0

try

unix2dos -o test1 

use

  • -o to change file in place
  • -n to create a new file

then email the file as attachment and open in excel

 mail -a out.xsl "Test Subject" abc@gmail.com < /dev/null
GeralexGR
  • 2,973
  • 6
  • 24
  • 33