469,311 Members | 2,514 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,311 developers. It's quick & easy.

convert HTML string into csv/xls/doc

CODE:
$stuff = '<html><head><title>stuff</title></head><body><b>Hello</b>
World</body></html>';
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); //
Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); //
always modified
header("Cache-Control: no-store, no-cache, must-revalidate"); //
HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); //
HTTP/1.0
header("Content-type: application/msword; filename=stuff.doc");
//header("Content-Disposition: attachment; filename=stuff.doc");
echo $stuff;
However, upon attempting to run this script I ran into the following
error in IE:
Internet Explorer could not open this script: test.php (note: I am
trying to change it to be "stuff.doc"). Nothing ever showed up.
test.php (the code you see) is in a Linux environment in a folder
protected by .htaccess.
In NS 7.0 it produces no errors but it tries to save the downloaded
file as "test.php" and not "stuff.doc".
I am unsure how to do this in PHP although I can do it in TCL and have
done it that way before, that, however, is not an option here.
Please help, I'm stuck at the very beginning of attempting customized
simple reporting.
Thank You,
Shailesh P.

Sep 26 '05 #1
7 19234
>>Shailesh<< wrote:
CODE:
$stuff = '<html><head><title>stuff</title></head><body><b>Hello</b>
World</body></html>';
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); //
Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); //
always modified
header("Cache-Control: no-store, no-cache, must-revalidate"); //
HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); //
HTTP/1.0
header("Content-type: application/msword; filename=stuff.doc");
//header("Content-Disposition: attachment; filename=stuff.doc");
echo $stuff;
However, upon attempting to run this script I ran into the following
error in IE:
Internet Explorer could not open this script: test.php (note: I am
trying to change it to be "stuff.doc"). Nothing ever showed up.


I do not know if this has anything to do with IE not being able to open
the document, but why do you specify a content-type of
"application/msword" when the document seems to be an HTML-document?
--

Gerard van Wilgen

www.majstro.com - Multilingual translation dictionary
www.erotikejo.com - International sex portal
Sep 26 '05 #2
hi,
i simply wants to convert html string to csv/xls file..i hv tried

$stuff = '<html><head><title>stuff</title></head><body><b>Hello</b>
World</body></html>';

header("Content-Type: application/vnd.ms-excel");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("content-disposition: attachment;filename=str.xls");

print $stuff;

this would ask to save as xls file...but while opening that xls file
it's giving error..
because it's saving html coded file with only xls extension.

would anyone plz help me to save HTML string in xls/cvs format..

Regards,
Shailesh P

Sep 26 '05 #3
>>Shailesh<< schrieb:
this would ask to save as xls file...but while opening that xls file
it's giving error..
because it's saving html coded file with only xls extension. Excel needs binary!
would anyone plz help me to save HTML string in xls/cvs format..

What did you want, a csv or a Excel File?
If you need csv you could write it like a normal textfile, if you want
to get a excel file, try the Excel_Spreadsheet_Writer from the PEAR package.

-Kirsten
Sep 26 '05 #4
hi
In my reporting script i want to give report format option(HTML &
CSV).
i hv written a script that generates HTML report...but when it is
required in CSV form
is there any way to convert my html embedded string into csv file..????

Thank you
Shailesh P.

Sep 26 '05 #5
hi
In my reporting script i want to give report format option(HTML &
CSV).
i hv written a script that generates HTML report...but when it is
required in CSV form
is there any way to convert my html embedded string into csv file by
setting headers..????

Thank you
Shailesh P.

Sep 26 '05 #6
>>Shailesh<< schrieb:
is there any way to convert my html embedded string into csv file by
setting headers..????

csv->Comma Separated Values!!!
Therfor you will need a seperate script or code for generating this csv.
Changing the header will only inform the browser about the content of
the output.
So what should excel do with a file wich contains html-code?

-Kirsten
Sep 26 '05 #7
Shailesh,

Setting the content-type header to "application/msword" should make the browser open the file as a Word document. This isn't a problem as Word understands HTML (more or less), however it's no use for outputting an Excel spreadsheet.

CSV is the way to go here and as Kirsten said, a CSV file is just data seperated by commas - easy to output with a simple script once you understand the structure. Try saving an excel spreadsheet as a CSV file, then open the CSV file in notepad to see how the data is formatted - this should give you a good idea of what your script needs to output.

Theoretically it would be possible to have a similar script to format your data into a valid .xls file, however this would be a MAJOR pain as .xls is a binary file format. Go with CSV.
Sep 30 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by z. f. | last post: by
10 posts views Thread by Nikolay Petrov | last post: by
2 posts views Thread by csgraham74 | last post: by
5 posts views Thread by Just Another Victim of the Ambient Morality | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.