By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,285 Members | 2,109 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,285 IT Pros & Developers. It's quick & easy.

<font size="-1">

P: n/a
I can put out a Word Doc from PHP but if I try and manipulate the font
size in the PHP part it outputs a blank Word Document.

Here is what I have:
<?php
$fname="report.doc";
$handle = fopen( $fname, "rb" );
$buf = fread( $handle, filesize( $fname ));
fclose( $handle );
$len = strlen( $buf );
header( "Pragma: public" );
header( "Cache-Control: private" );
header( "Connection: close" );
header( "Content-Type: application/msword" );
header( "Content-Length: $len" );
header( "Content-Disposition: inline; filename=\"$fname\"" );
print $buf;
>
<table border="1">
<tr>
<td>FieldOneHeader</td>
<td>FieldTwoHeader</td>
<td>FieldThreeHeader</td>
....
<td>FieldTenHeader</td>
</tr>
<?php
//Oracle DB Connection username and password etc here

$s = OCIParse($connection. "select * from theTable");
OCIExecute($s, OCI_DEFAULT);
while (OCIFetch($s)) {
print '<tr><td><font size="-1">' . ociresult($s, "FIELDONENAME") .
'</font></td>';
print '<td><font size="-1">' . ociresult($s, "FIELDTWONAME"). '</
font></td>';
print '<td><font size="-1">' . ociresult($s, "FIELDTHREENAME"). '</
font></td>';
print '<td><font size="-1">' . ociresult($s, "FIELDFOURNAME"). '</
font></td>';
print '<td><font size="-1">' . ociresult($s, "FIELDFIVENAME"). '</
font></td>';
//rest here .......
print '<td><font size="-1">' . ociresult($s, "FIELDNINENAME"). '</
font></td>';
print '<td><font size="-1">' . ociresult($s, "FIELDTENNAME"). '</
font></td></tr>';
}
print '</table>';
?>
The wierd part is if I only put font size in the first 5 fields it
will work:
print '<tr><td><font size="-1">' . ociresult($s, "FIELDONENAME") .
'</font></td>';
print '<td><font size="-1">' . ociresult($s, "FIELDTWONAME"). '</
font></td>';
print '<td><font size="-1">' . ociresult($s, "FIELDTHREENAME"). '</
font></td>';
print '<td><font size="-1">' . ociresult($s, "FIELDFOURNAME"). '</
font></td>';
print '<td><font size="-1">' . ociresult($s, "FIELDFIVENAME"). '</
font></td>';
//rest here .......
print '<td>' . ociresult($s, "FIELDNINENAME"). '</td>';
print '<td>' . ociresult($s, "FIELDTENNAME"). '</td></tr>';

Please advise.

Jun 13 '07 #1
Share this Question
Share on Google+
17 Replies


P: n/a
te****@hotmail.com wrote:
I can put out a Word Doc from PHP but if I try and manipulate the font
size in the PHP part it outputs a blank Word Document.
No; you are outputting HTML, not a MS Office document.

The problem is about MS Word's HTML parser, not about PHP.

--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

http://acm.asoc.fi.upm.es/~mr/ ; http://acm.asoc.fi.upm.es/~ivan/
MSN:i_*************************@hotmail.com
Jabber:iv*********@jabber.org ; iv*********@kdetalk.net
Jun 14 '07 #2

P: n/a
..oO(te****@hotmail.com)
>I can put out a Word Doc from PHP but if I try and manipulate the font
size in the PHP part it outputs a blank Word Document.

Here is what I have:
<?php
$fname="report.doc";
$handle = fopen( $fname, "rb" );
$buf = fread( $handle, filesize( $fname ));
fclose( $handle );
file_get_contents() exists.
$len = strlen( $buf );
header( "Pragma: public" );
'Pragma' is a request header, usage in a response is not defined.
Additionally the only defined directive for this header is 'no-cache'.
header( "Cache-Control: private" );
header( "Connection: close" );
header( "Content-Type: application/msword" );
header( "Content-Length: $len" );
header( "Content-Disposition: inline; filename=\"$fname\"" );
print $buf;
>>
<table border="1">
<tr>
[...]
Now I'm confused - do you want to output the .doc document _and_ the
following together on the same page? That's not going to work.

Micha
Jun 14 '07 #3

P: n/a
Michael Fesser wrote:
> header( "Content-Type: application/msword" );
header( "Content-Disposition: inline; filename=\"$fname\"" );
Now I'm confused - do you want to output the .doc document _and_ the
following together on the same page? That's not going to work.
No - He's forcing MS Word to open, then feeding HTML to it. He's not feeding
Word anything else.

--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

Funciona mejor si lo enchufas
Jun 14 '07 #4

