473,320 Members | 2,020 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,320 software developers and data experts.

Problem with converting HTML to Word/Excel/Etc.

Based on the information I read in www.php.net on the header command I wrote
a dummy test script to try to convert the contents of $stuff to MS Word
downloadable format:

http://www.php.net/header

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.

Thanx
Phil
Jul 17 '05 #1
2 8005

"Phil Powell" <so*****@erols.com> schreef in bericht
news:%Ckkb.89577$0Z5.43633@lakeread03...

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.


The following should be enough to download any word document:

<?
// Code which retrieves the word document as $stuff
// .....
header("Content-Disposition: attachment; filename=stuff".time().".doc");
echo $stuff

?>

This way, the browser will always download a new version because the
filename is unique with the appended return value of the time() function.

Using a content-type header is not necessary, unless the .doc extension is
already associated on the server.
JW

Jul 17 '05 #2
Thanx, however, I just found out that business requirements indicate that it
is embedded, so I can't use "attachment"; I have to use "inline" instead.
And it could be .doc, .xls, .pdf, .rtf or .html now. More work to do. :(
but Thanx though!

Phil

"Janwillem Borleffs" <jw@jwscripts.com> wrote in message
news:3f**********************@news.euronet.nl...

"Phil Powell" <so*****@erols.com> schreef in bericht
news:%Ckkb.89577$0Z5.43633@lakeread03...

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.


The following should be enough to download any word document:

<?
// Code which retrieves the word document as $stuff
// .....
header("Content-Disposition: attachment; filename=stuff".time().".doc");
echo $stuff

?>

This way, the browser will always download a new version because the
filename is unique with the appended return value of the time() function.

Using a content-type header is not necessary, unless the .doc extension is
already associated on the server.
JW

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: A P | last post by:
Is this possible? I am planning to export data from SQL that generates HTML table. Instead of selecting the table and then copy then paste to word, I need a script(JS or VB) that will...
21
by: Davinder | last post by:
can anyone recommend a good tool to convert documents to HTML on the fly. I need to integrate this tool with a VB app so it must have an API. thanks in advance Davinder davinder@gujral.co.uk
20
by: Al Moritz | last post by:
Hi all, I was always told that the conversion of Word files to HTML as done by Word itself sucks - you get a lot of unnecessary code that can influence the design on web browsers other than...
2
by: Asbjørn Ulsberg | last post by:
Hi. I'm trying to convert Brady Hegberg's great RTF2HTML VB 6.0 module to C#. I've managed to convert the VB code to VB.NET, which gave me the following code: Option Strict On Option...
2
by: Steve Chatham | last post by:
I use the following code: Private Sub RbtnExport_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RbtnExport.SelectedIndexChanged Dim sFile As String =...
1
by: Ramakrishnan Nagarajan | last post by:
Hi, I am converting Excel data into a Dataset in C#. There are around 24 columns in the Excel Sheet. First I tried to insert one row with correct values in the Excel sheet. i.e. for text columns...
1
by: Tony | last post by:
My company has an online documentation system that got set up a while ago. They now want to to add the functionality to import documents into the system where they will be converted to HTML. I...
2
by: CM | last post by:
Hi, Could anyone please help me? I am completing my Master's Degree and need to reproduce a Webpage in Word. Aspects of the page are lost and some of the text goes. I would really appreciate it....
2
by: s.danyal.k | last post by:
Hi All, I have created an application in C# that converts HTML file to MS word documents. The HTML file may also have images , for e.g "<img src='http://www.google.com.pk/images/hp0.gif'></img>"....
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.