Send excel content in body of mail

pavan227

New Member
Joined
Feb 8, 2025
Messages
2
Reaction score
0
Credits
17
Hi,

I need to send contents of excel in body of mail through Linux script it should be like below. Please help me with the solution.

Sub: Job Load Status

Mail Body:

CategorySourceTable
A1LegacyA
A1SAPB
 


How are you running excel in Linux?

You will have to know the layout of the spreadsheet and build an html table to match the layout.
I have done this with LibreCalc, I haven't tried it with excel, but I know you can export excel into csv.
This will work, but obviously you'll have to tweak it to match your spreadsheet layout.

Code:
#!/bin/bash

# Convert Excel file to CSV
ssconvert your_spreadsheet.xlsx your_spreadsheet.csv

# Convert CSV to HTML table
csv_to_html() {
    echo "<table border='1'>"
    while IFS=, read -r col1 col2 col3; do
        echo "<tr><td>$col1</td><td>$col2</td><td>$col3</td></tr>"
    done < your_spreadsheet.csv
    echo "</table>"
}

# Store HTML content in a variable
html_content=$(csv_to_html)

# Send email
sendmail [email protected] <<EOF
Subject: Spreadsheet Contents
Content-Type: text/html
<html>
<body>
$html_content
</body>
</html>
EOF

I didn't put column headers on here. (I don't need them for what I'm doing), but it would be easy to add them I think.
 
Last edited:
Thank you for quick response. My requirement is body of email should be in table format.
 


Members online


Latest posts

Top