P: n/a
..oO(Iván Sánchez Ortega)
>Michael Fesser wrote:
>> header( "Content-Type: application/msword" );
header( "Content-Disposition: inline; filename=\"$fname\"" );
>Now I'm confused - do you want to output the .doc document _and_ the
following together on the same page? That's not going to work.

No - He's forcing MS Word to open, then feeding HTML to it. He's not feeding
Word anything else.
Hmm, but he opens and sends a .doc file, followed by some ugly HTML ...

Micha
Jun 14 '07 #5

P: n/a
Michael Fesser wrote:
Hmm, but he opens and sends a .doc file, followed by some ugly HTML ...
WTF???!!!

--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

http://acm.asoc.fi.upm.es/~mr/ ; http://acm.asoc.fi.upm.es/~ivan/
MSN:i_*************************@hotmail.com
Jabber:iv*********@jabber.org ; iv*********@kdetalk.net
Jun 14 '07 #6

P: n/a
On Jun 14, 12:36 am, "tes...@hotmail.com" <tes...@hotmail.comwrote:
I can put out a Word Doc from PHP but if I try and manipulate the font
size in the PHP part it outputs a blank Word Document.

Here is what I have:
<?php
$fname="report.doc";
$handle = fopen( $fname, "rb" );
$buf = fread( $handle, filesize( $fname ));
fclose( $handle );
$len = strlen( $buf );
header( "Pragma: public" );
header( "Cache-Control: private" );
header( "Connection: close" );
header( "Content-Type: application/msword" );
header( "Content-Length: $len" );
header( "Content-Disposition: inline; filename=\"$fname\"" );
print $buf;

<table border="1">
<tr>
<td>FieldOneHeader</td>
<td>FieldTwoHeader</td>
<td>FieldThreeHeader</td>
...
<td>FieldTenHeader</td>
</tr>
<?php
//Oracle DB Connection username and password etc here

