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!!
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.
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:
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.
cat > XLS2HTML.py
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')
def w2html (str1ng):
#end function list
with open("outputhtml.html") as fyle:
for name in book.sheet_names():
print "<h1>" + name + "</h1>"
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 "</table> \n"
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
otherwise it will throw you a type error, if you want to ignore the dates, wrap the nested for loops inside a
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)
all the for loops here.
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 (maybe 1, i forget)
that way you don't need to edit the python script using pico or nano
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.
Last edited by eval(BadCode); 08-11-2010 at 07:47 PM.
Great thanks so much. It seems rather detailed. Is there a way to use XML if I were to convert?
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>
Last edited by eval(BadCode); 08-11-2010 at 08:33 PM.
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!
the use of "clear:both;"
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…
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread