/    Sign up×
Community /Pin to ProfileBookmark

Is I possible to import information from an excel document to an HTML or email?

Hello everyone. I work for a company that sends out weekly specials and offers in the form of an excel document. We are currently looking to design and create an email that will “pull” the information from that spreadsheet (that we will house on a server) so all the deals and specials will be directly in the email. And when the spreadsheet is updated each we we will replace the old one and the email will update with the new info on the excel doc.

Is this something that is possible to do?! My boss is totally hounding me so any support would be awesome. Thanks so much!! ?

to post a comment
HTML

6 Comments(s)

Copy linkTweet thisAlerts:
@kiwibritAug 11.2010 — It's possible server side - here's a method of doing it with asp.net. No doubt it can be done with php. Not really an HTML problem.
Copy linkTweet thisAlerts:
@eval_BadCode_Aug 11.2010 — I use python to handle excel spreadsheets (the only limitation is .xls , you can't use .xlsx (i didn't really check).

python module: xlrd

description: A Python module for extracting data from MS Excel ™ spreadsheet files.

if you're on a shared server you can't install the module into the same root folder that python will be looking for it in, so you need to append the path and put your files into www/py/scripts and www/py/xlrd where www is the web root:



from the shell:
[CODE]

cat > XLS2HTML.py


import sys
sys.path.append( "/root_1/root_2/www/py/scripts" )
sys.path.append( "/root_1/root_2/www/py/xlrd" )

# where root_1 and root_2 are directories from the server root (it needs to be an absolute path I think)

from datetime import date,datetime,time
from xlrd import open_workbook,xldate_as_tuple

book = open_workbook('spreadhseets/weekly_specials.xls')


#write function

def w2html (str1ng):
fyle.writelines(str1ng)

#end function list

with open("outputhtml.html") as fyle:
for name in book.sheet_names():
print "<h1>" + name + "</h1>"
print "<table>"
for row_index in range(0,book.sheet_by_name(name).nrows):
print "<tr> n"
for col_n in range(0,book.sheet_by_name(name).ncols): #i might have switched columns and rows around, this might make your sheet transformed 90 degrees lol)
print "<td>",
print name.cell(row_index,col_n)
print "</td>",
print "</tr>"
print "</table> n"


[/CODE]


this will print all of the cells for each sheet into a separate html table (i think, didn't actually run it but if I don't get it first the right time.

if you want it to write the code into the html file, change all of the print statements like this

print "" will now become w2html("")

hope this helps some, if you have dates inside of your xls file you need to convert them to a tuple first, like this

[CODE]
sheet = book.sheet_by_name(name)
cell = sheet.cell(row_index,col_n)
date_value = xldate_as_tuple(sheet.cell(row_index,col_n).value,book.datemode)
date(*date_value[:3]))
[/CODE]


otherwise it will throw you a type error, if you want to ignore the dates, wrap the nested for loops inside a

try:

all the for loops here.

except:

continue


I like it, if you're using enourmous xls file (like a gig or more) you should look into using on demand sheet calling. It's much much faster, but for my purposes using the above as a skeleton works.

if you want to pass a value to the python script it will get stored in sys.argv[] (like a sheet name?)

so calling python XLS2HTML.py week_8_menu.xls

will put the value "week_8_menu.xls" in sys.argv[2] (maybe 1, i forget)

that way you don't need to edit the python script using pico or nano :p

php also has a way to let you open processes from a php script, you can read the process stream and it will echo all of the print lines in python or you can open the html table file that this script writes and echo the entire file (outputhtml.html). I actually use both, the process stream to show my users the error generated, and the htmlfile to show missing values inside the excel sheet. It lets them find errors in 30,000 rows of excel data very very fast, and having the data in an html table structure allows you to change it into an sql query with little effort.

There is a module to write to excel sheets (xlwd i think), but why would you want to.

good luck with the boss

Hope this helps.
Copy linkTweet thisAlerts:
@eric23savauthorAug 11.2010 — Great thanks so much. It seems rather detailed. Is there a way to use XML if I were to convert?
Copy linkTweet thisAlerts:
@eval_BadCode_Aug 12.2010 — yes, but your spreadsheet would have to have some specific method to the madness and even then. You would probably need to parse the data, because people make mistakes.

an HTML table is a hierarchical model.

edit: replace (<table>,</table>,<tr>,</tr>,<td>,</td>) with your xml tags.

I just showed you how I do this, I'd bet a pretty penny that the other poster has a perfectly workable method.

But you will need a programming language or a program to convert a file. There is no html tag <xlsxtohtml src="weeklymenu.xlsx></xlsx>
Copy linkTweet thisAlerts:
@bagfranceAug 12.2010 — eava is used by hakers! some website was balck linked by this! just like some words "ugg" or "chanel coco"! it's also can get a good rank on google!
Copy linkTweet thisAlerts:
@bagfranceAug 12.2010 — A plain block level element without content, does not give raise to the creation of any inline box at all but still keeps its block box properties available for styling. The fact that there is no inline element content to be rendered results in a block box that "collapses" to whatever height that is specified as the browser default through the margin , padding and possibly border properties. A user «--» author style sheet can now cascade new values on top of the browsers ua.css default to give a visual effect of a "not existing" block box, leaving only the effect of 'clear:both;' as a visual result.

This example page shows the "markup trick" in use and illustrates how to specify nested DIV elements to create an impression of content arranged as a table of data. You already have the source mark-up downloaded, since you are reading this right now. The corresponding stylesheet can be found here…
×

Success!

Help @eric23sav spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...