$s = OCIParse($connection. "select * from theTable");
OCIExecute($s, OCI_DEFAULT);
while (OCIFetch($s)) {
print '<tr><td><font size="-1">' . ociresult($s, "FIELDONENAME") .
'</font></td>';
print '<td><font size="-1">' . ociresult($s, "FIELDTWONAME"). '</
font></td>';
print '<td><font size="-1">' . ociresult($s, "FIELDTHREENAME"). '</
font></td>';
print '<td><font size="-1">' . ociresult($s, "FIELDFOURNAME"). '</
font></td>';
print '<td><font size="-1">' . ociresult($s, "FIELDFIVENAME"). '</
font></td>';
//rest here .......
print '<td><font size="-1">' . ociresult($s, "FIELDNINENAME"). '</
font></td>';
print '<td><font size="-1">' . ociresult($s, "FIELDTENNAME"). '</
font></td></tr>';}

print '</table>';

?>

The wierd part is if I only put font size in the first 5 fields it
will work:
print '<tr><td><font size="-1">' . ociresult($s, "FIELDONENAME") .
'</font></td>';
print '<td><font size="-1">' . ociresult($s, "FIELDTWONAME"). '</
font></td>';
print '<td><font size="-1">' . ociresult($s, "FIELDTHREENAME"). '</
font></td>';
print '<td><font size="-1">' . ociresult($s, "FIELDFOURNAME"). '</
font></td>';
print '<td><font size="-1">' . ociresult($s, "FIELDFIVENAME"). '</
font></td>';
//rest here .......
print '<td>' . ociresult($s, "FIELDNINENAME"). '</td>';
print '<td>' . ociresult($s, "FIELDTENNAME"). '</td></tr>';

Please advise.

Why don't you use this:

http://sourceforge.net/projects/php-doc-xls-gen/

Sounds a lot better than trying to force things . Some people may have
no Word installed, this would suck with Doc headers for HTML.
Cheers!
Vladimir

Jun 14 '07 #7

P: n/a
Iván Sánchez Ortega <ivansanchez-alg@rroba-escomposlinux.-.punto.-.org>
wrote:
>Michael Fesser wrote:
>> header( "Content-Type: application/msword" );
header( "Content-Disposition: inline; filename=\"$fname\"" );
>Now I'm confused - do you want to output the .doc document _and_ the
following together on the same page? That's not going to work.

No - He's forcing MS Word to open, then feeding HTML to it. He's not feeding
Word anything else.
Yes, he is. I think you missed the "print $buf;" statement, where he
copies a Word document to stdout.

Note, however, that Internet Explorer does not trust the Content-Type; it
will often examine the first part of the file to determine how to process
it.
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jun 15 '07 #8

P: n/a
"No - He's forcing MS Word to open, then feeding HTML to it. He's not
feeding
Word anything else.

Hmm, but he opens and sends a .doc file, followed by some ugly
HTML ... "
I am forcing the MS Word to open and feeding Oracle Database records
with HTML into it.
It works until I get to over 25 records and then it doesnt show
anything on the page.
Please advise how I can get a Word Document to open from a PHP web
page where it shows all the Database records because the way I am
doing it doesnt work when I get over 25 records.

I am in an environment where I cant download any foreign software so I
need to do it using PHP code.
Please advise.

Jun 16 '07 #9

P: n/a

---------- Forwarded message ----------
From: "tes...@hotmail.com" <tes...@hotmail.com>
Date: Jun 15, 8:03 pm
Subject: <font size="-1">
To: comp.lang.php
"No - He's forcing MS Word to open, then feeding HTML to it. He's not
feeding
Word anything else.

Hmm, but he opens and sends a .doc file, followed by some ugly
HTML ... "

I am forcing the MS Word to open and feeding Oracle Database records
with HTML into it.
It works until I get to over 25 records and then it pops open a Word
Document that is blank.
Please advise how I can get a Word Document to open from a PHP web
page where it shows all the Database records because the way I am
doing it doesnt work when I get over 25 records.

I am in an environment where I cant download any foreign software so I
need to do it using PHP code.
Please advise.

Jun 16 '07 #10

P: n/a
..oO(te****@hotmail.com)
>I am forcing the MS Word to open and feeding Oracle Database records
with HTML into it.
It works until I get to over 25 records and then it doesnt show
anything on the page.
I'm surprised you see anything at all. From Word's point of view you're
sending an invalid document. It's like taking an image file, appending
some random bytes to it and then expecting the image viewer to still
recognize it as an image.
>Please advise how I can get a Word Document to open from a PHP web
page where it shows all the Database records because the way I am
doing it doesnt work when I get over 25 records.
Well, you would have to create that Word document on the server and then
deliver it to the browser ...

Or maybe Word is capable of recognizing plain HTML? Then all you would
have to do is to send an appropriate Content-Type header (as you already
do), followed by the HTML content. No reason to send any .doc file.

Micha
Jun 16 '07 #11

P: n/a
te****@hotmail.com wrote:
"No - He's forcing MS Word to open, then feeding HTML to it. He's not
feeding
Word anything else.

Hmm, but he opens and sends a .doc file, followed by some ugly
HTML ... "
I am forcing the MS Word to open and feeding Oracle Database records
with HTML into it.
It works until I get to over 25 records and then it doesnt show
anything on the page.
Please advise how I can get a Word Document to open from a PHP web
page where it shows all the Database records because the way I am
doing it doesnt work when I get over 25 records.

I am in an environment where I cant download any foreign software so I
need to do it using PHP code.
Please advise.
Forget about Word and create correct HTML that any browser can understand.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 16 '07 #12

P: n/a
On Jun 15, 9:26 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
tes...@hotmail.com wrote:
"No - He's forcing MS Word to open, then feeding HTML to it. He's not
feeding
Word anything else.
Hmm, but he opens and sends a .doc file, followed by some ugly
HTML ... "
I am forcing the MS Word to open and feeding Oracle Database records
with HTML into it.
It works until I get to over 25 records and then it doesnt show
anything on the page.
Please advise how I can get a Word Document to open from a PHP web
page where it shows all the Database records because the way I am
doing it doesnt work when I get over 25 records.
I am in an environment where I cant download any foreign software so I
need to do it using PHP code.
Please advise.

Forget about Word and create correct HTML that any browser can understand.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -

- Show quoted text -
Okay, I guess the main thing is how do I create a Print Friendly
report? I was using Word Doc so I oould create a Printer Friendly
report that could be seen in Word Document and also downloaded as a
Word Document.

Jun 16 '07 #13

P: n/a
te****@hotmail.com wrote:
On Jun 15, 9:26 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>tes...@hotmail.com wrote:
>>"No - He's forcing MS Word to open, then feeding HTML to it. He's not
feeding
Word anything else.
Hmm, but he opens and sends a .doc file, followed by some ugly
HTML ... "
I am forcing the MS Word to open and feeding Oracle Database records
with HTML into it.
It works until I get to over 25 records and then it doesnt show
anything on the page.
Please advise how I can get a Word Document to open from a PHP web
page where it shows all the Database records because the way I am
doing it doesnt work when I get over 25 records.
I am in an environment where I cant download any foreign software so I
need to do it using PHP code.
Please advise.
Forget about Word and create correct HTML that any browser can understand.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -

- Show quoted text -

Okay, I guess the main thing is how do I create a Print Friendly
report? I was using Word Doc so I oould create a Printer Friendly
report that could be seen in Word Document and also downloaded as a
Word Document.
If you need to create something which is exact, create a PDF.
Otherwise, code good html and CSS to make your pages fluid. For the
latter, try alt.html for help.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 17 '07 #14

P: n/a
On Jun 16, 8:16 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
tes...@hotmail.com wrote:
On Jun 15, 9:26 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
tes...@hotmail.com wrote:
"No - He's forcing MS Word to open, then feeding HTML to it. He's not
feeding
Word anything else.
Hmm, but he opens and sends a .doc file, followed by some ugly
HTML ... "
I am forcing the MS Word to open and feeding Oracle Database records
with HTML into it.
It works until I get to over 25 records and then it doesnt show
anything on the page.
Please advise how I can get a Word Document to open from a PHP web
page where it shows all the Database records because the way I am
doing it doesnt work when I get over 25 records.
I am in an environment where I cant download any foreign software so I
need to do it using PHP code.
Please advise.
Forget about Word and create correct HTML that any browser can understand.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -
- Show quoted text -
Okay, I guess the main thing is how do I create a Print Friendly
report? I was using Word Doc so I oould create a Printer Friendly
report that could be seen in Word Document and also downloaded as a
Word Document.

If you need to create something which is exact, create a PDF.
Otherwise, code good html and CSS to make your pages fluid. For the
latter, try alt.html for help.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -

- Show quoted text -
Thanks, I was also trying to find info on PHP to PDF but cant seem to
find anything on that.
I would like to output my Oracle records using PHP to PDF report.
Please advise.

Jun 17 '07 #15

P: n/a
..oO(te****@hotmail.com)
>Thanks, I was also trying to find info on PHP to PDF but cant seem to
find anything on that.
http://www.google.com/search?q=php+create+pdf

There's _a lot_ of informations available! There are many different
libraries available for use with PHP, some commercial, some free.

Check out

http://fpdf.org/
http://sourceforge.net/projects/pdf-php

I haven't used them yet, so I can't provide examples. For FPDF there are
tutorials available on their site.

Micha
Jun 17 '07 #16

P: n/a
te****@hotmail.com wrote:
On Jun 16, 8:16 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>tes...@hotmail.com wrote:
>>On Jun 15, 9:26 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
tes...@hotmail.com wrote:
"No - He's forcing MS Word to open, then feeding HTML to it. He's not
feeding
Word anything else.
Hmm, but he opens and sends a .doc file, followed by some ugly
HTML ... "
I am forcing the MS Word to open and feeding Oracle Database records
with HTML into it.
It works until I get to over 25 records and then it doesnt show
anything on the page.
Please advise how I can get a Word Document to open from a PHP web
page where it shows all the Database records because the way I am
doing it doesnt work when I get over 25 records.
I am in an environment where I cant download any foreign software so I
need to do it using PHP code.
Please advise.
Forget about Word and create correct HTML that any browser can understand.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -
- Show quoted text -
Okay, I guess the main thing is how do I create a Print Friendly
report? I was using Word Doc so I oould create a Printer Friendly
report that could be seen in Word Document and also downloaded as a
Word Document.
If you need to create something which is exact, create a PDF.
Otherwise, code good html and CSS to make your pages fluid. For the
latter, try alt.html for help.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -

- Show quoted text -

Thanks, I was also trying to find info on PHP to PDF but cant seem to
find anything on that.
I would like to output my Oracle records using PHP to PDF report.
Please advise.
Try www. fpdf.org.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 17 '07 #17

P: n/a
Michael Fesser wrote:
I'm surprised you see anything at all. From Word's point of view you're
sending an invalid document. It's like taking an image file, appending
some random bytes to it and then expecting the image viewer to still
recognize it as an image.
If you're using GIF, then this will work flawlessly. The GIF spec states
that any additional data found at the end of a file must be ignored.

Interestingly the ZIP spec says the inverse: any extra data found at the
*beginning* of a file must be ignored. ("Header" data for ZIP files is
stored at the *end* of the file rather than what is common for most file
formats: the beginning of the file. This is because ZIP files would often
span multiple floppy disks, and the header would need to be the last bit
of data to be written.) Thus it is possible to create a file which is both
a perfectly valid GIF *and* a perfectly valid ZIP -- nice way of hiding
arbitrary data in an image file, though it swells the size of the file
significantly.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 114 days, 1 min.]

You're Not Allowed to Take Pictures of the US Embassy in Rome
http://tobyinkster.co.uk/blog/2007/06/16/us-embassy/
Jun 17 '07 #18

This discussion thread is closed

Replies have been disabled for this discussion.