472,972 Members | 2,161 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,972 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 7988

"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>"....
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
3
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.