473,378 Members | 1,544 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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 19398
>>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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: hunterb | last post by:
I have a file which has no BOM and contains mostly single byte chars. There are numerous double byte chars (Japanese) which appear throughout. I need to take the resulting Unicode and store it in a...
4
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a...
2
by: z. f. | last post by:
Hi, i need to convert a unicode string to ascii string (in order to put it in HTML page url ) right now the string gets to the page, but when the url clicked (with the unicode string in a...
3
by: Mark Kamoski | last post by:
Hi-- What is the difference between Convert.ToString(obj) and CType(obj, String)? (Assume obj is a variable of type Object.) Please advise. Thank you.
25
by: Charles Law | last post by:
I thought this was going to be straight forward, given the wealth of conversion functions in .NET, but it is proving more convoluted than imagined. Given the following <code> Dim ba(1) As...
10
by: Nikolay Petrov | last post by:
How can I convert DOS cyrillic text to Unicode
2
by: csgraham74 | last post by:
Hi, I have a requirement in work that i give a person the ability to create a html document using a richt text editor. What i then want to do is save the HTML doct to my server & insert...
5
by: Just Another Victim of the Ambient Morality | last post by:
I've done a google search on this but, amazingly, I'm the first guy to ever need this! Everyone else seems to need the reverse of this. Actually, I did find some people who complained about this...
2
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - Why does 1+1 equal 11? or How do I convert a string to a number?...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.